1
A
回答
0
:)我需要的其他方式,我想獲得一個401
而不是重定向(302
)。你目前的設置是什麼?你能從shiro.ini
文件配置這個嗎?
0
不確定您正在使用哪種技術堆棧,但是在Java Web應用程序中,您可以在標記中的web.xml中配置它。
<error-page>
<error-code>401</error-code>
<location>{path to custom page}</location>
</error-page>
3
我發現只有一條路,如何改變重定向到的login.jsp以響應與401
你應該創建自己的過濾器,這將延長org.apache.shiro.web.filter。 authc.FormAuthenticationFilter,並覆蓋saveRequestAndRedirectToLogin()方法。
public class SecurityAuthenticationFilter extends FormAuthenticationFilter {
@Override
protected void saveRequestAndRedirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
saveRequest(request);
sendChallenge(response);
}
protected void sendChallenge(ServletResponse response) {
HttpServletResponse httpResponse = WebUtils.toHttp(response);
httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
}
我使用Guice + Shiro集成。因此,此過濾器的添加方式與org.apache.shiro.guice.web.ShiroWebModule中的相同。
public class SecurityModule extends ShiroWebModule {
public static final Key<SecurityAuthenticationFilter> AUTHC_REST = Key.get(SecurityAuthenticationFilter.class);
...
@Override
protected void configureShiroWeb() {
...
// Add as filter
addFilterChain("/rest/login", ANON);
addFilterChain("/rest/**", AUTHC_REST);
...
}
}
對於shiro.ini文件應該在以下方式添加:
[main]
authc = package.path.to.SecurityAuthenticationFilter
[urls]
/rest/login = anon
/rest/** = authc
這應該工作:)
相關問題
- 1. Dropwizard-Shiro:登錄後即使未經授權訪問
- 2. 如何顯示已驗證但未經授權的用戶未經授權的頁面MVC 3?
- 3. Maven錯誤:未經授權,ReasonPhrase:未經授權
- 4. LinqToTwitter的OAuth未經授權
- 5. 未經授權的指紋
- 6. 未經授權的藍郵
- 7. 使用OWIN授權經典ASP頁面
- 8. Web API StatusCode未經授權的登錄頁面源代碼
- 9. 在ASP.NET中強制定製HTTP 401未經授權的頁面
- 10. rails設計401未經授權的特定頁面
- 11. Laravel未經授權的頁面時,AJAX請求發送
- 12. 如何爲未經授權的用戶重定向頁面
- 13. ASP.NET WindowsAuthentication自定義401未經授權的錯誤頁面
- 14. PHP腳本阻止未經授權的用戶訪問頁面
- 15. 避免頁面未經授權的訪問通過改變MVC3
- 16. Ominauth-的Evernote,的OAuth ::使用了未經授權401未授權
- 17. Shiro LDAP授權配置
- 18. 從未經授權的頁面重定向到索引頁面php
- 19. MVC3重定向到「未經授權」頁面不工作?
- 20. EWS&VB.Net:未經授權的證書 - (401)未授權
- 21. MongoDB未經授權:replSetGetConfig
- 22. Pushwoosh報告未經授權
- 23. HtmlAgilityPack LoadHtml未經授權401
- 24. com.google.api.client.auth.oauth2.TokenResponseException:401未經授權
- 25. 未經授權編輯
- 26. 401(未經授權)WebResource.axd
- 27. 401未經授權與jquery
- 28. 覆蓋ASP.NET MVC中的授權屬性
- 29. MVC 5 - 角色授權 - 自定義未授權頁面
- 30. 「未經授權:未經授權」消息,當推泊塢窗容器Bluemix
感謝豬頭...這個解決我的問題。 +1 – Alexandre