Last active
November 19, 2023 11:28
-
-
Save sandipchitale/b8d75fa41bf8e8701970411825983d7c to your computer and use it in GitHub Desktop.
Set portmapper for oauth2Login() #oauth2Login #portMapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ObjectPostProcessor<AuthenticationEntryPoint> authenticationEntryPointFilterPostProcessor = new ObjectPostProcessor<>() { | |
@Override | |
public <O extends AuthenticationEntryPoint> O postProcess(O authenticationEntryPoint) { | |
if (authenticationEntryPoint instanceof DelegatingAuthenticationEntryPoint delegatingAuthenticationEntryPoint) { | |
Field entryPointsField = ReflectionUtils.findField(DelegatingAuthenticationEntryPoint.class, "entryPoints"); | |
assert entryPointsField != null; | |
entryPointsField.setAccessible(true); | |
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = | |
(LinkedHashMap<RequestMatcher, AuthenticationEntryPoint>) ReflectionUtils.getField(entryPointsField, | |
delegatingAuthenticationEntryPoint); | |
entryPoints.values().forEach(authenticationEntryPointValue -> { | |
if (authenticationEntryPointValue instanceof LoginUrlAuthenticationEntryPoint loginUrlAuthenticationEntryPoint) { | |
PortMapperImpl portMapper = new PortMapperImpl(); | |
portMapper.setPortMappings(Map.of("80", "80", "8080", "8080")); | |
loginUrlAuthenticationEntryPoint.setPortMapper(portMapper); | |
} | |
}); | |
} | |
return authenticationEntryPoint; | |
} | |
}; | |
httpSecurity | |
.oauth2Login((OAuth2LoginConfigurer<HttpSecurity> httpSecurityOAuth2LoginConfigurer) -> { | |
httpSecurityOAuth2LoginConfigurer.withObjectPostProcessor(authenticationEntryPointFilterPostProcessor); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment