syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1554186 - in /syncope/branches/1_1_X: common/src/main/java/org/apache/syncope/common/types/ core/src/main/java/org/apache/syncope/core/rest/data/ core/src/main/java/org/apache/syncope/core/rest/utils/ core/src/main/webapp/ core/src/test/ja...
Date Mon, 30 Dec 2013 11:13:03 GMT
Author: ilgrosso
Date: Mon Dec 30 11:13:03 2013
New Revision: 1554186

URL: http://svn.apache.org/r1554186
Log:
[SYNCOPE-466] Replacing IllegalArgumentException thrown on server side with more appropriate
exception

Modified:
    syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/types/SyncopeClientExceptionType.java
    syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
    syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/utils/RestServiceExceptionMapper.java
    syncope/branches/1_1_X/core/src/main/webapp/syncopeClientError.jsp
    syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
    syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java

Modified: syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/types/SyncopeClientExceptionType.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/types/SyncopeClientExceptionType.java?rev=1554186&r1=1554185&r2=1554186&view=diff
==============================================================================
--- syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/types/SyncopeClientExceptionType.java
(original)
+++ syncope/branches/1_1_X/common/src/main/java/org/apache/syncope/common/types/SyncopeClientExceptionType.java
Mon Dec 30 11:13:03 2013
@@ -31,17 +31,15 @@ public enum SyncopeClientExceptionType {
     InvalidLogger("Syncope.InvalidLogger", "Syncope.InvalidLogger.message"),
     InvalidConnInstance("Syncope.InvalidConnInstance", "Syncope.InvalidConnInstance.message"),
     InvalidConnIdConf("Syncope.InvalidConnIdConf", "Syncope.InvalidConnIdConf.message"),
-    InvalidPasswordPolicy("Syncope.InvalidPasswordPolicy", "Syncope.InvalidPasswordPolicy.reason"),
-    InvalidAccountPolicy("Syncope.InvalidAccountPolicy", "Syncope.InvalidAccountPolicy.reason"),
-    InvalidSyncPolicy("Syncope.InvalidSyncPolicy", "Syncope.InvalidSyncPolicy.reason"),
+    InvalidPolicy("Syncope.InvalidPolicy", "Syncope.InvalidPolicy.reason"),
     InvalidSyncopeRole("Syncope.InvalidSyncopeRole", "Syncope.InvalidSyncopeRole.reason"),
     InvalidReportExec("Syncope.InvalidReportExec", "Syncope.InvalidReportExec.reason"),
     InvalidRoles("Syncope.InvalidRoles", "Syncope.InvalidRoles.name"),
     InvalidSchemaDefinition("Syncope.InvalidSchemaDefinition", ""),
     InvalidSearchCondition("Syncope.InvalidSearchCondition", ""),
     InvalidPropagationTaskExecReport(
-    "Syncope.InvalidPropagationTaskExecReport",
-    "Syncope.InvalidPropagationTaskExecReport.element"),
+            "Syncope.InvalidPropagationTaskExecReport",
+            "Syncope.InvalidPropagationTaskExecReport.element"),
     InvalidUSchema("Syncope.InvalidUSchema", "Syncope.InvalidUSchema.name"),
     InvalidUDerSchema("Syncope.InvalidUDerSchema", "Syncope.InvalidUDerSchema.name"),
     InvalidUVirSchema("Syncope.InvalidUVirSchema", "Syncope.InvalidUVirSchema.name"),

Modified: syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java?rev=1554186&r1=1554185&r2=1554186&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
(original)
+++ syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/data/PolicyDataBinder.java
Mon Dec 30 11:13:03 2013
@@ -26,10 +26,14 @@ import org.apache.syncope.common.types.A
 import org.apache.syncope.common.types.PasswordPolicySpec;
 import org.apache.syncope.common.types.PolicyType;
 import org.apache.syncope.common.types.SyncPolicySpec;
+import org.apache.syncope.common.types.SyncopeClientExceptionType;
+import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException;
+import org.apache.syncope.common.validation.SyncopeClientException;
 import org.apache.syncope.core.persistence.beans.AccountPolicy;
 import org.apache.syncope.core.persistence.beans.PasswordPolicy;
 import org.apache.syncope.core.persistence.beans.Policy;
 import org.apache.syncope.core.persistence.beans.SyncPolicy;
+import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -105,8 +109,12 @@ public class PolicyDataBinder {
     @SuppressWarnings("unchecked")
     public <T extends Policy> T getPolicy(T policy, final PolicyTO policyTO) {
         if (policy != null && policy.getType() != policyTO.getType()) {
-            throw new IllegalArgumentException(
-                    String.format("Cannot update %s from %s", policy.getType(), policyTO.getType()));
+            SyncopeClientException sce = new SyncopeClientException(SyncopeClientExceptionType.InvalidPolicy);
+            sce.addElement(String.format("Cannot update %s from %s", policy.getType(), policyTO.getType()));
+            SyncopeClientCompositeErrorException scce =
+                    new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
+            scce.addException(sce);
+            throw scce;
         }
 
         final boolean isGlobal = isGlobalPolicy(policyTO.getType());

Modified: syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/utils/RestServiceExceptionMapper.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/utils/RestServiceExceptionMapper.java?rev=1554186&r1=1554185&r2=1554186&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/utils/RestServiceExceptionMapper.java
(original)
+++ syncope/branches/1_1_X/core/src/main/java/org/apache/syncope/core/rest/utils/RestServiceExceptionMapper.java
Mon Dec 30 11:13:03 2013
@@ -167,10 +167,12 @@ public class RestServiceExceptionMapper 
             } else {
                 return ((BadRequestException) ex).getResponse();
             }
-
         } else if (ex instanceof InvalidEntityException) {
-            SyncopeClientExceptionType exType = SyncopeClientExceptionType.valueOf("Invalid"
-                    + ((InvalidEntityException) ex).getEntityClassSimpleName());
+            SyncopeClientExceptionType exType =
+                    ((InvalidEntityException) ex).getEntityClassSimpleName().endsWith("Policy")
+                    ? SyncopeClientExceptionType.InvalidPolicy
+                    : SyncopeClientExceptionType.valueOf(
+                            "Invalid" + ((InvalidEntityException) ex).getEntityClassSimpleName());
 
             responseBuilder.header(SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER, exType.getHeaderValue());
 

Modified: syncope/branches/1_1_X/core/src/main/webapp/syncopeClientError.jsp
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/main/webapp/syncopeClientError.jsp?rev=1554186&r1=1554185&r2=1554186&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/main/webapp/syncopeClientError.jsp (original)
+++ syncope/branches/1_1_X/core/src/main/webapp/syncopeClientError.jsp Mon Dec 30 11:13:03
2013
@@ -49,8 +49,11 @@ under the License.
     int statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
 
     if (ex instanceof InvalidEntityException) {
-        SyncopeClientExceptionType exType = SyncopeClientExceptionType.valueOf(
-                "Invalid" + ((InvalidEntityException) ex).getEntityClassSimpleName());
+        SyncopeClientExceptionType exType =
+                ((InvalidEntityException) ex).getEntityClassSimpleName().endsWith("Policy")
+                ? SyncopeClientExceptionType.InvalidPolicy
+                : SyncopeClientExceptionType.valueOf(
+                        "Invalid" + ((InvalidEntityException) ex).getEntityClassSimpleName());
 
         response.setHeader(SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER, exType.getHeaderValue());
 

Modified: syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java?rev=1554186&r1=1554185&r2=1554186&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
(original)
+++ syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
Mon Dec 30 11:13:03 2013
@@ -82,7 +82,7 @@ public class PolicyTestITCase extends Ab
             createPolicy(PolicyType.PASSWORD, policy);
             fail();
         } catch (SyncopeClientCompositeErrorException sccee) {
-            assertNotNull(sccee.getException(SyncopeClientExceptionType.InvalidPasswordPolicy));
+            assertNotNull(sccee.getException(SyncopeClientExceptionType.InvalidPolicy));
         }
     }
 
@@ -95,7 +95,7 @@ public class PolicyTestITCase extends Ab
             createPolicy(PolicyType.SYNC, policy);
             fail();
         } catch (SyncopeClientCompositeErrorException sccee) {
-            assertNotNull(sccee.getException(SyncopeClientExceptionType.InvalidSyncPolicy));
+            assertNotNull(sccee.getException(SyncopeClientExceptionType.InvalidPolicy));
         }
     }
 
@@ -165,6 +165,20 @@ public class PolicyTestITCase extends Ab
         assertEquals(1, policyService.getSyncCorrelationRuleClasses(PolicyType.SYNC).size());
     }
 
+    @Test
+    public void issueSYNCOPE466() {
+        PasswordPolicyTO policy = policyService.read(PolicyType.PASSWORD, 4L);
+        assertEquals(PolicyType.PASSWORD, policy.getType());
+
+        policy.setType(PolicyType.GLOBAL_PASSWORD);
+        try {
+            policyService.update(PolicyType.PASSWORD, policy.getId(), policy);
+            fail();
+        } catch (SyncopeClientCompositeErrorException e) {
+            assertNotNull(e.getException(SyncopeClientExceptionType.InvalidPolicy));
+        }
+    }
+
     private SyncPolicyTO buildSyncPolicyTO() {
         SyncPolicyTO policy = new SyncPolicyTO();
 

Modified: syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java?rev=1554186&r1=1554185&r2=1554186&view=diff
==============================================================================
--- syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java
(original)
+++ syncope/branches/1_1_X/core/src/test/java/org/apache/syncope/core/rest/ResourceTestITCase.java
Mon Dec 30 11:13:03 2013
@@ -128,7 +128,6 @@ public class ResourceTestITCase extends 
         assertNotNull(actual);
 
         // check the existence
-
         actual = resourceService.read(resourceName);
         assertNotNull(actual);
     }
@@ -257,7 +256,6 @@ public class ResourceTestITCase extends 
         assertNotNull(actual);
 
         // check the existence
-
         actual = resourceService.read(resourceName);
         assertNotNull(actual);
         assertNotNull(actual.getPasswordPolicy());
@@ -367,7 +365,7 @@ public class ResourceTestITCase extends 
 
     @Test
     public void list() {
-        List<ResourceTO> actuals = resourceService.list(null);
+        List<ResourceTO> actuals = resourceService.list();
         assertNotNull(actuals);
         assertFalse(actuals.isEmpty());
         for (ResourceTO resourceTO : actuals) {
@@ -379,9 +377,10 @@ public class ResourceTestITCase extends 
     public void listByType() {
         List<ResourceTO> actuals = resourceService.list(105L);
 
-        assertNotNull(actuals);
-        assertEquals(1, actuals.size());
-        assertNotNull(actuals.get(0));
+        for (ResourceTO resourceTO : actuals) {
+            assertNotNull(resourceTO);
+            assertEquals(105L, resourceTO.getConnectorId().longValue());
+        }
     }
 
     @Test



Mime
View raw message