|
35 | 35 | import org.springdoc.core.customizers.OpenApiCustomiser;
|
36 | 36 |
|
37 | 37 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
| 38 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
38 | 39 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
39 | 40 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
40 | 41 | import org.springframework.context.annotation.Bean;
|
@@ -86,34 +87,39 @@ SpringSecurityOAuth2Provider springSecurityOAuth2Provider(FrameworkEndpointHandl
|
86 | 87 | }
|
87 | 88 | }
|
88 | 89 |
|
89 |
| - @Bean |
90 |
| - @ConditionalOnProperty(SPRINGDOC_SHOW_LOGIN_ENDPOINT) |
91 |
| - @Lazy(false) |
92 |
| - OpenApiCustomiser springSecurityLoginEndpointCustomiser(FilterChainProxy filterChainProxy) { |
93 |
| - return openAPI -> { |
94 |
| - for (SecurityFilterChain filterChain : filterChainProxy.getFilterChains()) { |
95 |
| - Optional<UsernamePasswordAuthenticationFilter> optionalFilter = |
96 |
| - filterChain.getFilters().stream() |
97 |
| - .filter(filterVar -> filterVar instanceof UsernamePasswordAuthenticationFilter) |
98 |
| - .map(filter -> (UsernamePasswordAuthenticationFilter) filter) |
99 |
| - .findAny(); |
100 |
| - if (optionalFilter.isPresent()) { |
101 |
| - UsernamePasswordAuthenticationFilter usernamePasswordAuthenticationFilter = optionalFilter.get(); |
102 |
| - Operation operation = new Operation(); |
103 |
| - Schema<?> schema = new ObjectSchema() |
104 |
| - .addProperties(usernamePasswordAuthenticationFilter.getUsernameParameter(), new StringSchema()) |
105 |
| - .addProperties(usernamePasswordAuthenticationFilter.getPasswordParameter(), new StringSchema()); |
106 |
| - RequestBody requestBody = new RequestBody().content(new Content().addMediaType("loginRequestBody", new MediaType().schema(schema))); |
107 |
| - operation.requestBody(requestBody); |
108 |
| - ApiResponses apiResponses = new ApiResponses(); |
109 |
| - apiResponses.addApiResponse(String.valueOf(HttpStatus.OK.value()), new ApiResponse().description(HttpStatus.OK.getReasonPhrase())); |
110 |
| - apiResponses.addApiResponse(String.valueOf(HttpStatus.FORBIDDEN.value()), new ApiResponse().description(HttpStatus.FORBIDDEN.getReasonPhrase())); |
111 |
| - operation.responses(apiResponses); |
112 |
| - operation.addTagsItem("login-endpoint"); |
113 |
| - PathItem pathItem = new PathItem().post(operation); |
114 |
| - openAPI.getPaths().addPathItem("/login", pathItem); |
| 90 | + @Configuration(proxyBeanMethods = false) |
| 91 | + @ConditionalOnClass(javax.servlet.Filter.class) |
| 92 | + class SpringSecurityLoginEndpointConfiguration { |
| 93 | + |
| 94 | + @Bean |
| 95 | + @ConditionalOnProperty(SPRINGDOC_SHOW_LOGIN_ENDPOINT) |
| 96 | + @Lazy(false) |
| 97 | + OpenApiCustomiser springSecurityLoginEndpointCustomiser(FilterChainProxy filterChainProxy) { |
| 98 | + return openAPI -> { |
| 99 | + for (SecurityFilterChain filterChain : filterChainProxy.getFilterChains()) { |
| 100 | + Optional<UsernamePasswordAuthenticationFilter> optionalFilter = |
| 101 | + filterChain.getFilters().stream() |
| 102 | + .filter(filterVar -> filterVar instanceof UsernamePasswordAuthenticationFilter) |
| 103 | + .map(filter -> (UsernamePasswordAuthenticationFilter) filter) |
| 104 | + .findAny(); |
| 105 | + if (optionalFilter.isPresent()) { |
| 106 | + UsernamePasswordAuthenticationFilter usernamePasswordAuthenticationFilter = optionalFilter.get(); |
| 107 | + Operation operation = new Operation(); |
| 108 | + Schema<?> schema = new ObjectSchema() |
| 109 | + .addProperties(usernamePasswordAuthenticationFilter.getUsernameParameter(), new StringSchema()) |
| 110 | + .addProperties(usernamePasswordAuthenticationFilter.getPasswordParameter(), new StringSchema()); |
| 111 | + RequestBody requestBody = new RequestBody().content(new Content().addMediaType("loginRequestBody", new MediaType().schema(schema))); |
| 112 | + operation.requestBody(requestBody); |
| 113 | + ApiResponses apiResponses = new ApiResponses(); |
| 114 | + apiResponses.addApiResponse(String.valueOf(HttpStatus.OK.value()), new ApiResponse().description(HttpStatus.OK.getReasonPhrase())); |
| 115 | + apiResponses.addApiResponse(String.valueOf(HttpStatus.FORBIDDEN.value()), new ApiResponse().description(HttpStatus.FORBIDDEN.getReasonPhrase())); |
| 116 | + operation.responses(apiResponses); |
| 117 | + operation.addTagsItem("login-endpoint"); |
| 118 | + PathItem pathItem = new PathItem().post(operation); |
| 119 | + openAPI.getPaths().addPathItem("/login", pathItem); |
| 120 | + } |
115 | 121 | }
|
116 |
| - } |
117 |
| - }; |
| 122 | + }; |
| 123 | + } |
118 | 124 | }
|
119 | 125 | }
|
0 commit comments