-
-
Save monkey-codes/534167e67d17e985f15b8d4f8deea7da to your computer and use it in GitHub Desktop.
Configuring Spring Web Security with OAuth
This file contains hidden or 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
| @Configuration | |
| @Order(-20) | |
| static class WebSecurityConfig extends WebSecurityConfigurerAdapter { | |
| @Override | |
| @Bean | |
| AuthenticationManager authenticationManagerBean() throws Exception { | |
| super.authenticationManagerBean() | |
| } | |
| @Override | |
| protected void configure(HttpSecurity http) throws Exception { | |
| http | |
| .formLogin().loginPage('/login').permitAll() | |
| .and().httpBasic().and() | |
| .requestMatchers() | |
| //specify urls handled | |
| .antMatchers("/login", "/oauth/authorize", "/oauth/confirm_access") | |
| .antMatchers("/fonts/**", "/js/**", "/css/**") | |
| .and() | |
| .authorizeRequests() | |
| .antMatchers("/fonts/**", "/js/**", "/css/**").permitAll() | |
| .anyRequest().authenticated() | |
| } | |
| @Override | |
| protected void configure(AuthenticationManagerBuilder auth) throws Exception { | |
| auth.inMemoryAuthentication() | |
| .withUser('reader') | |
| .password('reader') | |
| .authorities('ROLE_READER') | |
| .and() | |
| .withUser('guest') | |
| .password('guest') | |
| .authorities('ROLE_GUEST') | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment