| | |
| | | package com.ycl.jxkg.config.spring.security; |
| | | |
| | | |
| | | import com.github.benmanes.caffeine.cache.Cache; |
| | | import com.ycl.jxkg.constants.CaffeineConstant; |
| | | import com.ycl.jxkg.context.WebContext; |
| | | import com.ycl.jxkg.enums.RoleEnum; |
| | | import com.ycl.jxkg.enums.UserStatusEnum; |
| | | import com.ycl.jxkg.service.AuthenticationService; |
| | | import com.ycl.jxkg.service.UserService; |
| | | import com.ycl.jxkg.utils.CaffeineUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationProvider; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | |
| | | private final AuthenticationService authenticationService; |
| | | private final UserService userService; |
| | | private final WebContext webContext; |
| | | private final CaffeineUtil caffeineUtil; |
| | | |
| | | /** |
| | | * Instantiates a new Rest authentication provider. |
| | |
| | | * @param webContext the web context |
| | | */ |
| | | @Autowired |
| | | public RestAuthenticationProvider(AuthenticationService authenticationService, UserService userService, WebContext webContext) { |
| | | public RestAuthenticationProvider(AuthenticationService authenticationService, UserService userService, WebContext webContext, CaffeineUtil caffeineUtil) { |
| | | this.authenticationService = authenticationService; |
| | | this.userService = userService; |
| | | this.webContext = webContext; |
| | | this.caffeineUtil = caffeineUtil; |
| | | } |
| | | |
| | | @Override |
| | |
| | | grantedAuthorities.add(new SimpleGrantedAuthority(RoleEnum.fromCode(user.getRole()).getRoleName())); |
| | | |
| | | User authUser = new User(user.getUserName(), user.getPassword(), grantedAuthorities); |
| | | |
| | | // 登录之后保存到内存中 |
| | | caffeineUtil.put(CaffeineConstant.AUTH, authUser.getUsername(), authUser); |
| | | return new UsernamePasswordAuthenticationToken(authUser, authUser.getPassword(), authUser.getAuthorities()); |
| | | } |
| | | |