Rev 218 |
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
;
@
Override
protected void configure
(AuthenticationManagerBuilder auth
) throws Exception {
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");
// auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@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()
.
antMatchers("/sistema/login").
permitAll()
.
and()
.
formLogin()
.
loginPage("/sistema/login.xhtml")
.
defaultSuccessUrl("/sistema/home.xhtml")
.
failureUrl("/sistema/login.xhtml?error=true")
.
loginProcessingUrl("/loginAcao").
permitAll()
.
and()
.
logout().
logoutSuccessUrl("/sistema/login.xhtml?logout=true").
invalidateHttpSession(true).
permitAll()
.
and().
csrf().
disable();
/*
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();
*/
}
}