2016-08-20 3 views
0

スプリングブートアプリケーションでスワッガーを設定するには、次のようにthis articleがあります。ここで私は(私が構築し、JBoss上で展開するIntelliJのを使用しています)、スプリング・ブートアプリケーションを実行するとだから私は、次のUIを参照してくださいここに私のSwaggerConfigクラススプリングブートアプリケーションのスワッガーの設定

package com.path.to.project.config; 

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import springfox.documentation.builders.PathSelectors; 
import springfox.documentation.builders.RequestHandlerSelectors; 
import springfox.documentation.spi.DocumentationType; 
import springfox.documentation.spring.web.plugins.Docket; 
import springfox.documentation.swagger2.annotations.EnableSwagger2; 

@Configuration 
@EnableSwagger2 
public class SwaggerConfig { 
    @Bean 
    public Docket api() { 
     return new Docket(DocumentationType.SWAGGER_2) 
       .select() 
       .apis(RequestHandlerSelectors.any()) 
       .paths(PathSelectors.any()) 
       .build(); 
    } 
} 

は私WebSecurityConfigクラスは

ある
package com.path.to.project.config; 

import com.path.to.project.jwt.JwtAuthenticationEntryPoint; 
import com.path.to.project.jwt.JwtAuthenticationTokenFilter; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 
import org.springframework.security.config.annotation.web.builders.HttpSecurity; 
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 
import org.springframework.security.config.http.SessionCreationPolicy; 
import org.springframework.security.core.userdetails.UserDetailsService; 
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 
import org.springframework.security.crypto.password.PasswordEncoder; 
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 

@Configuration 
@EnableWebSecurity 
@EnableGlobalMethodSecurity(prePostEnabled = true) 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Autowired 
    private JwtAuthenticationEntryPoint unauthorizedHandler; 

    @Autowired 
    private UserDetailsService userDetailsService; 

    @Autowired 
    public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception { 
     authenticationManagerBuilder.userDetailsService(userDetailsService) 
       .passwordEncoder(passwordEncoder()); 
    } 

    @Bean 
    public JwtAuthenticationTokenFilter authenticationTokenFilterBean() throws Exception { 
     return new JwtAuthenticationTokenFilter(); 
    } 

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

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

    } 

    @Bean 
    public PasswordEncoder passwordEncoder() { 
     PasswordEncoder encoder = new BCryptPasswordEncoder(); 
     return encoder; 
    } 

} 

です私はここで

Swagger UI on local spring-boot app

をしないのですか?

+0

JARまたはWARのデプロイメントを使用していますか? JS/CSSファイルは現在どこにありますか? – luboskrnac

答えて

0

CSS/JSが読み込まれていないようです。私はあなたのブラウザログをチェックして、どのURLがリクエストを作成するのかを確認し、httpSecurityを設定して、それらのリソースを既存のセキュリティロールと同様にロードできるようにします。

+0

ヒントのために大丈夫です。これは、私のセキュリティ設定のためかもしれません。 '.css'ファイルと' .js'ファイルのルールを追加することはできますが、CSS/JSが読み込まれていなくても、どうして** apiとそのメソッドを表示しないのですか? '.css/js'とは何の関係もありません。 –

+0

ちょうど推測ですが、デフォルトのSwagger UIでは、サーバーからswagger.jsonファイルにアクセスする必要があります。 '.css'ファイルと' .js'ファイルがロードされていない場合、swaggerファイルがロードされていないと推測しています。 –

0

WebSecurityConfigでは、ルール

.antMatchers( "/ V2/API-ドキュメント"、 "/設定/ UI"、 "/闊歩資源"、 "/設定/セキュリティ"、「/闊歩以下の追加012/APPLICATIONS/APPLIED/APPLIED/APPLIED/APPLICATIONS/APPLICATIONSこのオプションを使用すると、apiとそのメソッドを表示するための春のセキュリティが可能になります。 FirebugまたはChromeのデバッグモードでネットワークトラフィックを監視することで問題を特定できます

関連する問題