From 0da6a2356f3953a21974ccfb31fc28c5cba10ffa Mon Sep 17 00:00:00 2001 From: Nadim Ritter Date: Thu, 18 Jul 2024 13:52:27 +0200 Subject: [PATCH] redesign add security scheme for swagger --- .../weblayer/WebServiceSecurityConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/WebServiceSecurityConfig.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/WebServiceSecurityConfig.java index cb406d2a..e7ab67ba 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/WebServiceSecurityConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/WebServiceSecurityConfig.java @@ -13,6 +13,11 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.security.OAuthFlow; +import io.swagger.v3.oas.models.security.OAuthFlows; +import io.swagger.v3.oas.models.security.SecurityScheme; import org.apache.catalina.filters.RemoteIpFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -117,6 +122,21 @@ public class WebServiceSecurityConfig extends WebSecurityConfigurerAdapter { return new RemoteIpFilter(); } + @Bean + public OpenAPI cutomOpenApi(){ + + return new OpenAPI() + .components(new Components() + .addSecuritySchemes("oauth2", new SecurityScheme() + .type(SecurityScheme.Type.OAUTH2) + .scheme("bearer") + .in(SecurityScheme.In.HEADER) + .bearerFormat("jwt") + .flows(new OAuthFlows().password(new OAuthFlow().tokenUrl("/oauth/token"))) + ) + ); + } + @Bean public AccessTokenConverter accessTokenConverter() { final DefaultAccessTokenConverter accessTokenConverter = new DefaultAccessTokenConverter();