我正在使用Spring BOOT + OAUTH2,并希望在成功登录后将用户对数据库注册表的访问权限保存起来...搜索解决方案我遇到了此类:https : //docs.spring.io/spring -security / oauth / apidocs / org / springframework / security / oauth2 / provider / endpoint / TokenEndpointAuthenticationFilter.html
所以我实现了这样的方法: CustomTokenEndpointAuthenticationFilter.java
public class CustomTokenEndpointAuthenticationFilter extends TokenEndpointAuthenticationFilter {
public CustomTokenEndpointAuthenticationFilter(AuthenticationManager authenticationManager, OAuth2RequestFactory oAuth2RequestFactory) {
super(authenticationManager, oAuth2RequestFactory);
}
@Override
protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
/* on successful authentication do stuff here */
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
/* before authentication …Run Code Online (Sandbox Code Playgroud)