Spring Security3 摘要笔记

<http use-expressions="true">  
<!-- 非匿名用户就允许访问 -->  
<intercept-url pattern="/index.jsp" access="isAuthenticated()"/>  


<form-login login-page="/login.jsp" authentication-failure-url="/login.jsp?error=true"  always-use-default-target="true" default-target-url="/index.jsp" />  
<logout logout-success-url="/login.jsp"/>  

<!-- 没有权限访问的页面 -->  
<access-denied-handler error-page="/403.jsp"/>  
<session-management></session-management>  
<remember-me/>  
<custom-filter ref="myFilter" before="FILTER_SECURITY_INTERCEPTOR"/>  
</http>  

AntPathRequestMatcher(** 匹配0或者更多的目录,如/aa/** 可以配 /aa /aa/bb …)

// 加载地址资源与角色关系
private void loadResourceDefine() {
	resourceMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>();
	Map<String, String> resource = getResource();
	for (Map.Entry<String, String> entry : resource.entrySet()) {
		Collection<ConfigAttribute> configAttributes = new ArrayList<ConfigAttribute>();
		configAttributes.add(new SecurityConfig(entry.getValue()));
		resourceMap.put(new AntPathRequestMatcher(entry.getKey()), configAttributes);
	}
}

// 返回所请求资源所需要的权限
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
	HttpServletRequest request = ((FilterInvocation) object).getRequest();
	if (null == resourceMap) {
		System.out.println("请求地址 " + ((FilterInvocation) object).getRequestUrl());
		loadResourceDefine();
		System.out.println("我需要的认证:" + resourceMap.toString());
	}
	for (Map.Entry<RequestMatcher, Collection<ConfigAttribute>> entry : resourceMap.entrySet()) {
	    // 通过matches方法进行资源匹配
		if (entry.getKey().matches(request)) {
			return entry.getValue();
		}
	}
	return null;
}

参考地址:
https://www.cnblogs.com/fan-yuan/p/6249064.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值