0

경로 /gateways은 인증이 필요합니다.
/gateways은 내가 /login로 리디렉션하고 브라우저에서 액세스 다음과 같은 화면이 나타납니다 때 : angular2 응용 프로그램에서 액세스 할 수Spring 서버 설정에서 '인증 필요'팝업을 비활성화하는 방법은 무엇입니까?

enter image description here

/gateways 경우 다음과 같은 팝업이 나타납니다

enter image description here

스프링 보안 구성은 다음과 같습니다.

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 


    private static String REALM="Authentication"; 

    @Autowired 
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception { 

     auth.inMemoryAuthentication().withUser("cris").password("123").roles("ADMIN"); 
     auth.inMemoryAuthentication().withUser("felix").password("felix123").roles("USER"); 
    } 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 

     http 

       .httpBasic() 

       .and() 
       .csrf() 
       .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) 

       .and() 
       .formLogin() 

       .and() 
       .authorizeRequests() 
       .antMatchers("/user", "/vehicles", "/signin", "/isautheticated").permitAll().anyRequest() 
       .authenticated(); 
    } 

// Access-Control-Allow-Origin header to be present 
    @Bean 
    public WebMvcConfigurer corsConfigurer() { 
     return new WebMvcConfigurerAdapter() { 
      @Override 
      public void addCorsMappings(CorsRegistry registry) { 
       registry.addMapping("/**"); 
      } 
     }; 
    } 

    /* To allow Pre-flight [OPTIONS] request from browser */ 
    @Override 
    public void configure(WebSecurity web) throws Exception { 
     web.ignoring().antMatchers(HttpMethod.OPTIONS, "/**"); 
    } 

어떻게 팝업을 비활성화 할 수 있습니까?

답변

1

구성에 httpBasic() 대신 formLogin()을 지정해야합니다. configure 메쏘드는 다음과 같이 보일 것입니다.

@Override 
protected void configure(HttpSecurity http) throws Exception { 

    http 

      .formLogin() 
       .loginPage("/login"); 

      .and() 
      .csrf() 
      .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) 

      .and() 
      .formLogin() 

      .and() 
      .authorizeRequests() 
      .antMatchers("/user", "/vehicles", "/signin", "/isautheticated").permitAll().anyRequest() 
      .authenticated(); 
} 
+0

'HttpBasic'을 입력하지 않으면 로그인이 작동하지 않습니다. – Cristian

0

내가 angular2에서 요청이 잘못된 Authorization 기본 헤더를 가지고 있다고 생각, 그것은 BasicAuthenticationFilter에 의해 처리, 그리고 그것은 AuthenticationException을 던졌다 및 진입 점에 시작되었다. AuthenticationEntryPoint을 구현하는 고유 진입 점을 구현 한 다음 BasicFilter에 삽입하면 기본 진입 점은 BasicAuthenticationEntryPoint이됩니다. 보시다시피 응답 헤더는 WWW-Authenticate입니다.

public void commence(HttpServletRequest request, HttpServletResponse response, 
      AuthenticationException authException) throws IOException, ServletException { 
     response.addHeader("WWW-Authenticate", "Basic realm=\"" + realmName + "\""); 
     response.sendError(HttpServletResponse.SC_UNAUTHORIZED, 
       authException.getMessage()); 
    }