2010-05-28 94 views
0

喜春豆,我使用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

为什么你直接继承'GrailsPlaceholderConfigurer'而不是'PropertyPlaceholderConfigurer'? – skaffman 2010-05-28 07:48:52

+0

因为我使用grails,而grails使用GrailsPlaceholderConfigurer – user340017 2010-05-28 08:28:08

+1

@skaffman所以在那里。 – Andy 2011-04-28 11:50:08

回答

2

子类PropertyPlaceholderConfigurer并实现从数据库加载。然后添加类作为一个bean在applicationContext.xml(就好像它是常规PropertyPlaceholderConfigurer