代码片段(3)[全屏查看所有代码]
1. [代码][Java]代码
1
2
3
4
5
6
7
|
<beans:bean id=
"customlogin"
class
=
"com.sniper.springmvc.shiro.filter.CustomLogonUrl"
>
<beans:property name=
"loginUrl"
value=
"/company/login"
/>
</beans:bean>
//增加模块的filter的控制
/company/**=customlogin
|
2. [代码][Java]代码
1
2
3
4
5
6
|
<beans:property name=
"filters"
>
<beans:map>
<beans:entry key=
"kickout"
value-ref=
"kickout"
/>
<beans:entry key=
"customlogin"
value-ref=
"customlogin"
/>
</beans:map>
</beans:property>
|
3. [文件] CustomLogonUrl.java ~ 1KB 下载(0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package
com.sniper.springmvc.shiro.filter;
import
javax.servlet.ServletRequest;
import
javax.servlet.ServletResponse;
import
javax.servlet.http.HttpServletRequest;
import
org.apache.shiro.subject.Subject;
import
org.apache.shiro.web.filter.AccessControlFilter;
import
org.apache.shiro.web.util.WebUtils;
/**
* 控制企业没有登录访问页面似的转向
*
* @author suzhen
*
*/
public
class
CustomLogonUrl
extends
AccessControlFilter {
@Override
protected
boolean
isAccessAllowed(ServletRequest request,
ServletResponse response, Object mappedValue)
throws
Exception {
return
false
;
}
@Override
protected
boolean
onAccessDenied(ServletRequest request,
ServletResponse response)
throws
Exception {
// 获取当前网页地址
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
httpServletRequest.getRequestURI();
Subject subject = getSubject(request, response);
if
(!subject.isAuthenticated() && !subject.isRemembered()) {
WebUtils.issueRedirect(request, response, getLoginUrl());
return
false
;
}
return
true
;
}
}
|