我创建了一个自定义AuthenticationProvider
,因此我必须使用用户的用户名和密码(例如Authentication
或自定义实现)返回UsernamePasswordAuthenticationToken
实现。 Authentication
实施的此实例将存储在SecurityContext
中。这是一个好习惯吗?密码是否安全存储?谢谢!
public class CustomAuthenticationProvider implements AuthenticationProvider {
@Autowired
private SSOClient ssoClient;
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
String id = authentication.getName();
String password = authentication.getCredentials().toString();
ssoClient.login(id, password);
return new CustomAuthenticationToken(id, password);
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
答案 0 :(得分:1)
我认为在安全文件中存储密码是不安全的,因为可以在整个应用程序中访问安全上下文。我建议我们使用UsernamePasswordAuthenticationToken中的密码进行身份验证并将其删除。