spring security oauth 2でユーザー認証を行い、Redisのユーザー情報をどのように更新するか
4276 ワード
spring security oauth 2でユーザー認証を行い、初めてログインしてaccess_を得るtokenとrefresh_その後、変更します.getContext().getAuthentication()のPrincipal情報ですが、Redisのデータは変更されていません.
oauth 2構成:
資格認定:
UserDetailsの取得:
oauth 2構成:
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.requestMatchers().antMatchers(HttpMethod.OPTIONS, "/oauth/token").and().csrf().disable();
}
資格認定:
@Component
public class PasswdAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider
{
@Autowired
private LoginUserDetailsService loginUserDetailsService;
@Override
protected void additionalAuthenticationChecks(UserDetails userDetails, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException
{
String UserName = authentication.getName();
String Password = (String) authentication.getCredentials();
}
@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException
{
UserDetails userDetails = null;
String UserName = authentication.getName();
String Password = (String) authentication.getCredentials();
userDetails = (UserDetails) loginUserDetailsService.loadUserByUsername(UserName, Password);
if (userDetails == null)
{
throw new UsernameNotFoundException(" : " + username + " .");
}
return userDetails;
}
}
UserDetailsの取得:
public static SecuserEntity getUserInfo() {
SecuserEntity secuserentity = null;
try {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Object principal = authentication == null ? null : authentication.getPrincipal();
if (principal instanceof SecuserEntity) {
secuserentity = (SecuserEntity) principal;
}
} catch (Exception e) {
}
return secuserentity;
}