有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring AuthenticationManager是否将有效令牌保存在内存中的某个位置?

Spring AuthenticationManager是否将有效令牌保存在内存中的某个位置

或者我们应该将有效令牌保存在某个表/db中?这已经在Spring security中实现了吗

这是我的Spring boot应用程序的登录筛选器:

public class JWTLoginFilter extends AbstractAuthenticationProcessingFilter {


    public JWTLoginFilter(String url, AuthenticationManager authManager) {
        super(new AntPathRequestMatcher(url));
        setAuthenticationManager(authManager);
    }

    @Override
    public Authentication attemptAuthentication(HttpServletRequest req,
            HttpServletResponse res) throws AuthenticationException,
            IOException, ServletException {

        CustomUserDetails creds = new ObjectMapper().readValue(
                req.getInputStream(), CustomUserDetails.class);

        return getAuthenticationManager().authenticate(
                new UsernamePasswordAuthenticationToken(creds.getUsername(),
                        creds.getPassword()));
    }

    @Override
    protected void successfulAuthentication(HttpServletRequest req,
            HttpServletResponse res, FilterChain chain, Authentication auth) {
        TokenAuthenticationService.addAuthentication(res, auth.getName());
    }
}

共 (0) 个答案