Class SecurityConfig

java.lang.Object
api.mpba.rastvdmy.config.SecurityConfig

@Configuration @EnableWebSecurity @EnableMethodSecurity public class SecurityConfig extends Object
Security configuration class for the application that extends Spring Security's capabilities. This class defines the security filter chain, authentication provider, and various security settings for the application.

The configuration includes JWT authentication, CSRF protection disabling, session management, and method-level security.

  • Constructor Summary

    Constructors
    Constructor
    Description
    SecurityConfig(JwtAuthenticationFilter jwtAuthFilter, UserProfileService userProfileService, org.springframework.security.web.AuthenticationEntryPoint authEntryPoint)
    Constructor for SecurityConfig that initializes the security components.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.security.authentication.AuthenticationManager
    authenticationManager(org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration config)
    Provides the authentication manager for the application.
    org.springframework.security.authentication.AuthenticationProvider
    Configures the authentication provider for the application.
    org.springframework.security.crypto.password.PasswordEncoder
    Configures the password encoder to use for encoding passwords.
    org.springframework.security.web.SecurityFilterChain
    securityFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http)
    Configures the security filter chain for the application.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SecurityConfig

      public SecurityConfig(JwtAuthenticationFilter jwtAuthFilter, @Lazy UserProfileService userProfileService, @Qualifier("authenticationEntryPointImpl") org.springframework.security.web.AuthenticationEntryPoint authEntryPoint)
      Constructor for SecurityConfig that initializes the security components.
      Parameters:
      jwtAuthFilter - The JwtAuthenticationFilter for processing JWT authentication.
      userProfileService - The UserProfileService for loading user details.
      authEntryPoint - The AuthenticationEntryPoint to handle authentication exceptions.
  • 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 for the application. This method sets up CSRF protection, XSS protection, session management, request authorization, and exception handling.
      Parameters:
      http - The HttpSecurity object used to configure the security settings.
      Returns:
      The configured SecurityFilterChain.
      Throws:
      Exception - if an error occurs during the configuration.
    • authenticationProvider

      @Bean public org.springframework.security.authentication.AuthenticationProvider authenticationProvider()
      Configures the authentication provider for the application. This method uses a DaoAuthenticationProvider to authenticate users based on user details provided by the UserProfileService and encodes passwords using the PasswordEncoder.
      Returns:
      The configured AuthenticationProvider.
    • authenticationManager

      @Bean public org.springframework.security.authentication.AuthenticationManager authenticationManager(org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration config) throws Exception
      Provides the authentication manager for the application. This bean is required for managing authentication operations.
      Parameters:
      config - The AuthenticationConfiguration object used to retrieve the authentication manager.
      Returns:
      The configured AuthenticationManager.
      Throws:
      Exception - if an error occurs while retrieving the authentication manager.
    • passwordEncoder

      @Bean public org.springframework.security.crypto.password.PasswordEncoder passwordEncoder()
      Configures the password encoder to use for encoding passwords. This method returns a BCryptPasswordEncoder instance for secure password hashing.
      Returns:
      The configured PasswordEncoder.