You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2009/04/23 05:51:22 UTC

svn commit: r767774 - /ofbiz/trunk/specialpurpose/crowd/src/org/ofbiz/crowd/CrowdAuthenticator.java

Author: jaz
Date: Thu Apr 23 03:51:22 2009
New Revision: 767774

URL: http://svn.apache.org/viewvc?rev=767774&view=rev
Log:
minor change to prevent security groups from failing to be created when one is configured in the crowd mapping but does not actually exist

Modified:
    ofbiz/trunk/specialpurpose/crowd/src/org/ofbiz/crowd/CrowdAuthenticator.java

Modified: ofbiz/trunk/specialpurpose/crowd/src/org/ofbiz/crowd/CrowdAuthenticator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/crowd/src/org/ofbiz/crowd/CrowdAuthenticator.java?rev=767774&r1=767773&r2=767774&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/crowd/src/org/ofbiz/crowd/CrowdAuthenticator.java (original)
+++ ofbiz/trunk/specialpurpose/crowd/src/org/ofbiz/crowd/CrowdAuthenticator.java Thu Apr 23 03:51:22 2009
@@ -210,21 +210,32 @@
         // create security group(s)
         Timestamp now = UtilDateTime.nowTimestamp();
         for (String securityGroup : user.getUserGroupMapper().getSecurityGroups()) {
-            Map<String, Serializable> createSecGrpMap = FastMap.newInstance();
-            createSecGrpMap.put("userLoginId", user.getName());
-            createSecGrpMap.put("groupId", securityGroup);
-            createSecGrpMap.put("fromDate", now);
-            createSecGrpMap.put("userLogin", system);
-
-            Map<String, Object> createSecGrpResult;
-            try {
-                createSecGrpResult = dispatcher.runSync("addUserLoginToSecurityGroup", createSecGrpMap);
-            } catch (GenericServiceException e) {
-                throw new AuthenticatorException(e.getMessage(), e);
-            }
-            if (ServiceUtil.isError(createSecGrpResult)) {
-                throw new AuthenticatorException(ServiceUtil.getErrorMessage(createSecGrpResult));
-            }
+        	// check and make sure the security group exists
+        	GenericValue secGroup = null;
+        	try {
+        		secGroup = delegator.findOne("SecurityGroup", UtilMisc.toMap("groupId", securityGroup), true);
+        	} catch (GenericEntityException e) {
+        		Debug.logError(e, e.getMessage(), module);
+        	}
+        	
+        	// add it to the user if it exists
+        	if (secGroup != null) {
+	            Map<String, Serializable> createSecGrpMap = FastMap.newInstance();
+	            createSecGrpMap.put("userLoginId", user.getName());
+	            createSecGrpMap.put("groupId", securityGroup);
+	            createSecGrpMap.put("fromDate", now);
+	            createSecGrpMap.put("userLogin", system);
+	
+	            Map<String, Object> createSecGrpResult;
+	            try {
+	                createSecGrpResult = dispatcher.runSync("addUserLoginToSecurityGroup", createSecGrpMap);
+	            } catch (GenericServiceException e) {
+	                throw new AuthenticatorException(e.getMessage(), e);
+	            }
+	            if (ServiceUtil.isError(createSecGrpResult)) {
+	                throw new AuthenticatorException(ServiceUtil.getErrorMessage(createSecGrpResult));
+	            }
+        	}
         }
     }