Skip to content

Commit

Permalink
(feat) enable swagger swagger-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlermitage committed Oct 14, 2018
1 parent 0d0092a commit 834852c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<rest-assured.version>3.1.1</rest-assured.version>
<slf4j-api.version>1.7.25</slf4j-api.version>
<spring-boot.version>2.0.5.RELEASE</spring-boot.version>
<springfox-swagger.version>2.9.2</springfox-swagger.version>
<testng.version>6.14.3</testng.version>

<jacoco-maven-plugin.version>0.8.2</jacoco-maven-plugin.version>
Expand All @@ -37,6 +38,7 @@
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
<versions-maven-plugin.version>2.7</versions-maven-plugin.version>

</properties>

<dependencies>
Expand Down Expand Up @@ -105,6 +107,20 @@
<version>${janino.version}</version>
</dependency>

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- API doc via Swagger. -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-swagger.version}</version>
</dependency>

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Unit Testing. -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/manon/app/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package manon.app.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 productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("manon"))
.paths(PathSelectors.any())
.build();
}
}
34 changes: 34 additions & 0 deletions src/main/java/manon/app/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package manon.app.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@EnableAsync
public class WebConfig implements WebMvcConfigurer {

public WebConfig() {
super();
}

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}

@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/view/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
8 changes: 8 additions & 0 deletions src/main/java/manon/app/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private static final String ADMIN = UserAuthority.ROLE_ADMIN.name();
private static final String PLAYER = UserAuthority.ROLE_PLAYER.name();
private static final String ACTUATOR = UserAuthority.ROLE_ACTUATOR.name();
private static final String DEV = UserAuthority.ROLE_DEV.name();

private final PasswordEncoderService passwordEncoderService;
private final UserLoaderService userLoaderService;
Expand All @@ -55,6 +56,13 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/actuator").hasAuthority(ACTUATOR)
.antMatchers("/actuator/**").hasAuthority(ACTUATOR)

.antMatchers("/swagger-resources",
"/swagger-resources/configuration/ui",
"/swagger-resources/configuration/security",
"/swagger-ui.html",
"/webjars/**",
"/v2/api-docs").hasAuthority(DEV)

.and().httpBasic()
.and().csrf().disable();
}
Expand Down

0 comments on commit 834852c

Please sign in to comment.