Advertisement
andersonalmada2

Untitled

Aug 5th, 2022
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. package br.ufc.mandacaru5.config.security;
  2.  
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.security.authentication.AuthenticationManager;
  6. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  7. import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
  8. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  9. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  10. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  11. import org.springframework.security.config.http.SessionCreationPolicy;
  12. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  13. import org.springframework.security.crypto.password.PasswordEncoder;
  14. import org.springframework.stereotype.Component;
  15.  
  16. @Component
  17. @EnableWebSecurity
  18. @EnableGlobalMethodSecurity(prePostEnabled = true)
  19. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  20.  
  21.     @Autowired
  22.     UserDetailsServiceImpl userDetailsServiceImpl;
  23.  
  24.     @Override
  25.     protected void configure(HttpSecurity http) throws Exception {
  26.         http.httpBasic().and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().csrf().disable();
  27.     }
  28.  
  29.     @Override
  30.     protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  31.         auth.userDetailsService(userDetailsServiceImpl).passwordEncoder(passwordEncoder());
  32.     }
  33.  
  34.     @Bean
  35.     public PasswordEncoder passwordEncoder() {
  36.         return new BCryptPasswordEncoder();
  37.     }
  38.  
  39.     @Override
  40.     @Bean
  41.     public AuthenticationManager authenticationManagerBean() throws Exception {
  42.         return super.authenticationManagerBean();
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement