Class SecurityConfigurations
java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.infra.security.SecurityConfigurations
Security configuration class for setting up Spring Security in the application.
Configures HTTP security, authentication manager, password encoding, and the security filter chain.
-
Constructor Summary
ConstructorsConstructorDescriptionSecurityConfigurations
(SecurityFilter securityFilter) Constructs a newSecurityConfigurations
instance with the specified security filter. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.authentication.AuthenticationManager
authenticationManager
(org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration configuration) Provides theAuthenticationManager
bean configured by Spring Security.org.springframework.security.crypto.password.PasswordEncoder
Provides the password encoder bean using BCrypt hashing algorithm.org.springframework.security.web.SecurityFilterChain
securityFilterChain
(org.springframework.security.config.annotation.web.builders.HttpSecurity http) Configures the security filter chain with HTTP security rules.
-
Constructor Details
-
SecurityConfigurations
Constructs a newSecurityConfigurations
instance with the specified security filter.- Parameters:
securityFilter
- the custom security filter to be applied before authentication
-
-
Method Details
-
securityFilterChain
@Bean public org.springframework.security.web.SecurityFilterChain securityFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http) throws Exception Configures the security filter chain with HTTP security rules.- Disables CSRF protection (for stateless REST APIs).
- Sets session management to stateless.
- Defines endpoint authorization rules:
- Permits everyone to access POST /users/login and POST /users.
- Restricts GET /users to users with the role OWNER.
- Requires authentication for all other requests.
- Sets custom access denied handler returning 403 with message.
- Adds the custom security filter before the username-password authentication filter.
- Parameters:
http
- theHttpSecurity
to configure- Returns:
- the configured
SecurityFilterChain
- Throws:
Exception
- in case of configuration errors
-
authenticationManager
@Bean public org.springframework.security.authentication.AuthenticationManager authenticationManager(org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration configuration) throws Exception Provides theAuthenticationManager
bean configured by Spring Security.- Parameters:
configuration
- theAuthenticationConfiguration
provided by Spring- Returns:
- the authentication manager
- Throws:
Exception
- if unable to get the authentication manager
-
passwordEncoder
@Bean public org.springframework.security.crypto.password.PasswordEncoder passwordEncoder()Provides the password encoder bean using BCrypt hashing algorithm.- Returns:
- a
PasswordEncoder
instance
-