Advertisement
Guest User

Untitled

a guest
Feb 7th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package test.test
  2.  
  3. import test.test.service.UserService;
  4. import test.test.utils.HPassEncoder;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  8. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  9. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  10.  
  11. @Configuration
  12. public class SecurityConfig extends WebSecurityConfigurerAdapter {
  13.  
  14.     @Autowired
  15.     private HPassEncoder hPassEncoder;
  16.     @Autowired
  17.     private UserService userService;
  18.  
  19.     @Override
  20.     protected void configure(HttpSecurity http) throws Exception {
  21.         http.csrf().disable();
  22.         http.authorizeRequests()
  23.                 .antMatchers("/uploadfile/**.", "/users/**/**", "/tasks/**/**")
  24.                 .hasAuthority("admin")
  25.                 .antMatchers("/profile/**")
  26.                 .hasAnyAuthority("user", "admin")
  27.                 .antMatchers("/**")
  28.                 .permitAll()
  29.                 .and()
  30.                 .formLogin().loginPage("/login")
  31.                 .usernameParameter("username")
  32.                 .passwordParameter("password")
  33.                 .and()
  34.                 .logout().logoutSuccessUrl("/login?logout");
  35.     }
  36.  
  37.     @Override
  38.     public void configure(AuthenticationManagerBuilder auth) throws Exception {
  39.         auth.userDetailsService(userService).passwordEncoder(hPassEncoder.bCrypt());
  40.     }
  41.  
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement