首页 文章

当重写UsernamePasswordAuthenticationFilter类的方法时,eclipse在spring-security中显示错误

提问于
浏览
1

我想在我的Spring-MVC中为登录和注销页面创建具有不同角色的不同用户名 .

我从下面链接研究过,我使用的是 spring 4.2.5:

http://www.raistudies.com/spring-security-tutorial/role-based-spring-jsp-taglibs/

但我的一个 class 显示错误:

public class AjaxAuthenticationProcessingFilter extends
UsernamePasswordAuthenticationFilter {

    @Override
    protected void successfulAuthentication(HttpServletRequest request,
            HttpServletResponse response, Authentication authResult)
            throws IOException, ServletException {
        super.successfulAuthentication(request, response, authResult);
    }
}

Eclipse shoeing编译时方法错误

AjaxAuthenticationProcessingFilter类型的方法successAuthentication(HttpServletRequest,HttpServletResponse,Authentication)必须覆盖或实现超类型方法

和其他错误是当我调用超级 super.successfulAuthentication(request, response, authResult);successfulAuthentication 方法时 .

您可以看到下面给出的错误:

AbstractAuthenticationProcessingFilter类型中的方法successAuthentication(HttpServletRequest,HttpServletResponse,FilterChain,Authentication)不适用于参数(HttpServletRequest,HttpServletResponse,Authentication)

如果有人知道 spring 安全的任何链接以实现具有不同角色的不同用户,那么请在spring-xml配置的帮助下告诉我 .

1 回答

  • 1

    尝试以下代码..检查您的导入 .

    And Mainly

    successfulAuthentication(HttpServletRequest request,
                HttpServletResponse response,Authentication authResult)
    

    已弃用 .

    Use

    successfulAuthentication(HttpServletRequest request,
                HttpServletResponse response,FilterChain a, Authentication authResult)
    

    最后,

    import java.io.IOException;
    
    import javax.servlet.FilterChain;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.security.core.Authentication;
    import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
    
    public class AjaxAuthenticationProcessingFilter extends
    UsernamePasswordAuthenticationFilter {
    
        @Override
        protected void successfulAuthentication(HttpServletRequest request,
                HttpServletResponse response,FilterChain filter, Authentication authResult)
                throws IOException, ServletException {
            super.successfulAuthentication(request, response,filter, authResult);
    
        }
    
    }
    

相关问题