springMVC integrated shiro permission authentication framework, the problem Log on to log does not appear after logging

There are two solutions:

1. Configure section of the welcome page in the web.xml file:

<welcome-file-list>
    <welcome-file>/index.do</welcome-file>     
 </welcome-file-list>

 

 2. In the Customize Form Filler MyFormAuthenticationFilter, the add remove shiro visit on sesion stored address shiroSavedReques 

 

 1 package cn.zj.logistic.shiro;
 2 
 3 import javax.servlet.ServletRequest;
 4 import javax.servlet.ServletResponse;
 5 import javax.servlet.http.HttpServletRequest;
 6 
 7 import org.apache.commons.lang3.StringUtils;
 8 import org.apache.shiro.authc.AuthenticationToken;
 9 import org.apache.shiro.session.Session;
10 import org.apache.shiro.subject.Subject;
11 import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
12 import org.apache.shiro.web.util.WebUtils;
13 
14 public class MyFormAuthenticationFilter extends FormAuthenticationFilter {
15 
16     @Override
17     protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
18 
19         HttpServletRequest req = (HttpServletRequest) request;
20 
21         // 1.获取前台表单提交的验证码
22         String verifyCode = req.getParameter("verifyCode");
23 
24         
25         
26         RAND = String (String) the req.getSession () the getAttribute ( "RAND." );
 27  
28          System.out.println ( "RAND:" + RAND);
 29  
30          IF (StringUtils.isNotBlank (verifyCode)) {
 31 is              IF ( ! verifyCode.equals (rand.toLowerCase ())) {
 32                  // share an error message to shiroLoginFailure 
33 is                  request.setAttribute ( "shiroLoginFailure", "verifyCodeError" );
 34 is  
35                  // returns true, shiro no longer the next operation (authentication database), the direct return of 
36                  return  to true ;
 37 [              }
 38 is          }
 39  
40         return super.onAccessDenied(request, response);
41     }
42 
43     @Override
44     protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request,
45             ServletResponse response) throws Exception {
46                 
47     
48         // 1.获取sesssion
49         Session session = subject.getSession(false);
50         if (session != null) {
51             // 清除shiro共享的上一次地址 ://shiroSavedRequest
52             session.removeAttribute(WebUtils.SAVED_REQUEST_KEY);
53         }
54 
55         return super.onLoginSuccess(token, subject, request, response);
56     }
57 
58 }

 

Guess you like

Origin www.cnblogs.com/abcdjava/p/11241457.html