Last active
September 30, 2018 22:26
-
-
Save m1k3yfoo/c809415d245ffd648046c2adde000c98 to your computer and use it in GitHub Desktop.
[Spring Boot Security Config] #SpringBoot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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