Propagating changes to main ! #102

Merged
hitanshu merged 5 commits from test into main 2026-01-23 13:45:46 +00:00
3 changed files with 29 additions and 18 deletions
Showing only changes of commit d2d8e74ba9 - Show all commits

View File

@ -1,6 +1,8 @@
package com.hithomelabs.CFTunnels.Config; package com.hithomelabs.CFTunnels.Config;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.*;
import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.servers.Server;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -16,6 +18,12 @@ public class OpenApiConfig {
@Value("${api.baseUrl}") @Value("${api.baseUrl}")
private String baseUrl; private String baseUrl;
@Value("${springdoc.swagger-ui.oauth.authorization-url}")
private String authorizationUri;
@Value("${springdoc.swagger-ui.oauth.token-url}")
private String tokenUri;
@Bean @Bean
public OpenAPI openAPI() { public OpenAPI openAPI() {
Server httpsServer = new Server().url(baseUrl); Server httpsServer = new Server().url(baseUrl);
@ -23,6 +31,24 @@ public class OpenApiConfig {
ArrayList<Server> servers = new ArrayList<>(); ArrayList<Server> servers = new ArrayList<>();
servers.add(httpsServer); servers.add(httpsServer);
openApi.setServers(servers); openApi.setServers(servers);
openApi.addSecurityItem(new SecurityRequirement().addList("oidcAuth"))
.components(new Components()
.addSecuritySchemes("oidcAuth",
new SecurityScheme()
.type(SecurityScheme.Type.OAUTH2)
.flows(new OAuthFlows()
.authorizationCode(new OAuthFlow()
.authorizationUrl(authorizationUri)
.tokenUrl(tokenUri)
.scopes(new Scopes()
.addString("openid", "OpenID scope")
.addString("profile", "OpenID profile")
.addString("email", "OpenID email"))
)
)
)
)
.addSecurityItem(new SecurityRequirement().addList("oidcAuth"));
return openApi; return openApi;
} }
} }

View File

@ -28,6 +28,7 @@ public class SecuirtyConfig {
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http http
.authorizeHttpRequests(auth -> auth .authorizeHttpRequests(auth -> auth
//.requestMatchers( "/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html" ).permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
).csrf(csrf -> csrf.disable()) ).csrf(csrf -> csrf.disable())
.with(new OAuth2LoginConfigurer<>(), .with(new OAuth2LoginConfigurer<>(),

View File

@ -11,22 +11,6 @@ public class HomeController implements ErrorController {
private static final String ERROR_PATH = "/error"; private static final String ERROR_PATH = "/error";
/**
* Redirects the root (including any query params like ?continue=)
* straight into Swagger UI.
*/
@GetMapping("/")
public String rootRedirect() {
return "redirect:/swagger-ui/index.html";
}
/**
* Catches any errors (404s, unhandled paths) and punts them
* into the same Swagger UI page.
*/
@RequestMapping(ERROR_PATH)
public String onError() {
return "redirect:/swagger-ui/index.html";
}
} }