2016-11-01 9 views
0

私のxmlには、異なる入力ポイント-refを持つ複数のsecurity:http設定があります。私はこの設定をJavaの設定に変換しようとしています。複数のsecuriy http設定をxmlからjava設定に変換する

これは、WebSecurityConfigurerAdapterを拡張する複数のサブクラスを使用して可能であることを読んでいます。

java configでこれらのエントリポイントをどのように設定すればよいですか?

フォローはXML設定です。 Javaクラスと

<security:http request-matcher-ref="preReqMatcher" auto-config="false" use-expressions="false" entry-point- ref="preAuthenticatedProcessingFilterEntryPoint"> 
    <custom-filter position="PRE_AUTH_FILTER" ref="preAuthFilter" /> 
    <custom-filter after="CAS_FILTER" ref="attrFilter" /> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 
    <csrf disabled="true"/> 
</security:http> 

<security:http auto-config="true" entry-point-ref="casEntryPoint" use-expressions="false" disable-url-rewriting="false"> 
    <custom-filter position="CAS_FILTER" ref="casFilter" /> 
    <custom-filter after="CAS_FILTER" ref="attrFilter" /> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 
    <custom-filter ref="testFilter" before="CAS_FILTER" /> 
    <csrf disabled="true"/> 
</security:http> 

答えて

0

以下は、私がエントリーポイントを設定する方法です。

http.httpBasic().authenticationEntryPoint(preAuthenticatedProcessingFilterEntryPoint);

0

セキュリティの設定は、「ウェブ」の部分(リクエスト)とorg.springframeworkためorg.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapterをサブクラスあなた@Configurationクラスを提供することから始めます。 "グローバル"部分(サービス層)のsecurity.config.annotation.method.configuration.GlobalMethodSecurityConfiguration。 (単なる例...)その@Configurationクラスで

public void configure(final WebSecurity web) throws Exception { 
      // @formatter:off 
      web.ignoring() 
       .antMatchers("/*.html","/*.ico","/css/**","/html/**","/i18n/**","/img/**","/js/**","/lib/**"); 
      // @formatter:on 
} 

protected void configure(final HttpSecurity http) throws Exception { 

http.headers() 
       .addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsMode.SAMEORIGIN)) 
       .and() 
        .csrf().disable() 
        .addFilterAfter(jeePreAuthenticatedFilter(), AbstractPreAuthenticatedProcessingFilter.class) 
        .addFilterBefore(new BasicAuthenticationFilter(authenticationManagerBean()), 
         UsernamePasswordAuthenticationFilter.class) 
        .addFilterBefore(switchUserProcessingFilter(), SwitchUserFilter.class) 
        .authorizeRequests() 
         .antMatchers("/*.html","/*.ico","/css/**","/html/**","/i18n/**","/img/**","/js/**","/lib/**").permitAll() 
         .anyRequest().authenticated() 

       .and() 
        .sessionManagement() 
        .sessionFixation().none().maximumSessions(maxSessionsPerUser) 
        .sessionRegistry(sessionRegistry) 
       ; 

} 

protected void configure(final AuthenticationManagerBuilder auth) throws Exception { 
    auth.authenticationProvider(basicDAOAuthenticationProvider()); 
    auth.authenticationProvider(preauthAuthProvider()); 
} 

、あなたがすべき/:WebSecurityConfigurerAdapterのサブクラスで

は、あなたには、いくつかの "設定(...)" メソッドをオーバーライドする必要があります

protected AccessDecisionManager accessDecisionManager() { 
... 
} 

protected void configure(final AuthenticationManagerBuilder auth) throws Exception { 
... 
} 

protected MethodSecurityExpressionHandler createExpressionHandler() { 
    ...; 
} 


@Bean 
public MethodSecurityExpressionHandler methodSecurityExpressionHandler() { 
... 
} 
:またあなたの@Configuration、GlobalMethodSecurityConfigurationのサブクラスMethodSecurityMetadataSource、AccessDecisionManager、AccessDecisionVoter、...あなたの認証プロバイダの豆、...

同じ原理を持つことができます

関連する問題