2015-02-11 7 views
6

Chcę zdefiniować coś podobnego do tego XML w wiosennym Boot wykorzystaniem Java Config.Jak mogę określić http „security = 'none' w JavaConfig?

<http pattern="/webservices/**" security="none"/>

muszę inny sposób ich zabezpieczania i nie można tworzyć logowań formularza Zabezpieczanie ich nastąpi później .. Na razie chcę zatrzymać ich zabezpieczanie za pomocą metody http.formLogin().

Nadpisałem obiekt WebSecurityConfigurerAdapter.configure() jako taki. Nie mogę znaleźć interfejsu API do powiedzmy tak:

http.securityNone().antMatchers("/webservices")

Oto configure() Metoda mój teraz:

@Override 
protected void configure(HttpSecurity http) throws Exception 
    http.csrf().disable(); 
    http.headers().frameOptions().disable(); 

    http.authorizeRequests() 
      .antMatchers("/resources/**", 
//"/services/**", THIS LOGS IN AUTOMATICALLY AS 'ANONYMOUS'. NO GOOD! 
//"/remoting/**", THIS LOGS IN AUTOMATICALLY AS 'ANONYMOUS'. NO GOOD! 
         "/pages/login", 
         "/pages/loginFailed").permitAll() 

    // Only authenticated can access these URLs and HTTP METHODs 
    .antMatchers("/secured/**").authenticated() 
    .antMatchers(HttpMethod.HEAD,"/**").authenticated() 
    .antMatchers(HttpMethod.GET,"/**").authenticated() 
    .antMatchers(HttpMethod.POST,"/**").authenticated() 
    .antMatchers(HttpMethod.PUT,"/**").authenticated() 
    .antMatchers(HttpMethod.DELETE,"/**").authenticated(); 

    // Accept FORM-based authentication 
    http.formLogin() 
     .failureUrl("/pages/loginFailed") 
     .defaultSuccessUrl("/") 
     .loginPage("/pages/login") 
     .permitAll() 
     .and() 
     .logout() 
     .logoutRequestMatcher(new AntPathRequestMatcher("/pages/logout")) 
     .logoutSuccessUrl("/pages/login") 
     .permitAll(); 

    http.formLogin().successHandler(new AppLoginSuccessHandler()); 

} 

Odpowiedz

13

Według WebSecurityConfigurerAdapter Javadocs:

/** 
* Override this method to configure {@link WebSecurity}. For 
* example, if you wish to ignore certain requests. 
*/ 
public void configure(WebSecurity web) throws Exception { 
} 

Można to zrobić tak:

@Override 
public void configure(WebSecurity web) throws Exception { 
    web.ignoring() 
     .antMatchers("/webservices/**"); 
} 
Powiązane problemy