SpringSecurity如何定义自己的Provider?如何限制指定的IP?

<!-- http安全配置 -->
	<s:http auto-config="true" use-expressions="true" lowercase-comparisons="false" create-session="ifRequired" >
		 。。。。<s:intercept-url pattern="/pages/**" access="isAuthenticated()" /> 
	</s:http>
	
	 <bean id="loggerListener" class="org.springframework.security.authentication.event.LoggerListener"/>
    
	<s:authentication-manager alias="authenticationManager">
		<s:authentication-provider ref="bobkpiAuthenticationProvider">
		</s:authentication-provider>
	</s:authentication-manager>
	
	<bean id="bobkpiAuthenticationProvider" class="com.resoft.prophet.security.provider.BobkpiAuthenticationProvider">
		<property name="userDetailsService" ref="userDetailsService"></property>
		<property name="ehrUserDAO" ref="ehrUserDAO"/>
	</bean>
	
		
	<!-- 项目实现的用户查询服务  -->
	<bean id="userDetailsService" class="com.resoft.prophet.security.userdetails.UserDetailsServiceImpl">
		<property name="securityService" ref="securityService" />
	</bean>
 

    

1、为什么没有使用userCache?

    以上是springsecurity的配置,考虑到维护userCache的繁杂性,userCache 并没有进行配置。主要原因是角色资源的关联,一旦角色资源关联关系发生变化,Cache还是需要清空,重新插入。

 

  2、 如果需要定义自己的provider?

   

<s:authentication-manager alias="authenticationManager">
		<s:authentication-provider ref="bobkpiAuthenticationProvider">
		</s:authentication-provider>
	</s:authentication-manager>

 

 

 3、use-expressions="true"这个配置什么作用??

  主要是用于isAuthenticated()这样的表达式解析

 

4、springsecurity的源码中HttpConfigurationBuilder中,定义了多达数配置项。

 

5、SecurityExpressionRoot中定义了很多表达式可用于配置的方法名称。

 

默认采用的是WebSecurityExpressionRoot,这个类中有hasIpAddress,可以指定某些IP进行访问。

 

 /**
     * Takes a specific IP address or a range using the IP/Netmask (e.g. 192.168.1.0/24 or 202.24.0.0/14).
     *
     * @param ipAddress the address or range of addresses from which the request must come.
     * @return true if the IP address of the current request is in the required range.
     */
    public boolean hasIpAddress(String ipAddress) {
        return (new IpAddressMatcher(ipAddress).matches(request));
    }

 

 public final boolean isAuthenticated() {
        return !isAnonymous();
    }

   指的是必须为非匿名用户。 

 

   <s:intercept-url pattern="/pages/**" access="hasIpAddress('10.168.166.125')" />

 

  access表达式必须只有一个

 

 关于springsecurity的配置,很多人仍然觉得比较复杂,我是从acegi开始学起的,虽然acegi的配置更复杂,但是对于大多数的关于配置的代码,我看了一遍,对于所有配置还是比较熟悉的,而且很容易进行扩展,新的配置有了新的schema,但是如果和acegi以前的学习成果结合起来学习,印象还是比较深刻的,毕竟springsecurity只是acegi的升级,很多类只是换了个名字。建议将acegi的配置对照起来,原来怎么配置,现在怎么配置,学起来比较快了。

 

  最好看下schema DTD的说明,这样方便你自己的扩展。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值