Skip to content

Commit d88d66a

Browse files
author
predicate@bonzo
committed
add support for custom paths
1 parent 5787a07 commit d88d66a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

springdoc-openapi-security/src/main/java/org/springdoc/security/SpringDocSecurityConfiguration.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package org.springdoc.security;
2222

23+
import java.lang.reflect.Field;
2324
import java.util.Optional;
2425

2526
import io.swagger.v3.oas.models.Operation;
@@ -50,6 +51,7 @@
5051
import org.springframework.security.web.SecurityFilterChain;
5152
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
5253
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
54+
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
5355

5456
import static org.springdoc.core.Constants.SPRINGDOC_ENABLED;
5557
import static org.springdoc.core.Constants.SPRINGDOC_SHOW_LOGIN_ENDPOINT;
@@ -131,7 +133,16 @@ OpenApiCustomiser springSecurityLoginEndpointCustomiser(ApplicationContext appli
131133
operation.responses(apiResponses);
132134
operation.addTagsItem("login-endpoint");
133135
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);
135146
}
136147
}
137148
};

0 commit comments

Comments
 (0)