我在spring security中编写了自定义过滤器,但过滤器没有被调用。我通过在过滤器类中添加日志语句来确保这一点。不知道错过了哪里或做错了。找到以下代码:
popUpClassFilter.java
public class popUpClassFilter implements AuthenticationSuccessHandler {
private static final Logger log = LoggerFactory.getLogger(popUpClass.class);
@Override
public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
//do some logic here if you want something to be done whenever
//the user successfully logs in.
log.debug("Entered into customfilter");
HttpSession session = httpServletRequest.getSession();
User user = SecurityClass.getUserDetails();
session.setAttribute("id", user.ID());
session.setAttribute("state", user.State());
//set our response to OK status
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
//since we have created our custom success handler, its up to us to where
//we will redirect the user after successfully login
httpServletResponse.sendRedirect("home");
}
}
的Config.xml
<bean id="popUpClass" class="myPackage.security.popUpClassFilter" />
<security:http entry-point-ref="myAppAuthEntryPoint" use-expressions="true">
.............
<security:custom-filter after="LOGIN_FILTER" ref="popUpFilter"/>
</security:http>
提前感谢。
答案 0 :(得分:-1)
<bean id="customAuthenticationSuccessHandler" class="myPackage.security.popUpClassFilter" />
并添加此
<security:form-login login-page="/login" authentication-success-handler-ref="customAuthenticationSuccessHandler" />
最好的问候