我想在 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 显示方法的编译时错误,
The method successfulAuthentication(HttpServletRequest, HttpServletResponse, Authentication) of type AjaxAuthenticationProcessingFilter must override or implement a supertype method
其他错误是当我调用 successfulAuthentication
方法时
父类(super class) super.successfulAuthentication(request, response, authResult);
.
您可以看到下面给出的错误:
The method successfulAuthentication(HttpServletRequest, HttpServletResponse, FilterChain, Authentication) in the type AbstractAuthenticationProcessingFilter is not applicable for the arguments (HttpServletRequest, HttpServletResponse, Authentication)
如果有人知道 spring security 的任何链接来实现具有不同角色的不同用户,请在 spring-xml 配置的帮助下让我知道。
最佳答案
尝试下面的代码..检查您的导入。
主要
successfulAuthentication(HttpServletRequest request,
HttpServletResponse response,Authentication authResult)
已弃用。
使用
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);
}
}
关于java - 当重写 UsernamePasswordAuthenticationFilter 类的方法时,eclipse 在 spring-security 中显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37158964/