shiroの権限のないページを無効にする方法を知る必要があります。ユーザーが保護されたURLに対して何らかの許可を持っていない場合、shiroは401ページを返します。ユーザーを事前定義された権限のないページに転送する方法を教えてください。shiro unauthorized page
おかげで...
shiroの権限のないページを無効にする方法を知る必要があります。ユーザーが保護されたURLに対して何らかの許可を持っていない場合、shiroは401ページを返します。ユーザーを事前定義された権限のないページに転送する方法を教えてください。shiro unauthorized page
おかげで...
:)私は周りに他の方法を必要とする、私の代わりにリダイレクト(302
)の401
を取得したいのですが。あなたの現在の設定は何ですか? shiro.ini
ファイルから設定できますか?
使用しているテクノロジスタックは不明ですが、Java Webアプリケーションではタグ内のweb.xmlでこれを設定できます。
<error-page>
<error-code>401</error-code>
<location>{path to custom page}</location>
</error-page>
私はあなたがorg.apache.shiro.web.filterを延長する独自のフィルタを作成する必要があり401
と応答にlogin.jspにするためにリダイレクトを変更する方法、唯一の方法を発見しました。 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 – Alexandre