Rev 218 |
Rev 226 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| Download
| RSS feed
package br.com.ec.controller.seguranca;
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.PasswordEncoder;
@
Configuration
@EnableWebSecurity
public class SecurityConfig
extends WebSecurityConfigurerAdapter
{
// @Autowired
// private UserDetailsService userDetailsService;
// @Autowired
// private SistemaAuthenticationProvider sistemaAuthenticationProvider;
// @Override
// protected void configure(AuthenticationManagerBuilder auth) throws Exception {
// auth.authenticationProvider(sistemaAuthenticationProvider);
// auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
/*
auth.inMemoryAuthentication()
.passwordEncoder(passwordEncoder())
.withUser("user").password(passwordEncoder().encode("123456")).roles("USER")
.and()
.withUser("admin").password(passwordEncoder().encode("123456")).roles("USER", "ADMIN")
.and()
.withUser("bruno").password(passwordEncoder().encode("brunolp0910")).roles("USER", "ADMIN");
*/
// }
@Bean
public PasswordEncoder passwordEncoder
() {
return new BCryptPasswordEncoder
();
}
@
Override
protected void configure
(HttpSecurity http
) throws Exception {
http.
authorizeRequests()
.
antMatchers("/sistema/login**").
permitAll()
.
antMatchers("/sistema/**").
authenticated()
// .anyRequest().authenticated()
// .anyRequest().hasAnyRole("ADMIN", "USER")
.
and().
authorizeRequests()
.
and()
.
formLogin()
.
loginPage("/sistema/login.xhtml")
.
defaultSuccessUrl("/sistema/pagina_inicial.xhtml")
.
failureUrl("/sistema/login.xhtml?login_error=1")
.
loginProcessingUrl("/loginAcao").
permitAll()
.
and()
.
logout().
logoutUrl("/sistema_security_logout").
logoutSuccessUrl("/sistema/login.xhtml?logout=true").
invalidateHttpSession(true).
permitAll()
.
and().
csrf().
disable();
// <logout logout-url="/sistema_security_logout" logout-success-url="/sistema/index.xhtml"/>
/*
http.authorizeRequests()
.antMatchers("/sistema/mega").permitAll()
.antMatchers("/sistema/home").permitAll()
.antMatchers("/sistema/login").permitAll()
.antMatchers("/sistema/**").hasAnyRole("ADMIN", "USER")
//.antMatchers("/sistema/**").authenticated()
.and()
.formLogin()
.loginPage("/sistema/login.xhtml")
.defaultSuccessUrl("/sistema/home.xhtml")
.failureUrl("/sistema/login.xhtml?error=true")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/sistema/login.xhtml?logout=true")
.invalidateHttpSession(true)
.permitAll()
.and()
.csrf()
.disable();
*/
}
}