| | |
| | | |
| | | |
| | | import com.mindskip.xzs.context.WebContext; |
| | | import com.mindskip.xzs.domain.enums.DeptAdminEnum; |
| | | import com.mindskip.xzs.domain.enums.RoleEnum; |
| | | import com.mindskip.xzs.domain.enums.UserStatusEnum; |
| | | import com.mindskip.xzs.repository.DepartmentMapper; |
| | | import com.mindskip.xzs.service.AuthenticationService; |
| | | import com.mindskip.xzs.service.UserService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationProvider; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | |
| | | * @date 2021/12/25 9:45 |
| | | */ |
| | | @Component |
| | | @RequiredArgsConstructor |
| | | public class RestAuthenticationProvider implements AuthenticationProvider { |
| | | |
| | | private final AuthenticationService authenticationService; |
| | | private final UserService userService; |
| | | private final WebContext webContext; |
| | | |
| | | /** |
| | | * Instantiates a new Rest authentication provider. |
| | | * |
| | | * @param authenticationService the authentication service |
| | | * @param userService the user service |
| | | * @param webContext the web context |
| | | */ |
| | | @Autowired |
| | | public RestAuthenticationProvider(AuthenticationService authenticationService, UserService userService, WebContext webContext) { |
| | | this.authenticationService = authenticationService; |
| | | this.userService = userService; |
| | | this.webContext = webContext; |
| | | } |
| | | private final DepartmentMapper departmentMapper; |
| | | |
| | | @Override |
| | | public Authentication authenticate(Authentication authentication) throws AuthenticationException { |
| | |
| | | throw new LockedException("用户被禁用"); |
| | | } |
| | | |
| | | // // 查询该用户是不是部门管理员 |
| | | // Integer num = departmentMapper.countByAdminId(user.getId()); |
| | | |
| | | ArrayList<GrantedAuthority> grantedAuthorities = new ArrayList<>(); |
| | | // 赋予部门管理员角色 |
| | | if (DeptAdminEnum.YES.getValue().equals(user.getDeptAdmin())) { |
| | | grantedAuthorities.add(new SimpleGrantedAuthority(RoleEnum.DEPT_ADMIN.getRoleName())); |
| | | } |
| | | grantedAuthorities.add(new SimpleGrantedAuthority(RoleEnum.fromCode(user.getRole()).getRoleName())); |
| | | |
| | | User authUser = new User(user.getUserName(), user.getPassword(), grantedAuthorities); |