【发布时间】:2011-01-19 22:16:00
【问题描述】:
希望这是超级简单的,存在的,而且我正在忽略我眼皮底下的一些东西。我知道我可以通过注释限制访问:
@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 插件开箱即用,所以我知道它必须存在。请不要让我的大脑爆炸!!!
编辑:
想通了……
您必须提供自定义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" />
【问题讨论】:
标签: java spring grails spring-mvc spring-security