Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
- import org.springframework.security.config.annotation.web.builders.HttpSecurity;
- import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
- import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
- import org.springframework.security.core.userdetails.UserDetailsService;
- import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
- import org.springframework.security.crypto.password.NoOpPasswordEncoder;
- import org.springframework.security.crypto.password.PasswordEncoder;
- @EnableWebSecurity
- @Configuration
- public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
- @Autowired
- UserDetailsService userDetailsService;
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception{
- auth.userDetailsService(userDetailsService);
- }
- @Bean
- public BCryptPasswordEncoder getPasswordEncoder() {
- BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
- return passwordEncoder;
- }
- @Override
- protected void configure(HttpSecurity http) throws Exception{
- http.authorizeRequests()
- .antMatchers("/sekretar/**").hasRole("sekretar")
- .antMatchers("/clan/**").hasAnyRole("clan","sekretar")
- .antMatchers("/").permitAll()
- .and()
- .formLogin().loginPage("/login.jsp")
- .loginProcessingUrl("/login")
- .defaultSuccessUrl("/pocetna")
- .and()
- .rememberMe()
- .and().csrf().disable();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement