Skip to content

Instantly share code, notes, and snippets.

@m1k3yfoo
Last active September 30, 2018 22:26
Show Gist options
  • Save m1k3yfoo/c809415d245ffd648046c2adde000c98 to your computer and use it in GitHub Desktop.
Save m1k3yfoo/c809415d245ffd648046c2adde000c98 to your computer and use it in GitHub Desktop.
[Spring Boot Security Config] #SpringBoot
package com.example.project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
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;
@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthenticationEntryPoint authEntryPoint;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.anyRequest().authenticated()
.and().httpBasic()
.authenticationEntryPoint(authEntryPoint);
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("username").password("password").roles("USER");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment