Created
October 9, 2016 20:07
-
-
Save anonymous/d1a8927733bd7d9c6c73224710deb803 to your computer and use it in GitHub Desktop.
Spring Security configuration generated by https://github.com/farrelmr/spring-security-generator
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.glenware.springboot; | |
import org.springframework.beans.factory.annotation.Autowired; | |
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; | |
@EnableWebSecurity | |
public class SecurityConfig extends WebSecurityConfigurerAdapter { | |
@Autowired | |
public void configureGlobal(AuthenticationManagerBuilder auth) | |
throws Exception { | |
auth. | |
inMemoryAuthentication() | |
.withUser("admin").password("admin").roles("admin"); | |
} | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http | |
.authorizeRequests() | |
.antMatchers("/webjars/**","/about.html").permitAll() | |
.antMatchers("/admin/**").hasAnyRole("admin") | |
.anyRequest().authenticated() | |
.and() | |
.formLogin() | |
.loginPage("/login") | |
.defaultSuccessUrl("/admin/admin.html") | |
.failureUrl("/login") | |
.permitAll() | |
.and() | |
.logout() | |
.logoutSuccessUrl("/") | |
.permitAll() | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment