2016-08-24 2 views
0

spring-boot에서 작동하는 UI가 아주 좋습니다. 모든 스프링 경로에 대한 역할에 따라 제한되는 내 스프링 휴식 API에 대한 상태 비 저장 인증 설정이 있습니다.Swager UI에 대한 액세스 제한

그러나 기본 인증 뒤에 <server_url>/swagger-ui.html을 어떻게 넣을 수 있는지 잘 모르겠습니다.

내가 websecurity 다음 한

UPDATE는 구성이 SO 질문에서 인에 대한 자세한 내용을 모른 채 WebSecurityConfig

@Override 
protected void configure(HttpSecurity httpSecurity) throws Exception { 
    httpSecurity 
      .csrf().disable() 
      .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() 
      .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() 
      .authorizeRequests() 
      .antMatchers("/sysadmin/**").hasRole("SYSADMIN") 
      .antMatchers("/admin/**").hasRole("ADMIN") 
      .antMatchers("/siteadmin/**").hasRole("SITEADMIN") 
      .antMatchers("/api/**").hasRole("USER") 
      .anyRequest().permitAll(); 

    // Custom JWT based security filter 
    httpSecurity 
      .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class); 

} 
+0

일반적으로는 사람들이 당신의 설정에 대한 작업 솔루션을 제공 할 수 있도록 현재 보안 정의한 방법을 포함하여 가치가 추가 할 수 있도록 경로 아래에 자신감 파일을 넣어하는 것입니다. 그것을하는 많은 방법이 있습니다 그러나 당신의 imlementation에 관하여 더 많은 것이 도움이 될 것입니다 알고있는. –

+0

업데이트 됨 내 질문 –

답변

0

한 가지 제안을 통해 구성.

@Override 
protected void configure(HttpSecurity httpSecurity) throws Exception { 
    httpSecurity 
      .csrf().disable() 
      .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() 
      .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() 
      .authorizeRequests() 
      .antMatchers("/sysadmin/**").hasRole("SYSADMIN") 
      .antMatchers("/admin/**").hasRole("ADMIN") 
      .antMatchers("/siteadmin/**").hasRole("SITEADMIN") 
      .antMatchers("/api/**").hasRole("USER") 
      // add the specific swagger page to the security 
      .antMatchers("/swagger-ui.html").hasRole("USER") 
      .anyRequest().permitAll(); 

    // Custom JWT based security filter 
    httpSecurity 
      .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class); 

} 
이의 문제는 그것은 단지 자신감 UI 페이지와하지 않은 API 사양을 보호한다

: 여기에 업데이트 된 질문 세부

https://stackoverflow.com/a/24920752/1499549

은 추가 할 수 있는지의 예입니다 해당 UI 페이지에서 .json 파일로로드됩니다.

더 좋은 방법은 그냥 antMatchers("/swagger/**").hasRole("USER")