복붙노트

[SPRING] JavaConfig에서 http "security = 'none'을 어떻게 정의합니까?

SPRING

JavaConfig에서 http "security = 'none'을 어떻게 정의합니까?

Java Config를 사용하여 Spring Boot에서이 XML과 비슷한 것을 정의하고 싶다.

다른 방법으로 보안을 설정해야하며 양식 로그인을 할 수 없습니다. 그 (것)들을 확보하는 것은 나중에 올 것이다. 지금은 http.formLogin ()을 사용하여 보안 설정을 중단하고 싶습니다.

WebSecurityConfigurerAdapter.configure ()를 재정의했습니다. 다음과 같이 API를 찾을 수 없습니다.

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

다음은 지금 configure () 메소드입니다.

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

}

해결법

  1. ==============================

    1.WebSecurityConfigurerAdapter JavaDocs에 따르면 :

    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 {
    }
    

    당신은 이렇게 할 수 있습니다 :

    @Override
    public void configure(WebSecurity web) throws Exception {
         web.ignoring()
            .antMatchers("/webservices/**");
    }
    
  2. from https://stackoverflow.com/questions/28455507/how-do-i-define-http-security-none-in-javaconfig by cc-by-sa and MIT license