[英]Different Form login in Shiro
Same question where asked under "Multiple logins url in Shiro" but it was unanswered. 在“ Shiro中的多个登录URL”下询问了相同的问题,但未得到回答。
I am trying to have two different loggin page for apache shiro 1) For Mobile devices (little screen, limited javascript different theme) 2) For standard devices 我正在尝试为apache shiro创建两个不同的登录页面1)对于移动设备(小屏幕,有限的javascript不同主题)2)对于标准设备
How can i do? 我能怎么做?
Now only one url is working at a time. 现在一次只能使用一个网址。
shiro.loginUrl = ... shiro.loginUrl = ...
Thankyou 谢谢
You need to extend FormAuthenticationFilter
to be aware of multiple login urls. 您需要扩展FormAuthenticationFilter
才能知道多个登录URL。 It can look like this: 它看起来可能像这样:
public class CustomAuthenticationFilter extends FormAuthenticationFilter {
private Map<String, String> loginUrlByUserAgent = new HashMap<String, String>();
public void setLoginUrls(final Map<String, String> loginUrlByUserAgent) {
this.loginUrlByUserAgent = loginUrlByUserAgent;
}
protected void redirectToLogin(final ServletRequest request, final ServletResponse response) throws IOException {
final String loginUrl = getLoginUrl(request);
WebUtils.issueRedirect(request, response, loginUrl);
}
private String getLoginUrl(final ServletRequest request) {
// check user agent
final String userAgent = getUserAgent(request);
// and return appropriate login url
return userAgent != null && loginUrlByUserAgent.containsKey(userAgent) ?
loginUrlByUserAgent.get(userAgent) :
getLoginUrl();
}
private String getUserAgent(final ServletRequest request) {
// get "User-Agent" header
}
}
Then you just need to replace authc filter with your newly created. 然后,您只需要用新创建的替换authc过滤器即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.