Skip to content

Commit

Permalink
feature/swagger-added
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-zip committed Aug 30, 2024
1 parent aba6f8b commit 2773908
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
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.configurers.AbstractHttpConfigurer;
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.SecurityFilterChain;
Expand Down Expand Up @@ -67,6 +69,7 @@ public class SecurityConfiguration {
private final JwtTokenValidationFilter jwtTokenValidationFilter;

@Bean
@Order(1)
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
List<String> paths = authenticationProperties.getPathExclude().getPaths();
String[] pathArray = new String[paths.size()];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.bloggios.auth.provider.configuration;

import com.bloggios.auth.provider.properties.SwaggerConfigProperties;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Owner - Rohit Parihar
* Author - rohit
* Project - blog-provider-application
* Package - com.bloggios.blog.configuration
* Created_on - August 30 - 2024
* Created_at - 01:19
*/

@Configuration
@RequiredArgsConstructor
public class SwaggerConfiguration {

private final SwaggerConfigProperties swaggerConfigProperties;

@Bean
public GroupedOpenApi api() {
return GroupedOpenApi.builder()
.group(swaggerConfigProperties.getGroupName().getDefinition())
.packagesToScan(swaggerConfigProperties.getGroupName().getScanPackages())
.build();
}

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info()
.title(swaggerConfigProperties.getInfo().getTitle())
.version(swaggerConfigProperties.getInfo().getVersion())
.description(swaggerConfigProperties.getInfo().getDescription())
.license(new License().name(swaggerConfigProperties.getInfo().getLicense().getName()).url(swaggerConfigProperties.getInfo().getLicense().getUrl()))
.contact(new Contact().name(swaggerConfigProperties.getInfo().getContact().getName()).email(swaggerConfigProperties.getInfo().getContact().getEmail()).url(swaggerConfigProperties.getInfo().getContact().getUrl())))
.servers(getServers())
.components(new Components()
.addSecuritySchemes(
"bearerAuth",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer").bearerFormat("JWT")
.name("bearerAuth")
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
.in(SecurityScheme.In.HEADER)
.description("JWT Authentication")));
}

public List<Server> getServers(){
Map<String, SwaggerConfigProperties.Server> servers = swaggerConfigProperties.getServers();
List<Server> serversList = new ArrayList<>();
for (String server : servers.keySet()){
SwaggerConfigProperties.Server getServer = servers.get(server);
serversList.add(new Server().description(getServer.getName()).url(getServer.getUrl()));
}
return serversList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.bloggios.auth.provider.properties;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
* Owner - Rohit Parihar
* Author - rohit
* Project - blog-provider-application
* Package - com.bloggios.blog.properties
* Created_on - August 30 - 2024
* Created_at - 01:35
*/

@Getter
@Setter
@ConfigurationProperties(prefix = "swagger-properties")
@Configuration
public class SwaggerConfigProperties {

private Info info;
private Map<String, Server> servers;
private Group groupName;


@Getter
@Setter
public static class Info{
private String title;
private String description;
private String summary;
private String version;
private Contact contact;
private License license;
}

@Getter
@Setter
public static class Contact{
private String name;
private String email;
private String url;
}

@Getter
@Setter
public static class License{
private String name;
private String url;
}

@Getter
@Setter
public static class Server{
private String name;
private String url;
}

@Getter
@Setter
public static class Group{
private String definition;
private String scanPackages;
}
}
37 changes: 36 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,39 @@ authentication:
- /auth-provider/auth/**
- /auth-provider/oauth/**
- /actuator/**
- /oauth2/**
- /oauth2/**
- /api/v1/auth/**"
- /v2/api-docs
- /swagger-resources
- /swagger-resources/**
- /configuration/ui
- /configuration/security
- /swagger-ui/**
- /webjars/**
- /swagger-ui.html
- /v3/api-docs
- /v3/api-docs/**

swagger-properties:
group-name:
definition: ${spring.application.name}
scan-packages: com.bloggios.auth.provider
info:
title: Bloggios - Auth Provider Application
version: @version@
description: API Documentation for auth-provider-application
summary: The Auth Provider Application microservice, developed with Java 17 and Spring Boot, is designed to offer robust authentication and authorization services for Bloggios. This microservice ensures secure access and user management, enhancing the overall security framework of the platform.
contact:
name: Bloggios
email: support@bloggios.com
url: https://www.bloggios.com
license:
name: Apache 2 License
url: https://github.com/Bloggios/auth-provider-application/blob/main/LICENSE
servers:
local:
name: Local Port
url: http://localhost:${server.port}
production:
name: Hosted Port
url: https://api.bloggios.com

0 comments on commit 2773908

Please sign in to comment.