2016-11-01 7 views
0

У меня есть несколько конфигураций security:http в моем xml с разными точками ввода-ссылки. Я пытаюсь преобразовать этот конфиг в java config.Преобразование нескольких конфигураций http-конфигурации securiy из конфигурации xml в java

Я читал, что это возможно, используя несколько подкласс, расширяя WebSecurityConfigurerAdapter.

Как мне настроить точку входа-ref для каждого из них в java config?

follwing - это xml config.

<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

Конфигурация безопасности с классами Java для начала предоставления классов @Configuration подклассов org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter для «веба» части (запрос) и org.springframework. security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration для «глобальной» части (уровня сервиса).

В подклассу WebSecurityConfigurerAdapter, вы должны переопределить некоторые "Configure (...)" методы: (только примеры ...)

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()); 
} 

В этом @Configuration классе, вы должны/может также иметь бобы для MethodSecurityMetadataSource, AccessDecisionManager, AccessDecisionVoter, ... ваших поставщиков проверки подлинности, ...

Тот же принцип ваш @Configuration, суб-класс GlobalMethodSecurityConfiguration:

protected AccessDecisionManager accessDecisionManager() { 
... 
} 

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

protected MethodSecurityExpressionHandler createExpressionHandler() { 
    ...; 
} 


@Bean 
public MethodSecurityExpressionHandler methodSecurityExpressionHandler() { 
... 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^