springsecurity Run-As认证服务

<security:authentication-manager alias="authenticationManager">
	<security:authentication-provider ref="daoAuthenticationProvider" />
	<security:authentication-provider ref="runAsImplAuthenticationProvider" />
</security:authentication-manager>

 

<bean id="methodSecurityInterceptor" class="org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor">  
	<property name="authenticationManager" ref="authenticationManager" />
	<property name="accessDecisionManager" ref="accessDecisionManager" />
	<property name="securityMetadataSource" ref="delegatingMethodSecurityMetadataSource" />
	<property name="runAsManager" ref="runAsManager" />
	<property name="objectDefinitionSource">
		<value>
			zhangxin.security.service.RoleService.loadMenu=ROLE_USER, RUN_AS_TEMP
			zhangxin.security.RunAsDemo.RunAsDate.showDate=ROLE_ADMIN, ROLE_RUN_AS_TEMP
		</value>
	</property>
</bean>

 

 

<!-- 替换验证身份 -->
<bean id="runAsImplAuthenticationProvider" class="org.springframework.security.access.intercept.RunAsImplAuthenticationProvider">
	<property name="key" value="javaee" />
</bean>

<bean id="runAsManager" class="org.springframework.security.access.intercept.RunAsManagerImpl">
	<property name="key" value="javaee" />
</bean>

 

objectDefinitionSource 与 delegatingMethodSecurityMetadataSource 一样,都为获取的资源。

 

 

以上配置

zhangxin.security.service.RoleService.loadMenu              简称方法A

zhangxin.security.RunAsDemo.RunAsDate.showDate      简称方法B

 

用户要访问方法B,而用户拥有的角色为ROLE_USER,

访问方法B,需要角色为ROLE_RUN_AS_TEMP,

 

那么此时就必须使用户拥有角色ROLE_RUN_AS_TEMP,才能访问方法B。

 

关键点再这里:

 

访问方法A的过程中会拥有以'RUN_AS'开头的RUN_AS_TEMP角色,实际过程中还会再加上角色前缀'ROLE_',也就是ROLE_RUN_AS_TEMP角色。

 

该用户在拥有角色ROLE_USER在执行方法A的过程中,拥有ROLE_RUN_AS_TEMP角色,在执行方法A过程中可以调用方法B。

 

注意: 用户执行方法A之前,没有ROLE_RUN_AS_TEMP角色,执行方法过程中才有,执行完毕后,自动移除ROLE_RUN_AS_TEMP角色。

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值