大佬教程收集整理的这篇文章主要介绍了从数据库或属性获取Spring Security拦截URL,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
已经有一段时间了,但是您@R_197_9838@Voter对象,该对象可以帮助决定是否允许访问URL。Voter对象可以从数据库或文件中加载数据,或者只是随机返回Allow,Deny或Abstain。
希望这是非常简单的,存在的,而且我正在俯视我的鼻子下面的东西。我知道我可以通过注释限制访问:
@Secured({"ROLE_ADMIN"})
或通过配置:
<security:intercept-url pattern="/**" access="ROLE_USER,ROLE_ADMIN,ROLE_SUPER_USER" />
我希望从数据库中获取身份验证规则,例如:
<security:intercept-url provider="authprovider"/>
<bean id="authprovider" class="authproviderImpl">
<property name="userDetailsservice" ref="userDetailsservice"/>
</bean>
最坏的情况是,必须有一种通过属性文件填充的方法吗?
/admin/**=ROLE_ADMIN
/**=ROLE_USER
<security:intercept-url props="classpath:urls.properties"/>
等等
请告诉我这存在,否则我的大脑会爆炸!!!Grails的spring-security插件开箱即用,所以我知道这必须存在。请不要让我的大脑爆炸!!!
编辑:
弄清楚了&Hellip;
您必须提供一个自定义org.springframework.security.intercept.web.FilterSecurityInterceptor
并提供objectDefinitionsource
:
<bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
<security:custom-filter before="FILTER_SECURITY_INTERCEPTOR" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="accessDecisionManager" ref="accessDecisionManager" />
<property name="objectDefinitionsource">
<value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/**login.html=IS_AUTHENTICATED_ANONymOUSLY
/user/**=ROLE_ADMIN
</value>
</property>
</bean>
我想我将使用FactoryBean:
public class requestMappingFactoryBean implements FactoryBean {
private final static String EOL = System.getProperty("line.separator");
public Object getObject() throws Exception {
StringBuffer sb = new StringBuffer();
sb.append("CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON");
sb.append(EOL);
sb.append("PATTERN_TYPE_APACHE_ANT");
sb.append(EOL);
sb.append("/**login.html=IS_AUTHENTICATED_ANONymOUSLY");
sb.append(EOL);
sb.append("/user/**=ROLE_ADMIN");
return sb.toString();
}
@SuppressWarnings("unchecked")
public Class getObjectType() {
return String.class;
}
public Boolean isSingleton() {
return true;
}
}
将其传递给DAO等
<bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
<security:custom-filter before="FILTER_SECURITY_INTERCEPTOR" />
<property name="authenticationManager" ref="authenticationManager" />
<property name="accessDecisionManager" ref="accessDecisionManager" />
<property name="objectDefinitionsource" ref="requestMappings" />
</bean>
<bean id="requestMappings" class="requestMappingFactoryBean" />
以上是大佬教程为你收集整理的从数据库或属性获取Spring Security拦截URL全部内容,希望文章能够帮你解决从数据库或属性获取Spring Security拦截URL所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。