嗨,我使用spring security,我的配置在数据库中:
<sec:http auto-config="true" entry-point-ref="casProcessingFilterEntryPoint">
<sec:remember-me />
<sec:session-management>
<sec:concurrency-control max-sessions="1"
error-if-maximum-exceeded="true" />
</sec:session-management>
<sec:logout logout-success-url="${host.url}/logout/" />
<sec:custom-filter ref="casAuthenticationFilter"
after="CAS_FILTER" />
<sec:custom-filter ref="filterInvocationInterceptor"
before="FILTER_SECURITY_INTERCEPTOR" />
</sec:http>
就像数据库中的${host.url}
一样
我该如何初始化?
所以,我这样做:
public class SnsPropertyResourceConfigurer extends GrailsPlaceholderConfigurer{
private BeanFactory beanFactory;
protected void loadProperties(Properties props) throws IOException {
setSystemPropertiesMode(2);
ConfigObject config = ConfigurationHolder.getConfig();
if(config != null) {
props.putAll(config.toProperties());
}
Properties add = addProperties();
if(add != null){
props.putAll(add);
}
}
private Properties addProperties(){
InfoFetchClientRpcService infoFetchRpcService = (InfoFetchClientRpcService)beanFactory.getBean("infoFetchRpcService");
Map<String, Application> apps = infoFetchRpcService.getAppInfo();
Application thisApp = apps.get("sns");
Application casApp = apps.get("cas");
Properties props = new Properties();
props.setProperty("cas.loginUrl", "11111111");
props.setProperty("cas.logoutUrl", "222222222222");
props.setProperty("cas.validator", casApp.getUrl());
props.setProperty("cas.service",thisApp.getUrl()+"/j_spring_cas_security_check");
props.setProperty("cas.defaultTargetUrl", thisApp.getSuccessUrl());
props.setProperty("cas.defaultFailureUrl", thisApp.getFailureUrl());
props.setProperty("cas.logout", thisApp.getLogoutUrl());
props.setProperty("cas.logoutSuccessUrl", thisApp.getUrl());
props.setProperty("cas.ticket.key", "sns");
return props;
}
public void setBeanFactory(BeanFactory beanFactory) {
this.beanFactory = beanFactory;
}
}
和
<bean name="snsPropertyResourceConfigurer" class="com.ai.sns.init.SnsPropertyResourceConfigurer">
</bean>
但不影响...
答案 0 :(得分:2)
子类PropertyPlaceholderConfigurer
并实现从数据库加载。然后在applicationContext.xml
中将该类添加为bean(就好像它是常规的PropertyPlaceholderConfigurer
)
答案 1 :(得分:0)
我解决了这个问题...
我在主应用程序上下文中注册了placeholderConfigurer
哪里是web-app/WEB-INF/applicationContext.xml
但不是grails-app/conf/spring/resources.xml
它运作良好
每个人都