|
20 | 20 |
|
21 | 21 | package org.springdoc.security;
|
22 | 22 |
|
| 23 | +import java.lang.reflect.Field; |
23 | 24 | import java.util.Optional;
|
24 | 25 |
|
25 | 26 | import io.swagger.v3.oas.models.Operation;
|
|
50 | 51 | import org.springframework.security.web.SecurityFilterChain;
|
51 | 52 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
52 | 53 | import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
|
| 54 | +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
53 | 55 |
|
54 | 56 | import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
|
55 | 57 | import static org.springdoc.core.Constants.SPRINGDOC_SHOW_LOGIN_ENDPOINT;
|
@@ -131,7 +133,16 @@ OpenApiCustomiser springSecurityLoginEndpointCustomiser(ApplicationContext appli
|
131 | 133 | operation.responses(apiResponses);
|
132 | 134 | operation.addTagsItem("login-endpoint");
|
133 | 135 | PathItem pathItem = new PathItem().post(operation);
|
134 |
| - openAPI.getPaths().addPathItem("/login", pathItem); |
| 136 | + String loginPath = "/login"; |
| 137 | + try { |
| 138 | + Field requestMatcherField = usernamePasswordAuthenticationFilter.getClass().getSuperclass().getDeclaredField("requiresAuthenticationRequestMatcher"); |
| 139 | + requestMatcherField.setAccessible(true); |
| 140 | + AntPathRequestMatcher requestMatcher = (AntPathRequestMatcher) requestMatcherField.get(usernamePasswordAuthenticationFilter); |
| 141 | + loginPath = requestMatcher.getPattern(); |
| 142 | + requestMatcherField.setAccessible(false); |
| 143 | + } catch (NoSuchFieldException | IllegalAccessException ignored) { |
| 144 | + } |
| 145 | + openAPI.getPaths().addPathItem(loginPath, pathItem); |
135 | 146 | }
|
136 | 147 | }
|
137 | 148 | };
|
|
0 commit comments