shiro配置successUrl卻不跳轉的問題java
shiroFilter配置web
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager" /> <!-- 配置咱們的登陸請求地址 --> <property name="loginUrl" value="/login" /> <!-- 配置咱們在登陸頁登陸成功後的跳轉地址, 源碼中fallbackUrl其實就是你shiroFilter bean裏面設置的successUrl, 可是successUrl在被fallbackUrl賦值以前就已經被savedRequest.getRequestUrl()取代了, 若是真要解決,就得繼承FormAuthenticationFilter --> <!--<property name="successUrl" value="/" />--> <!-- 若是您請求的資源再也不您的權限範圍,則跳轉到如下請求地址 --> <property name="unauthorizedUrl" value="/403" /> <!-- 權限配置 --> <property name="filterChainDefinitions"> <value> <!-- anon表示此地址不須要任何權限便可訪問 --> /static/**=anon <!-- perms[user:query]表示訪問此鏈接須要權限爲user:query的用戶 --> /user=perms[user:query] <!--/user=roles[normal]--> <!-- roles[manager]表示訪問此鏈接須要用戶的角色爲manager --> /user/add=roles[manager] /user/del/**=roles[admin] /user/edit/**=roles[manager] <!--全部的請求(除去配置的靜態資源請求或請求地址爲anon的請求)都要經過登陸驗證,若是未登陸則跳到/login--> /user/** = authc </value> </property> </bean>
跟蹤源碼以下:spring
public static void redirectToSavedRequest(ServletRequest request, ServletResponse response, String fallbackUrl) throws IOException { String successUrl = null; boolean contextRelative = true; SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request); if (savedRequest != null && savedRequest.getMethod().equalsIgnoreCase(AccessControlFilter.GET_METHOD)) { successUrl = savedRequest.getRequestUrl(); contextRelative = false; } if (successUrl == null) { successUrl = fallbackUrl; } if (successUrl == null) { throw new IllegalStateException("Success URL not available via saved request or via the " + "successUrlFallback method parameter. One of these must be non-null for " + "issueSuccessRedirect() to work."); } WebUtils.issueRedirect(request, response, successUrl, null, contextRelative); }
源碼中fallbackUrl其實就是你shiroFilter bean裏面設置的successUrl, 可是successUrl在被fallbackUrl賦值以前就已經被savedRequest.getRequestUrl()取代了, 若是真要解決,就得繼承FormAuthenticationFilterapache