Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @ComponentScan(value="com.spring.loja")
- @EnableWebSecurity
- public class SecurityConfig extends WebSecurityConfigurerAdapter {
- @Autowired
- private UserDetailsService userDetailsService;
- @Autowired
- private SocialUserDetailsService socialUserDetailsService;
- @Autowired
- private PasswordEncoder passwordEncoder;
- @Override
- public void configure(WebSecurity web) throws Exception {
- DefaultWebSecurityExpressionHandler handler = new DefaultWebSecurityExpressionHandler();
- handler.setPermissionEvaluator(new CustomPermissionEvaluator());
- web.expressionHandler(handler);
- }
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .csrf()
- .disable()
- .authorizeRequests()
- .antMatchers("/resources/**", "/erro/**", "/categoria/**", "/produto/**", "/**").permitAll()
- .anyRequest().authenticated()
- .and()
- .formLogin()
- .loginPage("/entrar").permitAll()
- .loginProcessingUrl("/login").permitAll()
- .usernameParameter("login")
- .passwordParameter("senha")
- .defaultSuccessUrl("/admin")
- .failureUrl("/entrar?erro=login").permitAll()
- .and()
- .exceptionHandling()
- .accessDeniedPage("/erro/403")
- .and()
- .logout()
- .logoutUrl("/logout")
- .logoutSuccessUrl("/").permitAll()
- .and()
- .apply(new SpringSocialConfigurer());
- }
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth
- .userDetailsService(userDetailsService)
- .passwordEncoder(passwordEncoder);
- }
- @Bean
- @Override
- public AuthenticationManager authenticationManagerBean() throws Exception {
- return super.authenticationManagerBean();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement