2016-08-24 20 views
0

私はspring-bootでうまくいくUIを持っています。私はすべてのAPIパスの役割に基づいて制限されている私の春の残りのAPIのためのステートレスな認証設定を持っています。Swager UIへのアクセスを制限する

はしかし、私は私が基本認証の後ろに<server_url>/swagger-ui.htmlを置くことができるかどうかはわかりませんよ。私はあなたの設定についての詳細を知らなくても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

を追加できるように、パスの下に闊歩ファイルを置くことです。それを行うにはいくつかの方法がありますが、あなたの実現についてもっと知ることは助けになります。 –

+0

更新された私の質問 –

答えて

0

1つの提案を介して設定WebSecurity社を以下している

UPDATE

は、このSOの質問からです。

@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")

関連する問題