在我的应用程序中,我需要针对外部工具进行身份验证。
我不确定用户认证后如何创建和注册会话范围的bean。这就是我现在所拥有的:
@Component
public class ExternalToolAuthenticationProvider implements AuthenticationProvider {
private final GenericApplicationContext applicationContext;
@Autowired
public CmsAuthenticationProvider(GenericApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String name = authentication.getName();
String password = authentication.getCredentials().toString();
Session externalSession = createSession(name, password);
if (externalSession.isAuthenticated()) {
// Somehow register session scoped bean here
return new UsernamePasswordAuthenticationToken(name, password, new ArrayList<>());
} else {
return null;
}
}
@Override
public boolean supports(Class<?> authentication) {
return authentication.equals(UsernamePasswordAuthenticationToken.class);
}
}
关于如何以编程方式创建和注册作用域bean的会话的任何提示? 另外,如果我注销用户,是否可以确保Spring Session被销毁?
谢谢你!