【问题标题】:Spring Security Remember me with custom authentication providerSpring Security 使用自定义身份验证提供程序记住我
【发布时间】:2023-03-05 01:46:01
【问题描述】:

我正在使用带有 Spring Security 的 GWT。我有一个自定义身份验证提供程序,我在其中执行所有身份验证。如何在不使用 UserDetailsS​​ervice 的情况下配置记住我功能?我没有使用 LDAP。

我的 AppliationContext_security.xml

<http auto-config="true" entry-point-ref="UnauthorizedEntryPoint"
    create-session="always">
    <form-login authentication-success-handler-ref="authenticationSuccessHandler"
        authentication-failure-handler-ref="authenticationFailureHandler" />
    <logout success-handler-ref="logoutSuccessHandler"
        invalidate-session="true" />
    <intercept-url pattern="/**/myapp.rpc" access="ROLE_USER" />

    <custom-filter before="CONCURRENT_SESSION_FILTER" ref="XSRFAttackFilter" />

</http>

<authentication-manager>        
    <authentication-provider ref="myAuthenticationProvider" />
</authentication-manager>

在我的自定义身份验证提供程序中,

@Override
public Authentication authenticate(Authentication authentication)
        throws AuthenticationException {
    String username = (String) authentication.getPrincipal();
    String password = (String) authentication.getCredentials();

    boolean response = loginmanager.authenticateUser(username, password,
            ((ServletRequestAttributes) RequestContextHolder
                    .getRequestAttributes()).getRequest().getSession());
    if (!response) {
        throw new BadCredentialsException(
                "Invalid Credentials.");
    }

    Authentication authentication = ...
    authentication.setAuthenticated(true);

    return authentication;
}

任何帮助将不胜感激。

【问题讨论】:

    标签: spring-security


    【解决方案1】:

    您需要创建一个自定义UserDetailsService,从您的loginmanager 读取用户名/密码的同一位置获取用户名/密码。查看TokenBasedRememberMeServices.processAutoLoginCookie() 的源代码,了解它是如何使用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-29
      • 2014-10-13
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      • 2011-01-03
      • 2016-07-19
      • 2015-08-16
      相关资源
      最近更新 更多