Showing
1 changed file
with
13 additions
and
6 deletions
@@ -332,10 +332,18 @@ public class RestAuthenticationProvider implements AuthenticationProvider { | @@ -332,10 +332,18 @@ public class RestAuthenticationProvider implements AuthenticationProvider { | ||
332 | if (optionalUser.isEmpty()) { | 332 | if (optionalUser.isEmpty()) { |
333 | throw new BadCredentialsException("验证码不正确"); | 333 | throw new BadCredentialsException("验证码不正确"); |
334 | } | 334 | } |
335 | - | ||
336 | - String tbEmail = | ||
337 | - optionalUser.get().getUsername() + FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB; | ||
338 | - User user = userService.findUserByEmail(TenantId.SYS_TENANT_ID, tbEmail); | 335 | + User user = new User(); |
336 | + String tbEmail = optionalUser.get().getUsername() + FastIotConstants.DEFAULT_EMAIL_SUFFIX_FOR_TB; | ||
337 | + UserDetailsDTO ytDetailDTO = optionalUser.get(); | ||
338 | + //如果是平台管理员 | ||
339 | + if(isPlatFormUser(ytDetailDTO)){ | ||
340 | + user.setAuthority(Authority.PLATFORM_USER); | ||
341 | + user.setTenantId(new TenantId(EntityId.NULL_UUID)); | ||
342 | + user.setId(new UserId(UUID.fromString(ytDetailDTO.getId()))); | ||
343 | + user.setEmail(tbEmail); | ||
344 | + }else{ | ||
345 | + user = userService.findUserByEmail(TenantId.SYS_TENANT_ID, tbEmail); | ||
346 | + } | ||
339 | if (user == null) { | 347 | if (user == null) { |
340 | throw new UsernameNotFoundException("User not found: " + tbEmail); | 348 | throw new UsernameNotFoundException("User not found: " + tbEmail); |
341 | } | 349 | } |
@@ -343,8 +351,7 @@ public class RestAuthenticationProvider implements AuthenticationProvider { | @@ -343,8 +351,7 @@ public class RestAuthenticationProvider implements AuthenticationProvider { | ||
343 | try { | 351 | try { |
344 | if (user.getAuthority() == null) | 352 | if (user.getAuthority() == null) |
345 | throw new InsufficientAuthenticationException("User has no authority assigned"); | 353 | throw new InsufficientAuthenticationException("User has no authority assigned"); |
346 | - | ||
347 | - user.setUserDetailsDTO(optionalUser.get()); | 354 | + user.setUserDetailsDTO(ytDetailDTO); |
348 | SecurityUser securityUser = new SecurityUser(user, true, userPrincipal); | 355 | SecurityUser securityUser = new SecurityUser(user, true, userPrincipal); |
349 | logLoginAction(user, authentication, ActionType.LOGIN, null); | 356 | logLoginAction(user, authentication, ActionType.LOGIN, null); |
350 | return new UsernamePasswordAuthenticationToken( | 357 | return new UsernamePasswordAuthenticationToken( |