Arquivo java | Fórum | School of Net

Deseja poder participar de nosso fórum e tirar todas as suas dúvidas?
Clique aqui e assine nosso plano de acesso ilimitado. Saiba mais.

por Rafael Mendes

1 ano, 9 meses atrás Rafael Mendes

Arquivo java

``` package com.schoolofnet.HelpDeskMaven.configs; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; 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.builders.WebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter{ @Autowired private DataSource dataSource; @Autowired private BCryptPasswordEncoder bCryptPasswordEncoder; @Override protected void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity.authorizeRequests() .antMatchers("/login").permitAll() .antMatchers("/registration/").permitAll() .antMatchers("/**").hasAnyAuthority("ADMIM", "USER").anyRequest() .authenticated() .and() .csrf() .disable() .formLogin() .loginPage("/login") .failureUrl("/login?errors=true") .defaultSuccessUrl("/") .usernameParameter("email") .passwordParameter("password") .and() .logout() .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutSuccessUrl("/") .and() .exceptionHandling() .accessDeniedPage("/denied"); } @Override public void configure(WebSecurity webSecurity) { webSecurity .ignoring().antMatchers("/static/**", "/js/**", "/css/**", "/images/**", "/resources/**"); } @Override protected void configure(AuthenticationManagerBuilder authenticationManager) throws Exception { authenticationManager .jdbcAuthentication() .usersByUsernameQuery("select usr.email, usr.active, usr.password from users usr where usr.email = ?") .authoritiesByUsernameQuery("select usr.email, role from users usr "+ "inner join user_roles usrr on (usr.users_id = usrr.user_id) "+ "inner join role rl on (usrr.role_id = rl.id)"+ "where usr.email = ?") .dataSource(dataSource) .passwordEncoder(bCryptPasswordEncoder); } } ```

1 Respostas