Class ChenileSecurityConfiguration
java.lang.Object
org.chenile.configuration.security.ChenileSecurityConfiguration
@Configuration
@ConditionalOnProperty(name="security.config.type",
havingValue="false",
matchIfMissing=true)
public class ChenileSecurityConfiguration
extends Object
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) String(package private) String(package private) KeycloakConnectionDetailsprivate Stringprivate final org.slf4j.Loggerprivate Stringprivate 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.AuthenticationManagergetAuthenticationManager(String tenantId) 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.private org.springframework.security.authentication.AuthenticationManagerprivate 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) (package private) SecurityService
-
Field Details
-
logger
private final org.slf4j.Logger logger -
connectionDetails
-
clientId
-
clientSecret
-
keycloakAuthServerUrl
-
realm
-
repositories
-
authenticationManagers
-
jwtDecoderMap
-
-
Constructor Details
-
ChenileSecurityConfiguration
public ChenileSecurityConfiguration()
-
-
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() -
getAuthenticationManager
private org.springframework.security.authentication.AuthenticationManager getAuthenticationManager(String tenantId) 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
-
jwt
-
jwtBearerTokenAuthenticationConverter
private Converter<org.springframework.security.oauth2.jwt.Jwt,? extends org.springframework.security.authentication.AbstractAuthenticationToken> jwtBearerTokenAuthenticationConverter() -
keycloakBaseUrl
-
keycloakOpenIdUrl
-
jwtDecoder
-
securityService
-