Skip to content

Instantly share code, notes, and snippets.

@sirius2k
Created July 1, 2018 14:23
Show Gist options
  • Save sirius2k/9097f782392255059ba922825002f39c to your computer and use it in GitHub Desktop.
Save sirius2k/9097f782392255059ba922825002f39c to your computer and use it in GitHub Desktop.
Use h2 database console with SpringBoot and SpringSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeRequests()
.antMatchers("/login/**").permitAll()
.antMatchers("/login").permitAll()
.antMatchers("/h2/**").permitAll() // here
.antMatchers("/**").authenticated()
.and()
.formLogin()
.loginPage("/login/form")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/")
.failureUrl("/login/form?error=true")
.usernameParameter("id")
.passwordParameter("password")
.and()
.headers() // here
.frameOptions()
.disable()
.and()
.csrf() // here
.ignoringAntMatchers("/h2/**")
.and()
.logout();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment