不调用身份验证提供程序

时间:2015-07-16 19:46:59

标签: spring spring-security

这是我的security-context.xml文件:

<http auto-config='false' authentication-manager-ref="authenticationManager" entry-point-ref="authenticationEntryPoint">
    <intercept-url pattern="/"/>
    <intercept-url pattern="/**"/>
    <csrf disabled="true"/>
    <custom-filter position="REMEMBER_ME_FILTER" ref="DashboardFilter"></custom-filter>
</http>

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="DashboardAuthProvider"></authentication-provider>
</authentication-manager>

<beans:bean id="DashboardFilter" class="com.apple.store.dashboard.security.DashboardAuthFilter">
    <beans:property name="authenticationManager" ref="authenticationManager"/>
</beans:bean>

<beans:bean id="authenticationEntryPoint" class="com.apple.store.dashboard.security.DashboardAuthEntryPoint">
</beans:bean>

<beans:bean id="DashboardAuthProvider" class="com.apple.store.dashboard.security.DashboardAuthProvider">  

我已经定义了DashboardAuthProvider:

public class DashboardAuthProvider implements AuthenticationProvider {

    private static final Logger logger = LoggerFactory.getLogger(DashboardAuthProvider.class);

    @Override 
    public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
         logger.debug("Inside DashboardAuthProvider: authenticate method +authentication=" + authentication);
         Authentication auth = null;
         [...]
    }
}

当我执行代码时,我可以点击过滤器,但不是提供商。我阅读了许多与Spring相关的文档,并且在xml中找不到我的配置有什么问题。有人可以帮忙吗?

这是我的过滤器:

public class DashboardAuthFilter extends AbstractAuthenticationProcessingFilter {

    private static final Logger logger = LoggerFactory.getLogger(DashboardAuthFilter.class);

    public DashboardAuthFilter() {
        super("/**");
    }

    public Authentication attemptAuthentication(final HttpServletRequest request, final HttpServletResponse response)
        throws org.springframework.security.core.AuthenticationException {
        logger.debug("Inside DashboardAuthFilter:attemptAuthentication method:");
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        if (auth!=null ){
            if (auth.isAuthenticated()){
                logger.debug("Previously authenticated.isAuthenticated=true::: Auth details:" +auth);
                return auth;
            }
        }
        //Validate the DS Auth Cookie
        Cookie AOSCookie = WebUtils.getCookie(request, "myacinfo-uat");//

        if ( AOSCookie == null )
        return null;

        Authentication authResult = null;
        try {
            if( org.apache.commons.lang.StringUtils.isEmpty(AOSCookie.toString())) {
                throw new PreAuthenticatedCredentialsNotFoundException("DS Auth Cookie not found. Commence DS Authentication..");
            }
            String credentials = "NA";

            String validateCookieDetails = correctAuthentication(AOSCookie, request);
            logger.debug("validateCookieDetails ....." + validateCookieDetails);
            UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(validateCookieDetails, credentials);
            authResult = getAuthenticationManager().authenticate(authRequest);
            logger.debug("Attempted authentication: authResult ::" + authResult.toString());
        } catch (org.springframework.security.core.AuthenticationException e) {
                logger.error("AttemptAuthentication: Not Authenticated : AuthenticationException ....." + e.getMessage());

        } catch (Exception e) {
            logger.error("Exception occured during authentication....." + e.getMessage());
        }
        return authResult;
    }
}

0 个答案:

没有答案