7
7
import io .swagger .v3 .oas .models .info .License ;
8
8
import io .swagger .v3 .oas .models .security .SecurityRequirement ;
9
9
import io .swagger .v3 .oas .models .security .SecurityScheme ;
10
+ import no .nav .testnav .libs .reactivecore .config .ApplicationProperties ;
10
11
import org .springframework .context .annotation .Bean ;
11
12
import org .springframework .context .annotation .Configuration ;
12
- import org .springframework .web .servlet .config .annotation .ViewControllerRegistry ;
13
- import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
13
+ import org .springframework .web .server .ServerWebExchange ;
14
+ import org .springframework .web .server .WebFilter ;
15
+ import org .springframework .web .server .WebFilterChain ;
16
+ import reactor .core .publisher .Mono ;
14
17
15
18
import java .util .Arrays ;
16
19
17
- import no .nav .testnav .libs .securitycore .config .UserConstant ;
18
- import no .nav .testnav .libs .servletcore .config .ApplicationProperties ;
19
-
20
20
@ Configuration
21
- public class OpenApiConfig implements WebMvcConfigurer {
21
+ public class OpenApiConfig implements WebFilter {
22
22
23
23
@ Bean
24
24
public OpenAPI openApi (ApplicationProperties applicationProperties ) {
25
25
return new OpenAPI ()
26
- .components (new Components ()
27
- .addSecuritySchemes ("bearer-jwt" , new SecurityScheme ()
28
- .type (SecurityScheme .Type .HTTP )
29
- .scheme ("bearer" )
30
- .bearerFormat ("JWT" )
31
- .in (SecurityScheme .In .HEADER )
32
- .name ("Authorization" )
33
- .description ("Trenger ikke \" Bearer \" foran" )
34
- )
35
- .addSecuritySchemes ("user-jwt" , new SecurityScheme ()
36
- .type (SecurityScheme .Type .APIKEY )
37
- .scheme ("bearer" )
38
- .bearerFormat ("JWT" )
39
- .in (SecurityScheme .In .HEADER )
40
- .name (UserConstant .USER_HEADER_JWT )
41
- ))
26
+ .components (new Components ().addSecuritySchemes ("bearer-jwt" , new SecurityScheme ()
27
+ .type (SecurityScheme .Type .HTTP )
28
+ .scheme ("bearer" )
29
+ .bearerFormat ("JWT" )
30
+ .in (SecurityScheme .In .HEADER )
31
+ .name ("Authorization" )
32
+ ))
42
33
.addSecurityItem (
43
- new SecurityRequirement ()
44
- .addList ("bearer-jwt" , Arrays .asList ("read" , "write" ))
45
- .addList ("user-jwt" , Arrays .asList ("read" , "write" ))
46
- )
34
+ new SecurityRequirement ().addList ("bearer-jwt" , Arrays .asList ("read" , "write" )))
47
35
.info (new Info ()
48
36
.title (applicationProperties .getName ())
49
37
.version (applicationProperties .getVersion ())
@@ -62,7 +50,15 @@ public OpenAPI openApi(ApplicationProperties applicationProperties) {
62
50
}
63
51
64
52
@ Override
65
- public void addViewControllers (ViewControllerRegistry registry ) {
66
- registry .addViewController ("/swagger" ).setViewName ("redirect:/swagger-ui.html" );
53
+ public Mono <Void > filter (ServerWebExchange exchange , WebFilterChain chain ) {
54
+ if (exchange .getRequest ().getURI ().getPath ().equals ("/swagger" )) {
55
+ return chain
56
+ .filter (exchange .mutate ()
57
+ .request (exchange .getRequest ()
58
+ .mutate ().path ("/swagger-ui.html" ).build ())
59
+ .build ());
60
+ }
61
+
62
+ return chain .filter (exchange );
67
63
}
68
64
}
0 commit comments