]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-787 changes suggested during the review CSPACE-886
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 17 Feb 2010 21:24:46 +0000 (21:24 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 17 Feb 2010 21:24:46 +0000 (21:24 +0000)
CSPACE-1010 added email validation (partial checkin)
test collectionobject account security

M    collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectValidatorHandler.java
M    account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.java

services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectValidatorHandler.java

index 487175f15e397e8ae3458e39eae3d2d2a0232fa7..f6336ba3860fad84b8cd593aaa05ff9cee8f3553 100644 (file)
@@ -50,6 +50,8 @@
 package org.collectionspace.services.account.storage;
 
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import org.collectionspace.services.account.AccountsCommon;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentHandler.Action;
@@ -74,29 +76,51 @@ public class AccountValidatorHandler implements ValidatorHandler {
         }
         try {
             AccountsCommon account = (AccountsCommon) ctx.getInput();
-            String msg = "validate() ";
+            StringBuilder msgBldr = new StringBuilder("validate() ");
             boolean invalid = false;
 
             List<AccountsCommon.Tenant> tl = account.getTenant();
             if (tl == null || tl.size() == 0) {
-                msg += " missing tenant information!";
+                msgBldr.append("\ntenant : missing information!");
                 invalid = true;
             }
             if (action.equals(Action.CREATE)) {
                 //create specific validation here
-                if (account.getUserId() == null || "".equals(account.getUserId())) {
+                if (account.getScreenName() == null || account.getScreenName().isEmpty()) {
                     invalid = true;
-                    msg += " userId is missing";
+                    msgBldr.append("\nscreenName : missing");
+                }
+                if (account.getUserId() == null || account.getUserId().isEmpty()) {
+                    invalid = true;
+                    msgBldr.append("\nuserId : missing");
+                }
+                if (account.getEmail() == null || account.getEmail().isEmpty()) {
+                    invalid = true;
+                    msgBldr.append("\nemail : missing");
+                } else {
+                    if (invalidEmail(account.getEmail(), msgBldr)) {
+                        invalid = true;
+                    }
                 }
             } else if (action.equals(Action.UPDATE)) {
                 //update specific validation here
+                if (account.getScreenName() != null && account.getScreenName().isEmpty()) {
+                    invalid = true;
+                    msgBldr.append("\nscreenName : cannot be changed!");
+                }
                 if (account.getPassword() != null
-                        && (account.getUserId() == null || "".equals(account.getUserId()))) {
+                        && (account.getUserId() == null || account.getUserId().isEmpty())) {
                     invalid = true;
-                    msg += " userId is needed with password";
+                    msgBldr.append("\npassword : userId is needed");
+                }
+                if (account.getEmail() != null) {
+                    if (invalidEmail(account.getEmail(), msgBldr)) {
+                        invalid = true;
+                    }
                 }
             }
             if (invalid) {
+                String msg = msgBldr.toString();
                 logger.error(msg);
                 throw new InvalidDocumentException(msg);
             }
@@ -106,4 +130,15 @@ public class AccountValidatorHandler implements ValidatorHandler {
             throw new InvalidDocumentException(e);
         }
     }
+
+    private boolean invalidEmail(String email, StringBuilder msgBldr) {
+        boolean invalid = false;
+        Pattern p = Pattern.compile("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[_A-Za-z0-9-]+)");
+        Matcher m = p.matcher(email);
+        if (!m.find()) {
+            invalid = true;
+            msgBldr.append("\nemail : invalid " + email);
+        }
+        return invalid;
+    }
 }
index a8a8730ea3e7eb29491af172694ee23ba676bfba..492de0df430f5fa9563b303142983c22869cce45 100644 (file)
@@ -76,11 +76,11 @@ public class CollectionObjectValidatorHandler implements ValidatorHandler {
             MultipartServiceContext mctx = (MultipartServiceContext) ctx;
             CollectionobjectsCommon co = (CollectionobjectsCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
                     CollectionobjectsCommon.class);
-            String msg = "";
+            StringBuilder msgBldr = new StringBuilder("validate()");
             boolean invalid = false;
             if (co.getObjectNumber() == null || co.getObjectNumber().isEmpty()) {
                 invalid = true;
-                msg += "objectNumber is missing!";
+                msgBldr.append("\nobjectNumber : missing");
             }
             if(action.equals(Action.CREATE)) {
                 //create specific validation here
@@ -89,6 +89,7 @@ public class CollectionObjectValidatorHandler implements ValidatorHandler {
             }
 
             if (invalid) {
+                String msg = msgBldr.toString();
                 logger.error(msg);
                 throw new InvalidDocumentException(msg);
             }