Created
January 10, 2017 13:59
-
-
Save codecitizen/8d130469d83439f5fca86b1a84733aab to your computer and use it in GitHub Desktop.
Buggy OAuth2 Spring Security Authorization Server Configuration
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.myapp.security; | |
import com.myapp.core.domain.PermissionsRepository; | |
import com.myapp.core.domain.UserRepository; | |
import com.myapp.core.service.PasswordEncoder; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.actuate.autoconfigure.ManagementServerProperties; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.core.annotation.Order; | |
import org.springframework.security.authentication.AuthenticationManager; | |
import org.springframework.security.authentication.dao.DaoAuthenticationProvider; | |
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |
/** | |
* Configurations for Spring Web Security. | |
* | |
* @since 1.0 | |
* @author amp | |
*/ | |
@Configuration | |
@Order(ManagementServerProperties.ACCESS_OVERRIDE_ORDER) | |
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { | |
@Override | |
@Bean | |
public AuthenticationManager authenticationManagerBean() throws Exception { | |
return super.authenticationManagerBean(); | |
} | |
@Override | |
protected void configure(AuthenticationManagerBuilder auth) throws Exception { | |
auth.authenticationProvider(daoAuthenticationProvider()); | |
} | |
@Bean | |
public DaoAuthenticationProvider daoAuthenticationProvider() { | |
DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); | |
provider.setUserDetailsService(userDetailsService()); | |
provider.setPasswordEncoder(passwordEncoder.getInstance()); | |
return provider; | |
} | |
@Autowired | |
private PasswordEncoder passwordEncoder; | |
@Bean | |
public MyappUserDetailsService userDetailsService() { | |
return new MyappUserDetailsService(userRepository, permissionsRepository); | |
} | |
@Autowired | |
private UserRepository userRepository; | |
@Autowired | |
private PermissionsRepository permissionsRepository; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&ved=2ahUKEwit-o3utpL2AhVahHIEHZCdDIwQFnoECAMQAQ&url=https%3A%2F%2Fkzitem.info%2Fnews%2Fevery-star-wars-reference-in-the-venture-bros%2FmaN_s3WifWqjnnY&usg=AOvVaw1nf-Fci10BdL_Qvmrd8CSD