Class SecurityConfig
java.lang.Object
com.erudika.para.server.security.SecurityConfig
@Configuration
@EnableWebSecurity
@DeclareRoles({"ROLE_USER","ROLE_MOD","ROLE_ADMIN","ROLE_APP"})
public class SecurityConfig
extends Object
Programmatic configuration for Spring Security.
- Author:
- Alex Bogdanovski [[email protected]]
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.authentication.AuthenticationManagerConfigures theAuthenticationManagerwith various providers.org.springframework.security.web.SecurityFilterChainfilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.security.authentication.AuthenticationManager authManager, FacebookAuthFilter facebookAuth, GoogleAuthFilter googleAuth, GitHubAuthFilter githubAuth, LinkedInAuthFilter linkedinAuth, TwitterAuthFilter twitterAuth, MicrosoftAuthFilter microsoftAuth, SlackAuthFilter slackAuth, AmazonAuthFilter amazonAuth, GenericOAuth2Filter oauth2Auth, LdapAuthFilter ldapAuth, PasswordAuthFilter passwordAuth, PasswordlessAuthFilter passwordlessAuth) Configures the protected private resources.getAmazonFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Amazon authentication filter.getFacebookFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Facebook authentication filter.Returns the authentication failure handler.getGenericOAuth2Filter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the generic OAuth2 authentication filter.getGithubFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the GitHub authentication filter.getGoogleFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Google authentication filter.getJWTAuthFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager, FacebookAuthFilter facebookAuth, GoogleAuthFilter googleAuth, GitHubAuthFilter githubAuth, LinkedInAuthFilter linkedinAuth, TwitterAuthFilter twitterAuth, MicrosoftAuthFilter microsoftAuth, SlackAuthFilter slackAuth, AmazonAuthFilter amazonAuth, GenericOAuth2Filter oauth2Auth, LdapAuthFilter ldapAuth, PasswordAuthFilter passwordAuth, PasswordlessAuthFilter passwordlessAuth) Returns the JWT restful authentication filter.getLdapAuthFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the LDAP authentication filter.getLinkedinFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the LinkedIn authentication filter.getMicrosoftFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Microsoft authentication filter.getPasswordFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the password authentication filter.getPasswordlessFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the passwordless authentication filter.getSamlAuthFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the SAML authentication filter.Returns the SAML metadata filter.getSlackFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Slack authentication filter.Returns the authentication success handler.getTwitterFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Twitter authentication filter.static voidsetFacebookAuthFilter(FacebookAuthFilter facebookAuthFilter) For testing only.org.springframework.security.core.userdetails.UserDetailsServiceSupplies the simple in-memoryUserDetailsServiceused for admin authentication.org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizerConfigures the unsecured public resources.
-
Field Details
-
DEFAULT_ROLES
Default roles.
-
-
Constructor Details
-
SecurityConfig
public SecurityConfig()No-args constructor.
-
-
Method Details
-
authenticationManager
@Bean public org.springframework.security.authentication.AuthenticationManager authenticationManager()Configures theAuthenticationManagerwith various providers.- Returns:
- the authentication manager
-
webSecurityCustomizer
@Bean public org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer webSecurityCustomizer()Configures the unsecured public resources.- Returns:
- web security customizer
-
filterChain
@Bean public org.springframework.security.web.SecurityFilterChain filterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.security.authentication.AuthenticationManager authManager, FacebookAuthFilter facebookAuth, GoogleAuthFilter googleAuth, GitHubAuthFilter githubAuth, LinkedInAuthFilter linkedinAuth, TwitterAuthFilter twitterAuth, MicrosoftAuthFilter microsoftAuth, SlackAuthFilter slackAuth, AmazonAuthFilter amazonAuth, GenericOAuth2Filter oauth2Auth, LdapAuthFilter ldapAuth, PasswordAuthFilter passwordAuth, PasswordlessAuthFilter passwordlessAuth) throws Exception Configures the protected private resources.- Parameters:
http- HTTP security objectauthManager- authentication managerfacebookAuth- Facebook auth filtergoogleAuth- Google auth filtergithubAuth- GitHub auth filterlinkedinAuth- LinkedIn auth filtertwitterAuth- Twitter auth filtermicrosoftAuth- Microsoft auth filterslackAuth- Slack auth filteramazonAuth- Amazon auth filteroauth2Auth- generic OAuth2 auth filterldapAuth- LDAP auth filterpasswordAuth- password auth filterpasswordlessAuth- passwordless auth filter- Returns:
- the security filter chain
- Throws:
Exception- ex
-
simpleUserDetailsService
@Bean public org.springframework.security.core.userdetails.UserDetailsService simpleUserDetailsService()Supplies the simple in-memoryUserDetailsServiceused for admin authentication.- Returns:
- service backed by
SimpleUserService
-
getSuccessHandler
Returns the authentication success handler.- Returns:
- success handler
-
getFailureHandler
Returns the authentication failure handler.- Returns:
- failure handler
-
getJWTAuthFilter
@Bean public JWTRestfulAuthFilter getJWTAuthFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager, FacebookAuthFilter facebookAuth, GoogleAuthFilter googleAuth, GitHubAuthFilter githubAuth, LinkedInAuthFilter linkedinAuth, TwitterAuthFilter twitterAuth, MicrosoftAuthFilter microsoftAuth, SlackAuthFilter slackAuth, AmazonAuthFilter amazonAuth, GenericOAuth2Filter oauth2Auth, LdapAuthFilter ldapAuth, PasswordAuthFilter passwordAuth, PasswordlessAuthFilter passwordlessAuth) Returns the JWT restful authentication filter.- Parameters:
authenticationManager- auth managerfacebookAuth- Facebook auth filtergoogleAuth- Google auth filtergithubAuth- GitHub auth filterlinkedinAuth- LinkedIn auth filtertwitterAuth- Twitter auth filtermicrosoftAuth- Microsoft auth filterslackAuth- Slack auth filteramazonAuth- Amazon auth filteroauth2Auth- generic OAuth2 auth filterldapAuth- LDAP auth filterpasswordAuth- password auth filterpasswordlessAuth- passwordless auth filter- Returns:
- filter
-
getPasswordFilter
@Bean public PasswordAuthFilter getPasswordFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the password authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getPasswordlessFilter
@Bean public PasswordlessAuthFilter getPasswordlessFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the passwordless authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getFacebookFilter
@Bean public FacebookAuthFilter getFacebookFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Facebook authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
setFacebookAuthFilter
For testing only.- Parameters:
facebookAuthFilter- used for testing
-
getGoogleFilter
@Bean public GoogleAuthFilter getGoogleFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Google authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getLinkedinFilter
@Bean public LinkedInAuthFilter getLinkedinFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the LinkedIn authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getTwitterFilter
@Bean public TwitterAuthFilter getTwitterFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Twitter authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getGithubFilter
@Bean public GitHubAuthFilter getGithubFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the GitHub authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getMicrosoftFilter
@Bean public MicrosoftAuthFilter getMicrosoftFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Microsoft authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getSlackFilter
@Bean public SlackAuthFilter getSlackFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Slack authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getAmazonFilter
@Bean public AmazonAuthFilter getAmazonFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the Amazon authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getGenericOAuth2Filter
@Bean public GenericOAuth2Filter getGenericOAuth2Filter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the generic OAuth2 authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getLdapAuthFilter
@Bean public LdapAuthFilter getLdapAuthFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the LDAP authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getSamlAuthFilter
@Bean public SAMLAuthFilter getSamlAuthFilter(org.springframework.security.authentication.AuthenticationManager authenticationManager) Returns the SAML authentication filter.- Parameters:
authenticationManager- auth manager- Returns:
- filter
-
getSamlMetadataFilter
Returns the SAML metadata filter.- Returns:
- filter
-