Skip to content

Instantly share code, notes, and snippets.

@TiagoTi
Created May 30, 2018 16:22
Show Gist options
  • Save TiagoTi/ec09666bc86b04d4db154d8e9810de1f to your computer and use it in GitHub Desktop.
Save TiagoTi/ec09666bc86b04d4db154d8e9810de1f to your computer and use it in GitHub Desktop.
basic atutentication
package br.net.ti2.MarinaAbramovick.config;
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.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.httpBasic();
}
@Autowired //Este é o cara que autoriza a requisição
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth.inMemoryAuthentication()
.withUser("tiago").password("{noop}123321").roles("USER")
.and()
.withUser("quel").password("{noop}123123").roles("USER", "ADMIN");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment