So erstellen Sie ein benutzerdefiniertes UserDetail-Objekt in Spring Security
Ich habe meinen benutzerdefinierten Authenticaton Manager für Spring Security erstellt, der ungefähr so funktioniert
public class AccountAuthenticationProvider implements AuthenticationProvider{
@Autowired
private AuthenticationService authService;
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String userName = authentication.getName();
String password = (String)authentication.getCredentials();
if(authService.isValid(userName,password)){
List<GrantedAuthority> grantedAuthorityList = new ArrayList<GrantedAuthority>();
grantedAuthorityList.add(new SimpleGrantedAuthority("ROLE_USER"));
SecurityContext securityContext = new SecurityContextImpl();
return new UsernamePasswordAuthenticationToken(userName,password);
}
return null;
}
public void setAuthService(AuthenticationService authService) {
this.authService = authService;
}
@Override
public boolean supports(Class<?> authentication) {
return true;
}
}
Aber wie erstelle ich mein eigenes benutzerdefiniertes UserDetail-Objekt? Ich werde das verwenden, um kontobezogene Werte zu speichern