Showing
1 changed file
with
13 additions
and
6 deletions
... | ... | @@ -332,10 +332,18 @@ public class RestAuthenticationProvider implements AuthenticationProvider { |
332 | 332 | if (optionalUser.isEmpty()) { |
333 | 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 | 347 | if (user == null) { |
340 | 348 | throw new UsernameNotFoundException("User not found: " + tbEmail); |
341 | 349 | } |
... | ... | @@ -343,8 +351,7 @@ public class RestAuthenticationProvider implements AuthenticationProvider { |
343 | 351 | try { |
344 | 352 | if (user.getAuthority() == null) |
345 | 353 | throw new InsufficientAuthenticationException("User has no authority assigned"); |
346 | - | |
347 | - user.setUserDetailsDTO(optionalUser.get()); | |
354 | + user.setUserDetailsDTO(ytDetailDTO); | |
348 | 355 | SecurityUser securityUser = new SecurityUser(user, true, userPrincipal); |
349 | 356 | logLoginAction(user, authentication, ActionType.LOGIN, null); |
350 | 357 | return new UsernamePasswordAuthenticationToken( | ... | ... |