package br.gov.servicos.editor.config;

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.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder;

import static br.gov.servicos.editor.usuarios.Papeis.ADMIN;
import static br.gov.servicos.editor.usuarios.Papeis.PUBLICADOR;
import static br.gov.servicos.editor.usuarios.Papeis.SUPER;

class SecurityConfig extends WebSecurityConfigurerAdapter {

    private PasswordEncoder passwordEncoder;

    public SecurityConfig(PasswordEncoder passwordEncoder) {
        this.passwordEncoder = passwordEncoder;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/editar/info").permitAll()
                .antMatchers("/editar/health").permitAll()
                .antMatchers("/editar/assets/**").permitAll()
                .antMatchers("/editar/fonts/**").permitAll()
                .anyRequest().authenticated();

        http.formLogin()
                .loginPage("/editar/login")
                .permitAll();

        http.logout()
                .permitAll();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        String hash = "46022771041f1486dc97b709a9bb35a3601ed9b7cbf82df729fcdf5319d48df0cad832848c6c3e82";

        auth.inMemoryAuthentication()
                .passwordEncoder(passwordEncoder)

                .withUser("mauricio.formiga@planejamento.gov.br").password(hash).roles(SUPER).and()
                .withUser("fabricio.fontenele@planejamento.gov.br").password(hash).roles(SUPER).and()
                .withUser("silvia.belarmino@planejamento.gov.br").password(hash).roles(ADMIN).and()
                .withUser("everson.aguiar@planejamento.gov.br").password(hash).roles(ADMIN).and()

                .withUser("cvillela@thoughtworks.com").password(hash).roles(PUBLICADOR).and()
                .withUser("oliviaj@thoughtworks.com").password(hash).roles(PUBLICADOR).and()
                .withUser("srosa@thoughtworks.com").password(hash).roles(PUBLICADOR).and()
                .withUser("jkirchne@thoughtworks.com").password(hash).roles(PUBLICADOR)
        ;
    }
}

@@ -451,138 +451,9 @@
 eis.
-ADMIN;%0Aimport static br.gov.servicos.editor.usuarios.Papeis.PUBLICADOR;%0Aimport static br.gov.servicos.editor.usuarios.Papeis.SUPER
+*
 ;%0A%0Ac
@@ -1147,78 +1147,114 @@
 in%22)
-%0A                .permitAll();%0A%0A        http.logout()%0A                
+.permitAll().and()%0A                .logout().logoutUrl(%22/editar/logout%22).logoutSuccessUrl(%22/editar/login%22)
 .per

Corrige configuração de logout - resolve #133