Skip to content

Instantly share code, notes, and snippets.

Created October 9, 2016 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/d1a8927733bd7d9c6c73224710deb803 to your computer and use it in GitHub Desktop.
Save anonymous/d1a8927733bd7d9c6c73224710deb803 to your computer and use it in GitHub Desktop.
Spring Security configuration generated by https://github.com/farrelmr/spring-security-generator
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