From e951c42c2b45bb04ce16013a0bdf45a4113d8299 Mon Sep 17 00:00:00 2001
From: Luke Taylor <luke.taylor@springsource.com>
Date: Wed, 6 Aug 2008 15:28:04 +0000
Subject: [PATCH] Improved javadoc. Some tidying up.

---
 ...ailsServiceInjectionBeanPostProcessor.java | 146 +++++++++---------
 1 file changed, 72 insertions(+), 74 deletions(-)

diff --git a/core/src/main/java/org/springframework/security/config/UserDetailsServiceInjectionBeanPostProcessor.java b/core/src/main/java/org/springframework/security/config/UserDetailsServiceInjectionBeanPostProcessor.java
index 85be87698d..cbe3433387 100644
--- a/core/src/main/java/org/springframework/security/config/UserDetailsServiceInjectionBeanPostProcessor.java
+++ b/core/src/main/java/org/springframework/security/config/UserDetailsServiceInjectionBeanPostProcessor.java
@@ -2,8 +2,6 @@ package org.springframework.security.config;
 
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.springframework.beans.BeanWrapperImpl;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.PropertyValue;
@@ -21,91 +19,91 @@ import org.springframework.security.userdetails.UserDetailsService;
 import org.springframework.util.Assert;
 
 /**
- * 
+ * Registered by {@link HttpSecurityBeanDefinitionParser} to inject a UserDetailsService into
+ * the X509Provider, RememberMeServices and OpenIDAuthenticationProvider instances created by
+ * the namespace.
+ *
  * @author Luke Taylor
  * @since 2.0.2
  */
 public class UserDetailsServiceInjectionBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware {
-    private final Log logger = LogFactory.getLog(getClass());
-    private ConfigurableListableBeanFactory beanFactory;	
-	
-	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
-		if (BeanIds.X509_AUTH_PROVIDER.equals(beanName)) {
-			injectUserDetailsServiceIntoX509Provider((PreAuthenticatedAuthenticationProvider) bean);
-		} else if (BeanIds.REMEMBER_ME_SERVICES.equals(beanName)) {
-			injectUserDetailsServiceIntoRememberMeServices((AbstractRememberMeServices)bean);
-		} else if (BeanIds.OPEN_ID_PROVIDER.equals(beanName)) {
-			injectUserDetailsServiceIntoOpenIDProvider(bean);
-		}
-		
-		return bean;
-	}
-	
-	
-	
-	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
-		return bean;
-	}
-	
+    private ConfigurableListableBeanFactory beanFactory;
+
+    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
+        if (BeanIds.X509_AUTH_PROVIDER.equals(beanName)) {
+            injectUserDetailsServiceIntoX509Provider((PreAuthenticatedAuthenticationProvider) bean);
+        } else if (BeanIds.REMEMBER_ME_SERVICES.equals(beanName)) {
+            injectUserDetailsServiceIntoRememberMeServices((AbstractRememberMeServices)bean);
+        } else if (BeanIds.OPEN_ID_PROVIDER.equals(beanName)) {
+            injectUserDetailsServiceIntoOpenIDProvider(bean);
+        }
+
+        return bean;
+    }
+
+    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
+        return bean;
+    }
+
     private void injectUserDetailsServiceIntoRememberMeServices(AbstractRememberMeServices services) {
         BeanDefinition beanDefinition = beanFactory.getBeanDefinition(BeanIds.REMEMBER_ME_SERVICES);
         PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("userDetailsService");
 
         if (pv == null) {
-        	services.setUserDetailsService(getUserDetailsService());
+            services.setUserDetailsService(getUserDetailsService());
         } else {
-        	UserDetailsService cachingUserService = getCachingUserService(pv.getValue());
-        	
-        	if (cachingUserService != null) {
-        		services.setUserDetailsService(cachingUserService);
-        	}            	
+            UserDetailsService cachingUserService = getCachingUserService(pv.getValue());
+
+            if (cachingUserService != null) {
+                services.setUserDetailsService(cachingUserService);
+            }
         }
     }
-	
+
     private void injectUserDetailsServiceIntoX509Provider(PreAuthenticatedAuthenticationProvider provider) {
         BeanDefinition beanDefinition = beanFactory.getBeanDefinition(BeanIds.X509_AUTH_PROVIDER);
         PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("preAuthenticatedUserDetailsService");
         UserDetailsByNameServiceWrapper wrapper = new UserDetailsByNameServiceWrapper();
-        
+
         if (pv == null) {
-        	wrapper.setUserDetailsService(getUserDetailsService());
-        	provider.setPreAuthenticatedUserDetailsService(wrapper);
+            wrapper.setUserDetailsService(getUserDetailsService());
+            provider.setPreAuthenticatedUserDetailsService(wrapper);
         } else {
-        	RootBeanDefinition preAuthUserService = (RootBeanDefinition) pv.getValue();
-        	Object userService = 
-        		preAuthUserService.getPropertyValues().getPropertyValue("userDetailsService").getValue();
-        	
-        	UserDetailsService cachingUserService = getCachingUserService(userService);
-        	
-        	if (cachingUserService != null) {
-        		wrapper.setUserDetailsService(cachingUserService);
-        		provider.setPreAuthenticatedUserDetailsService(wrapper);
-        	}
+            RootBeanDefinition preAuthUserService = (RootBeanDefinition) pv.getValue();
+            Object userService =
+                preAuthUserService.getPropertyValues().getPropertyValue("userDetailsService").getValue();
+
+            UserDetailsService cachingUserService = getCachingUserService(userService);
+
+            if (cachingUserService != null) {
+                wrapper.setUserDetailsService(cachingUserService);
+                provider.setPreAuthenticatedUserDetailsService(wrapper);
+            }
         }
     }
-    
+
     private void injectUserDetailsServiceIntoOpenIDProvider(Object bean) {
         BeanDefinition beanDefinition = beanFactory.getBeanDefinition(BeanIds.OPEN_ID_PROVIDER);
         PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("userDetailsService");
 
         if (pv == null) {
-        	BeanWrapperImpl beanWrapper = new BeanWrapperImpl(bean);
+            BeanWrapperImpl beanWrapper = new BeanWrapperImpl(bean);
             beanWrapper.setPropertyValue("userDetailsService", getUserDetailsService());
         }
     }
-    
-    
+
+
     /**
      * Obtains a user details service for use in RememberMeServices etc. Will return a caching version
-     * if available so should not be used for beans which need to separate the two. 
+     * if available so should not be used for beans which need to separate the two.
      */
     UserDetailsService getUserDetailsService() {
-    	Map beans = beanFactory.getBeansOfType(CachingUserDetailsService.class);
-    	
-    	if (beans.size() == 0) {
-    		beans = beanFactory.getBeansOfType(UserDetailsService.class);
-    	}
-    	        
+        Map beans = beanFactory.getBeansOfType(CachingUserDetailsService.class);
+
+        if (beans.size() == 0) {
+            beans = beanFactory.getBeansOfType(UserDetailsService.class);
+        }
+
         if (beans.size() == 0) {
             throw new SecurityConfigurationException("No UserDetailsService registered.");
 
@@ -116,24 +114,24 @@ public class UserDetailsServiceInjectionBeanPostProcessor implements BeanPostPro
 
         return (UserDetailsService) beans.values().toArray()[0];
     }
-    
-    private UserDetailsService getCachingUserService(Object userServiceRef) {
-    	Assert.isInstanceOf(RuntimeBeanReference.class, userServiceRef, 
-    			"userDetailsService property value must be a RuntimeBeanReference");
-    	
-    	String id = ((RuntimeBeanReference)userServiceRef).getBeanName();
-    	// Overwrite with the caching version if available
-    	String cachingId = id + AbstractUserDetailsServiceBeanDefinitionParser.CACHING_SUFFIX;
-    	
-    	if (beanFactory.containsBeanDefinition(cachingId)) {
-    		return (UserDetailsService) beanFactory.getBean(cachingId);
-    	}
-    	
-    	return null;
-    }
-    
 
-	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
-		this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
-	}
+    private UserDetailsService getCachingUserService(Object userServiceRef) {
+        Assert.isInstanceOf(RuntimeBeanReference.class, userServiceRef,
+                "userDetailsService property value must be a RuntimeBeanReference");
+
+        String id = ((RuntimeBeanReference)userServiceRef).getBeanName();
+        // Overwrite with the caching version if available
+        String cachingId = id + AbstractUserDetailsServiceBeanDefinitionParser.CACHING_SUFFIX;
+
+        if (beanFactory.containsBeanDefinition(cachingId)) {
+            return (UserDetailsService) beanFactory.getBean(cachingId);
+        }
+
+        return null;
+    }
+
+
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
+        this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
+    }
 }