Created
May 15, 2019 00:48
-
-
Save ohjuntaek/4dadb1c56bd4d6818cc1ecab795767d9 to your computer and use it in GitHub Desktop.
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
// src/main/java/hello/ | |
package hello; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
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.User; | |
import org.springframework.security.core.userdetails.UserDetails; | |
import org.springframework.security.core.userdetails.UserDetailsService; | |
import org.springframework.security.provisioning.InMemoryUserDetailsManager; | |
@Configuration | |
@EnableWebSecurity | |
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http | |
.authorizeRequests() | |
.antMatchers("/", "/home").permitAll() | |
.anyRequest().authenticated() | |
.and() | |
.formLogin() | |
.loginPage("/login") | |
.permitAll() | |
.and() | |
.logout() | |
.permitAll(); | |
} | |
@Bean | |
@Override | |
public UserDetailsService userDetailsService() { | |
UserDetails user = | |
User.withDefaultPasswordEncoder() | |
.username("user") | |
.password("password") | |
.roles("USER") | |
.build(); | |
return new InMemoryUserDetailsManager(user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment