mirror of https://github.com/halo-dev/halo
				
				
				
			Fix the problem of username being case-insensitive and logging in without permissions (#4552)
#### What type of PR is this? /kind bug /area core /milestone 2.10.x #### What this PR does / why we need it: This PR fixes the problem of username being case-insensitive and logging in without permissions. Please note that the problem only occurs with MySQL. #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/4549 #### Special notes for your reviewer: ```bash docker run -it --rm --name halodb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=openmysql -e MYSQL_DATABASE=halo mysql:8 ./gradlew bootRun --args="--spring.profiles.active=dev,mysql --halo.plugin.runtime-mode=deployment" ``` #### Does this PR introduce a user-facing change? ```release-note 修复因大小写问题导致登录后无权限的问题 ```pull/4551/head
							parent
							
								
									eea575c1e2
								
							
						
					
					
						commit
						9c3e603bda
					
				| 
						 | 
					@ -41,13 +41,14 @@ public class DefaultUserDetailService
 | 
				
			||||||
            .onErrorMap(UserNotFoundException.class,
 | 
					            .onErrorMap(UserNotFoundException.class,
 | 
				
			||||||
                e -> new BadCredentialsException("Invalid Credentials"))
 | 
					                e -> new BadCredentialsException("Invalid Credentials"))
 | 
				
			||||||
            .flatMap(user -> {
 | 
					            .flatMap(user -> {
 | 
				
			||||||
                var subject = new Subject(KIND, username, GROUP);
 | 
					                var name = user.getMetadata().getName();
 | 
				
			||||||
 | 
					                var subject = new Subject(KIND, name, GROUP);
 | 
				
			||||||
                return roleService.listRoleRefs(subject)
 | 
					                return roleService.listRoleRefs(subject)
 | 
				
			||||||
                    .filter(this::isRoleRef)
 | 
					                    .filter(this::isRoleRef)
 | 
				
			||||||
                    .map(RoleRef::getName)
 | 
					                    .map(RoleRef::getName)
 | 
				
			||||||
                    .collectList()
 | 
					                    .collectList()
 | 
				
			||||||
                    .map(roleNames -> User.builder()
 | 
					                    .map(roleNames -> User.builder()
 | 
				
			||||||
                        .username(username)
 | 
					                        .username(name)
 | 
				
			||||||
                        .password(user.getSpec().getPassword())
 | 
					                        .password(user.getSpec().getPassword())
 | 
				
			||||||
                        .roles(roleNames.toArray(new String[0]))
 | 
					                        .roles(roleNames.toArray(new String[0]))
 | 
				
			||||||
                        .build());
 | 
					                        .build());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue