Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebSecurity
- public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
- @Autowired
- private UserDetailsService userDetailsService;
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests()
- .antMatchers("/","/about","/contact","/v1/**").permitAll()
- .antMatchers("/admin/otp").hasRole("PRE_AUTH_USER")
- .antMatchers("/admin/**").hasAnyRole("SuperAdmin","BackOffice")
- .antMatchers("/admin/dashboard/**").hasAnyRole("BankAdmin","CallAdmin")
- //.antMatchers("/api/**").hasRole("FieldPerson")
- .anyRequest().authenticated();
- http.formLogin()
- .loginPage("/admin/login")
- .permitAll()
- .defaultSuccessUrl("/admin/otp", true)
- .and()
- .logout()
- .logoutSuccessUrl("/admin/login")
- .permitAll();
- http.exceptionHandling().accessDeniedPage("/error/403");
- }
- @Bean
- public DaoAuthenticationProvider authProvider(){
- DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
- authProvider.setUserDetailsService(userDetailsService);
- authProvider.setPasswordEncoder(new BCryptPasswordEncoder(12));
- return authProvider;
- }
- @Autowired
- public void registerAuthentication(AuthenticationManagerBuilder auth) throws Exception {
- auth.userDetailsService(userDetailsService);
- }
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception{
- auth.userDetailsService(userDetailsService).and().authenticationProvider(authProvider());
- }
- }
Add Comment
Please, Sign In to add comment