From 047576dbddea1fe7ecba46f151ec723807c098b2 Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Mon, 24 Mar 2014 20:38:38 -0500 Subject: [PATCH] Cleanup SecurityConfiguration - Clean imports - Remove unnecessary rememberMeServices() since this is already created via classpath scanning - Remove unnecessary RememberMeAuthenticationProvider. This is already created via http.rememberMe().rememberMeServices() - Remove unnecessary authenticationManager() Bean. This is not necessary since the AuthenticationManagerBuilder is being used - Removed unnecessary UserDetailsService since this is already created via classpath scanning - Use global AuthenticationManagerBuilder to expose to method security --- .../myapp/config/SecurityConfiguration.java | 35 ++++++------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/mycompany/myapp/config/SecurityConfiguration.java b/src/main/java/com/mycompany/myapp/config/SecurityConfiguration.java index b125ec9e4bfa..bc520bed339d 100644 --- a/src/main/java/com/mycompany/myapp/config/SecurityConfiguration.java +++ b/src/main/java/com/mycompany/myapp/config/SecurityConfiguration.java @@ -1,12 +1,9 @@ package com.mycompany.myapp.config; -import com.mycompany.myapp.config.reload.condition.ConditionalOnSpringLoaded; import com.mycompany.myapp.security.*; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.RememberMeAuthenticationProvider; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration; @@ -40,34 +37,22 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Inject private Http401UnauthorizedEntryPoint authenticationEntryPoint; - @Bean - public RememberMeServices rememberMeServices() { - return new CustomPersistentRememberMeServices(env, userDetailsService()); - } - - @Bean - public RememberMeAuthenticationProvider rememberMeAuthenticationProvider() { - return new RememberMeAuthenticationProvider(env.getProperty("jhipster.security.rememberme.key")); - } + @Inject + private UserDetailsService userDetailsService; - @Bean - public AuthenticationManager authenticationManager() throws Exception { - return super.authenticationManager(); - } + @Inject + private RememberMeServices rememberMeServices; @Bean public PasswordEncoder passwordEncoder() { return new StandardPasswordEncoder(); } - @Bean - public UserDetailsService userDetailsService() { - return new com.mycompany.myapp.security.UserDetailsService(); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userDetailsService()).passwordEncoder(passwordEncoder()); + @Inject + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth + .userDetailsService(userDetailsService) + .passwordEncoder(passwordEncoder()); } @Override @@ -89,7 +74,7 @@ protected void configure(HttpSecurity http) throws Exception { .authenticationEntryPoint(authenticationEntryPoint) .and() .rememberMe() - .rememberMeServices(rememberMeServices()) + .rememberMeServices(rememberMeServices) .key(env.getProperty("jhipster.security.rememberme.key")) .and() .formLogin()