Author: ilgrosso
Date: Tue Feb  5 17:40:28 2013
New Revision: 1442674

URL: http://svn.apache.org/viewvc?rev=1442674&view=rev
Log:
Renaming IncompatiblePolicyException to InvalidPasswordPolicySpecException and 
making it checked

Added:
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/InvalidPasswordPolicySpecException.java
      - copied, changed from r1442664, 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/IncompatiblePolicyException.java
Removed:
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/IncompatiblePolicyException.java
Modified:
    
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java
    
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/PasswordGenerator.java
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/connid/PasswordGeneratorTest.java

Modified: 
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java?rev=1442674&r1=1442673&r2=1442674&view=diff
==============================================================================
--- 
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java
 (original)
+++ 
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java
 Tue Feb  5 17:40:28 2013
@@ -20,7 +20,7 @@ package org.apache.syncope.common.types;
 
 import org.apache.syncope.common.AbstractBaseBean;
 
-public class AbstractPolicySpec extends AbstractBaseBean {
+public abstract class AbstractPolicySpec extends AbstractBaseBean {
 
     private static final long serialVersionUID = 2740439904103716653L;
 

Modified: 
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java?rev=1442674&r1=1442673&r2=1442674&view=diff
==============================================================================
--- 
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java
 (original)
+++ 
syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java
 Tue Feb  5 17:40:28 2013
@@ -20,11 +20,9 @@ package org.apache.syncope.common.types;
 
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlType;
-
 import org.apache.syncope.common.annotation.SchemaList;
 
 @XmlType

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java?rev=1442674&r1=1442673&r2=1442674&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/ConnObjectUtil.java
 Tue Feb  5 17:40:28 2013
@@ -57,7 +57,7 @@ import org.apache.syncope.core.rest.cont
 import org.apache.syncope.core.rest.data.UserDataBinder;
 import org.apache.syncope.core.util.ApplicationContextProvider;
 import org.apache.syncope.core.util.AttributableUtil;
-import org.apache.syncope.core.util.IncompatiblePolicyException;
+import org.apache.syncope.core.util.InvalidPasswordPolicySpecException;
 import org.apache.syncope.core.util.JexlUtil;
 import org.apache.syncope.core.util.MappingUtil;
 import org.identityconnectors.common.security.GuardedByteArray;
@@ -164,7 +164,7 @@ public class ConnObjectUtil {
             String password;
             try {
                 password = pwdGen.generatePasswordFromPwdSpec(ppSpecs);
-            } catch (IncompatiblePolicyException e) {
+            } catch (InvalidPasswordPolicySpecException e) {
                 LOG.error("Could not generate policy-compliant random password 
for {}", subjectTO, e);
 
                 password = RandomStringUtils.randomAlphanumeric(16);

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/PasswordGenerator.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/PasswordGenerator.java?rev=1442674&r1=1442673&r2=1442674&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/PasswordGenerator.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/connid/PasswordGenerator.java
 Tue Feb  5 17:40:28 2013
@@ -29,7 +29,7 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
 import org.apache.syncope.core.persistence.dao.PolicyDAO;
 import org.apache.syncope.core.policy.PolicyPattern;
-import org.apache.syncope.core.util.IncompatiblePolicyException;
+import org.apache.syncope.core.util.InvalidPasswordPolicySpecException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,7 +46,7 @@ public class PasswordGenerator {
     private PolicyDAO policyDAO;
 
     public String generatePasswordFromPwdSpec(final List<PasswordPolicySpec> 
passwordPolicySpecs)
-            throws IncompatiblePolicyException {
+            throws InvalidPasswordPolicySpecException {
 
         PasswordPolicySpec policySpec = mergePolicySpecs(passwordPolicySpecs);
 
@@ -56,7 +56,7 @@ public class PasswordGenerator {
     }
 
     public String generateUserPassword(final SyncopeUser user)
-            throws IncompatiblePolicyException {
+            throws InvalidPasswordPolicySpecException {
 
         List<PasswordPolicySpec> userPasswordPolicies = new 
ArrayList<PasswordPolicySpec>();
         PasswordPolicySpec passwordPolicySpec = 
policyDAO.getGlobalPasswordPolicy().getSpecification();
@@ -165,70 +165,50 @@ public class PasswordGenerator {
     }
 
     private void evaluateFinalPolicySpec(final PasswordPolicySpec policySpec)
-            throws IncompatiblePolicyException {
+            throws InvalidPasswordPolicySpecException {
 
         if (policySpec.getMinLength() == 0) {
-            LOG.error("Minimum length given is zero");
-            throw new IncompatiblePolicyException("Minimum length given is 
zero");
+            throw new InvalidPasswordPolicySpecException("Minimum length is 
zero");
         }
         if (policySpec.isMustEndWithAlpha() && 
policySpec.isMustntEndWithAlpha()) {
-            LOG.error("Incompatible password policy specification: 
mustEndWithAlpha and"
-                    + "mustntEndWithAlpha are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustEndWithAlpha and"
-                    + "mustntEndWithAlpha are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustEndWithAlpha and mustntEndWithAlpha are both true");
         }
         if (policySpec.isMustEndWithAlpha() && 
policySpec.isMustEndWithDigit()) {
-            LOG.error("Incompatible password policy specification: 
mustEndWithAlpha and"
-                    + "mustEndWithDigit are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustEndWithAlpha and"
-                    + "mustEndWithDigit are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustEndWithAlpha and mustEndWithDigit are both true");
         }
         if (policySpec.isMustEndWithDigit() && 
policySpec.isMustntEndWithDigit()) {
-            LOG.error("Incompatible password policy specification: 
mustEndWithDigit and"
-                    + "mustntEndWithDigit are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustEndWithDigit and"
-                    + "mustntEndWithDigit are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustEndWithDigit and mustntEndWithDigit are both true");
         }
         if (policySpec.isMustEndWithNonAlpha() && 
policySpec.isMustntEndWithNonAlpha()) {
-            LOG.error("Incompatible password policy specification: 
mustEndWithNonAlpha and"
-                    + "mustntEndWithNonAlpha are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustEndWithNonAlpha and"
-                    + "mustntEndWithNonAlpha are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustEndWithNonAlpha and mustntEndWithNonAlpha are both 
true");
         }
         if (policySpec.isMustStartWithAlpha() && 
policySpec.isMustntStartWithAlpha()) {
-            LOG.error("Incompatible password policy specification: 
mustStartWithAlpha and"
-                    + "mustntStartWithAlpha are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustStartWithAlpha and"
-                    + "mustntStartWithAlpha are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustStartWithAlpha and mustntStartWithAlpha are both 
true");
         }
         if (policySpec.isMustStartWithAlpha() && 
policySpec.isMustStartWithDigit()) {
-            LOG.error("Incompatible password policy specification: 
mustStartWithAlpha and"
-                    + "mustStartWithDigit are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustStartWithAlpha and"
-                    + "mustStartWithDigit are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustStartWithAlpha and mustStartWithDigit are both true");
         }
         if (policySpec.isMustStartWithDigit() && 
policySpec.isMustntStartWithDigit()) {
-            LOG.error("Incompatible password policy specification: 
mustStartWithDigit and"
-                    + "mustntStartWithDigit are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustStartWithDigit and"
-                    + " mustntStartWithDigit are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustStartWithDigit and mustntStartWithDigit are both 
true");
         }
         if (policySpec.isMustStartWithNonAlpha() && 
policySpec.isMustntStartWithNonAlpha()) {
-            LOG.error("Incompatible password policy specification: 
mustStartWithNonAlpha"
-                    + "and mustntStartWithNonAlpha are true");
-            throw new IncompatiblePolicyException("Incompatible password 
policy specification: mustStartWithNonAlpha"
-                    + "and mustntStartWithNonAlpha are true");
+            throw new InvalidPasswordPolicySpecException(
+                    "mustStartWithNonAlpha and mustntStartWithNonAlpha are 
both true");
         }
         if (policySpec.getMinLength() > policySpec.getMaxLength()) {
-            LOG.error("Minimun length given (" + policySpec.getMinLength() + 
") is higher than"
-                    + "maximum allowed (" + policySpec.getMaxLength() + ")");
-            throw new IncompatiblePolicyException("Minimun length given (" + 
policySpec.getMinLength() + ")"
-                    + "is higher than maximum allowed (" + 
policySpec.getMaxLength() + ")");
+            throw new InvalidPasswordPolicySpecException("Minimun length (" + 
policySpec.getMinLength() + ")"
+                    + "is greater than maximum length (" + 
policySpec.getMaxLength() + ")");
         }
     }
 
     private String generatePassword(final PasswordPolicySpec policySpec) {
-
         String[] generatedPassword = new String[policySpec.getMinLength()];
 
         for (int i = 0; i < generatedPassword.length; i++) {
@@ -298,7 +278,7 @@ public class PasswordGenerator {
         }
     }
 
-    private int firstEmptyChar(String[] generatedPStrings) {
+    private int firstEmptyChar(final String[] generatedPStrings) {
         int index = 0;
         while (!generatedPStrings[index].isEmpty()) {
             index++;
@@ -306,7 +286,7 @@ public class PasswordGenerator {
         return index;
     }
 
-    private void checkRequired(String[] generatedPassword, final 
PasswordPolicySpec policySpec) {
+    private void checkRequired(final String[] generatedPassword, final 
PasswordPolicySpec policySpec) {
         if (policySpec.isDigitRequired()
                 && 
!PolicyPattern.DIGIT.matcher(StringUtils.join(generatedPassword)).matches()) {
             generatedPassword[firstEmptyChar(generatedPassword)] = 
RandomStringUtils.randomNumeric(1);
@@ -328,7 +308,7 @@ public class PasswordGenerator {
         }
     }
 
-    private void checkPrefixAndSuffix(String[] generatedPassword, final 
PasswordPolicySpec policySpec) {
+    private void checkPrefixAndSuffix(final String[] generatedPassword, final 
PasswordPolicySpec policySpec) {
         for (Iterator<String> it = 
policySpec.getPrefixesNotPermitted().iterator(); it.hasNext();) {
             String prefix = it.next();
             if (StringUtils.join(generatedPassword).startsWith(prefix)) {

Copied: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/InvalidPasswordPolicySpecException.java
 (from r1442664, 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/IncompatiblePolicyException.java)
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/InvalidPasswordPolicySpecException.java?p2=syncope/trunk/core/src/main/java/org/apache/syncope/core/util/InvalidPasswordPolicySpecException.java&p1=syncope/trunk/core/src/main/java/org/apache/syncope/core/util/IncompatiblePolicyException.java&r1=1442664&r2=1442674&rev=1442674&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/IncompatiblePolicyException.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/InvalidPasswordPolicySpecException.java
 Tue Feb  5 17:40:28 2013
@@ -18,15 +18,20 @@
  */
 package org.apache.syncope.core.util;
 
-public class IncompatiblePolicyException extends RuntimeException {
+/**
+ * Raise when the merge of two or more PasswordPolicySpec leds to incompatible 
condition.
+ *
+ * @see org.apache.syncope.common.types.PasswordPolicySpec
+ */
+public class InvalidPasswordPolicySpecException extends Exception {
 
     private static final long serialVersionUID = 4810651743226663580L;
 
-    public IncompatiblePolicyException(String msg) {
+    public InvalidPasswordPolicySpecException(final String msg) {
         super(msg);
     }
 
-    public IncompatiblePolicyException(String msg, Exception e) {
+    public InvalidPasswordPolicySpecException(final String msg, final 
Exception e) {
         super(msg, e);
     }
 }

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java?rev=1442674&r1=1442673&r2=1442674&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java 
(original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/util/MappingUtil.java 
Tue Feb  5 17:40:28 2013
@@ -206,7 +206,7 @@ public final class MappingUtil {
                 } else if (resource.isRandomPwdIfNotProvided()) {
                     try {
                         passwordAttrValue = 
passwordGenerator.generateUserPassword(user);
-                    } catch (IncompatiblePolicyException e) {
+                    } catch (InvalidPasswordPolicySpecException e) {
                         LOG.error("Could not generate policy-compliant random 
password for {}", user, e);
 
                         passwordAttrValue = 
RandomStringUtils.randomAlphanumeric(16);

Modified: 
syncope/trunk/core/src/test/java/org/apache/syncope/core/connid/PasswordGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/connid/PasswordGeneratorTest.java?rev=1442674&r1=1442673&r2=1442674&view=diff
==============================================================================
--- 
syncope/trunk/core/src/test/java/org/apache/syncope/core/connid/PasswordGeneratorTest.java
 (original)
+++ 
syncope/trunk/core/src/test/java/org/apache/syncope/core/connid/PasswordGeneratorTest.java
 Tue Feb  5 17:40:28 2013
@@ -30,7 +30,7 @@ import org.apache.syncope.core.AbstractN
 import org.apache.syncope.core.persistence.beans.user.SyncopeUser;
 import org.apache.syncope.core.persistence.dao.UserDAO;
 import org.apache.syncope.core.policy.PolicyPattern;
-import org.apache.syncope.core.util.IncompatiblePolicyException;
+import org.apache.syncope.core.util.InvalidPasswordPolicySpecException;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -50,7 +50,7 @@ public class PasswordGeneratorTest exten
         String password = "";
         try {
             password = passwordGenerator.generateUserPassword(user);
-        } catch (IncompatiblePolicyException ex) {
+        } catch (InvalidPasswordPolicySpecException ex) {
             fail(ex.getMessage());
         }
         assertNotNull(password);
@@ -69,7 +69,7 @@ public class PasswordGeneratorTest exten
         try {
             password = passwordGenerator.generateUserPassword(user);
 
-        } catch (IncompatiblePolicyException ex) {
+        } catch (InvalidPasswordPolicySpecException ex) {
             fail(ex.getMessage());
         }
         assertNotNull(password);
@@ -79,7 +79,7 @@ public class PasswordGeneratorTest exten
 
     @Test
     public void startEndWithDigit()
-            throws IncompatiblePolicyException {
+            throws InvalidPasswordPolicySpecException {
 
         PasswordPolicySpec passwordPolicySpec = createBasePasswordPolicySpec();
         passwordPolicySpec.setMustStartWithDigit(true);
@@ -96,7 +96,7 @@ public class PasswordGeneratorTest exten
 
     @Test
     public void startWithDigitAndWithAlpha()
-            throws IncompatiblePolicyException {
+            throws InvalidPasswordPolicySpecException {
 
         PasswordPolicySpec passwordPolicySpec = createBasePasswordPolicySpec();
         passwordPolicySpec.setMustStartWithDigit(true);
@@ -113,7 +113,7 @@ public class PasswordGeneratorTest exten
 
     @Test
     public void passwordWithNonAlpha()
-            throws IncompatiblePolicyException {
+            throws InvalidPasswordPolicySpecException {
 
         PasswordPolicySpec passwordPolicySpec = createBasePasswordPolicySpec();
         passwordPolicySpec.setNonAlphanumericRequired(true);
@@ -128,9 +128,9 @@ public class PasswordGeneratorTest exten
         
assertTrue(Character.isLetter(generatedPassword.charAt(generatedPassword.length()
 - 1)));
     }
 
-    @Test(expected = IncompatiblePolicyException.class)
+    @Test(expected = InvalidPasswordPolicySpecException.class)
     public void incopatiblePolicies()
-            throws IncompatiblePolicyException {
+            throws InvalidPasswordPolicySpecException {
 
         PasswordPolicySpec passwordPolicySpec = createBasePasswordPolicySpec();
         passwordPolicySpec.setMinLength(12);


Reply via email to