Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spring Security and Swagger development
Added the Spring security Configuration and also swagger-ui
- Loading branch information
1 parent
5829e60
commit 9bc2a0c
Showing
6 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/hithesh/springbootdemo/config/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.hithesh.springbootdemo.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
|
||
import org.springframework.security.config.http.SessionCreationPolicy; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
@Configuration | ||
@EnableWebSecurity | ||
public class SecurityConfig { | ||
|
||
@Bean | ||
public SecurityFilterChain configure(HttpSecurity http) throws Exception { | ||
return http | ||
.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) | ||
.and().authorizeRequests().antMatchers("/demo/getDemoResponse").permitAll() | ||
.anyRequest().authenticated().and() | ||
.httpBasic().and().build(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/hithesh/springbootdemo/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.hithesh.springbootdemo.config; | ||
|
||
import org.springframework.cglib.core.Predicate; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import springfox.documentation.builders.ApiInfoBuilder; | ||
import springfox.documentation.builders.PathSelectors; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
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.basePackage("com.hithesh.springbootdemo.controller")) | ||
.paths(PathSelectors.any()) | ||
.build().apiInfo(apiEndPointsInfo()); | ||
} | ||
|
||
private ApiInfo apiEndPointsInfo() { | ||
return new ApiInfoBuilder().title("DEMO Project") | ||
.description("This is a demo project for Swagger implementation") | ||
.license("Demo license").version("1.0.0").build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
spring.security.user.name=admin | ||
spring.security.user.password=admin@123 | ||
|
||
spring.datasource.url=jdbc:h2:mem:demodb | ||
spring.datasource.driverClassName=org.h2.Driver | ||
|
||
spring.mvc.pathmatch.matching-strategy = ANT_PATH_MATCHER | ||
|