Skip to content

Commit f63a3e9

Browse files
author
predicate@bonzo
committed
some improvements
* access AbstractAuthenticationProcessingFilter class directly instead of calling getSuperclass() * catch ClassCastException for matchers that are not instances of AntPathRequestMatcher * ignore authentication filters that produce errors (such as wrong login endpoints) instead of assuming /login path
1 parent c8cace2 commit f63a3e9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: springdoc-openapi-security/src/main/java/org/springdoc/security/SpringDocSecurityConfiguration.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.springframework.security.oauth2.provider.endpoint.FrameworkEndpointHandlerMapping;
5050
import org.springframework.security.web.FilterChainProxy;
5151
import org.springframework.security.web.SecurityFilterChain;
52+
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
5253
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
5354
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
5455
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@@ -133,16 +134,15 @@ OpenApiCustomiser springSecurityLoginEndpointCustomiser(ApplicationContext appli
133134
operation.responses(apiResponses);
134135
operation.addTagsItem("login-endpoint");
135136
PathItem pathItem = new PathItem().post(operation);
136-
String loginPath = "/login";
137137
try {
138-
Field requestMatcherField = usernamePasswordAuthenticationFilter.getClass().getSuperclass().getDeclaredField("requiresAuthenticationRequestMatcher");
138+
Field requestMatcherField = AbstractAuthenticationProcessingFilter.class.getDeclaredField("requiresAuthenticationRequestMatcher");
139139
requestMatcherField.setAccessible(true);
140140
AntPathRequestMatcher requestMatcher = (AntPathRequestMatcher) requestMatcherField.get(usernamePasswordAuthenticationFilter);
141-
loginPath = requestMatcher.getPattern();
141+
String loginPath = requestMatcher.getPattern();
142142
requestMatcherField.setAccessible(false);
143-
} catch (NoSuchFieldException | IllegalAccessException ignored) {
143+
openAPI.getPaths().addPathItem(loginPath, pathItem);
144+
} catch (NoSuchFieldException | IllegalAccessException | ClassCastException ignored) {
144145
}
145-
openAPI.getPaths().addPathItem(loginPath, pathItem);
146146
}
147147
}
148148
};

0 commit comments

Comments
 (0)