Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1.  
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.context.annotation.Bean;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
  6. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  7. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  8. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  9. import org.springframework.security.core.userdetails.UserDetailsService;
  10. import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
  11. import org.springframework.security.crypto.password.NoOpPasswordEncoder;
  12. import org.springframework.security.crypto.password.PasswordEncoder;
  13.  
  14. @EnableWebSecurity
  15. @Configuration
  16. public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
  17.  
  18.     @Autowired
  19.     UserDetailsService userDetailsService;
  20.    
  21.     @Override
  22.     protected void configure(AuthenticationManagerBuilder auth) throws Exception{
  23.         auth.userDetailsService(userDetailsService);
  24.     }
  25.    
  26.     @Bean
  27.     public BCryptPasswordEncoder getPasswordEncoder() {
  28.         BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
  29.         return passwordEncoder;
  30.     }
  31.    
  32.     @Override
  33.     protected void configure(HttpSecurity http) throws Exception{
  34.         http.authorizeRequests()
  35.             .antMatchers("/sekretar/**").hasRole("sekretar")
  36.             .antMatchers("/clan/**").hasAnyRole("clan","sekretar")
  37.             .antMatchers("/").permitAll()
  38.             .and()
  39.             .formLogin().loginPage("/login.jsp")
  40.             .loginProcessingUrl("/login")
  41.             .defaultSuccessUrl("/pocetna")
  42.             .and()
  43.             .rememberMe()
  44.             .and().csrf().disable();
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement