Class SecurityConfiguration
java.lang.Object
org.chenile.configuration.security.SecurityConfiguration
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) String(package private) String(package private) KeycloakConnectionDetailsprivate org.slf4j.Loggerprivate final Map<String, org.springframework.security.oauth2.client.registration.ClientRegistrationRepository> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.springframework.security.authentication.AuthenticationManagerResolver<HttpServletRequest> org.springframework.security.oauth2.client.OAuth2AuthorizedClientServiceauthorizedClientService(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository) org.springframework.security.oauth2.client.registration.ClientRegistrationclient()org.springframework.security.oauth2.client.registration.ClientRegistrationorg.springframework.security.oauth2.client.registration.ClientRegistrationRepositoryprivate org.springframework.security.oauth2.client.registration.ClientRegistrationRepositoryclientRegistrationRepository(String tenantId) private org.springframework.security.authentication.AuthenticationManagerHere we take the tenant ID to construct a specific URL (with the realm as tenant ID) and return an Authentication Manager for that realm.private Converter<org.springframework.security.oauth2.jwt.Jwt, ? extends org.springframework.security.authentication.AbstractAuthenticationToken> (package private) org.springframework.security.oauth2.jwt.JwtDecoderjwtDecoder(String tenantId) private StringkeycloakBaseUrl(String realm) private StringkeycloakOpenIdUrl(String realm) private org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestResolverresolver()org.springframework.security.web.SecurityFilterChainsecurityFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http)
-
Field Details
-
logger
private org.slf4j.Logger logger -
connectionDetails
-
clientId
-
clientSecret
-
repositories
-
jwtDecoderMap
-
-
Constructor Details
-
SecurityConfiguration
public SecurityConfiguration()
-
-
Method Details
-
securityFilterChain
@Bean public org.springframework.security.web.SecurityFilterChain securityFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http) throws Exception - Throws:
Exception
-
resolver
private org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestResolver resolver() -
clientRegistrationRepository
@Bean public org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository() -
clientRegistrationRepository
private org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository(String tenantId) -
authorizedClientService
@Bean public org.springframework.security.oauth2.client.OAuth2AuthorizedClientService authorizedClientService(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRegistrationRepository) -
client
public org.springframework.security.oauth2.client.registration.ClientRegistration client() -
client
-
authenticationManagerResolver
private org.springframework.security.authentication.AuthenticationManagerResolver<HttpServletRequest> authenticationManagerResolver() -
jwt
Here we take the tenant ID to construct a specific URL (with the realm as tenant ID) and return an Authentication Manager for that realm.
Since the URL that is constructed depends on the validity of the tenant ID, it is possible that we may get a 404 from keycloak. To take care of this, we will recast all exceptions to "InvalidBearerTokenException" so that spring security will give a 401 in all those cases.- Parameters:
tenantId- the tenant ID- Returns:
- the Authentication manager for the particular tenant ID
-
jwtBearerTokenAuthenticationConverter
private Converter<org.springframework.security.oauth2.jwt.Jwt,? extends org.springframework.security.authentication.AbstractAuthenticationToken> jwtBearerTokenAuthenticationConverter() -
keycloakBaseUrl
-
keycloakOpenIdUrl
-
jwtDecoder
-
securityInterceptor
-