You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2018/02/07 12:35:58 UTC
[10/11] syncope git commit: Fixing error reporting in case (no more
IllegalArgumentException being returned by REST calls)
http://git-wip-us.apache.org/repos/asf/syncope/blob/43fcd1d6/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
----------------------------------------------------------------------
diff --git a/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java b/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
index 4450208..00a14d1 100644
--- a/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
+++ b/ext/camel/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/CamelRouteService.java
@@ -75,6 +75,7 @@ public interface CamelRouteService extends JAXRSService {
@PUT
@Path("{key}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response update(@NotNull CamelRouteTO route);
/**
@@ -84,6 +85,7 @@ public interface CamelRouteService extends JAXRSService {
*/
@POST
@Path("restartContext")
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response restartContext();
/**
http://git-wip-us.apache.org/repos/asf/syncope/blob/43fcd1d6/ext/saml2sp/logic/src/main/java/org/apache/syncope/core/logic/saml2/SAML2UserManager.java
----------------------------------------------------------------------
diff --git a/ext/saml2sp/logic/src/main/java/org/apache/syncope/core/logic/saml2/SAML2UserManager.java b/ext/saml2sp/logic/src/main/java/org/apache/syncope/core/logic/saml2/SAML2UserManager.java
index 4083a45..bdc5887 100644
--- a/ext/saml2sp/logic/src/main/java/org/apache/syncope/core/logic/saml2/SAML2UserManager.java
+++ b/ext/saml2sp/logic/src/main/java/org/apache/syncope/core/logic/saml2/SAML2UserManager.java
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.core.logic.saml2;
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -115,8 +116,14 @@ public class SAML2UserManager {
}
}
- IntAttrName intAttrName = intAttrNameParser.parse(
- idp.getConnObjectKeyItem().get().getIntAttrName(), AnyTypeKind.USER);
+ IntAttrName intAttrName;
+ try {
+ intAttrName = intAttrNameParser.parse(idp.getConnObjectKeyItem().get().getIntAttrName(), AnyTypeKind.USER);
+ } catch (ParseException e) {
+ LOG.error("Invalid intAttrName '{}' specified, ignoring",
+ idp.getConnObjectKeyItem().get().getIntAttrName(), e);
+ return result;
+ }
if (intAttrName.getField() != null) {
switch (intAttrName.getField()) {
@@ -200,8 +207,6 @@ public class SAML2UserManager {
}
idp.getItems().forEach(item -> {
- IntAttrName intAttrName = intAttrNameParser.parse(item.getIntAttrName(), AnyTypeKind.USER);
-
List<String> values = Collections.emptyList();
Optional<AttrTO> samlAttr = responseTO.getAttr(item.getExtAttrName());
if (samlAttr.isPresent() && !samlAttr.get().getValues().isEmpty()) {
@@ -217,7 +222,14 @@ public class SAML2UserManager {
}
}
- if (intAttrName.getField() != null) {
+ IntAttrName intAttrName = null;
+ try {
+ intAttrName = intAttrNameParser.parse(item.getIntAttrName(), AnyTypeKind.USER);
+ } catch (ParseException e) {
+ LOG.error("Invalid intAttrName '{}' specified, ignoring", item.getIntAttrName(), e);
+ }
+
+ if (intAttrName != null && intAttrName.getField() != null) {
switch (intAttrName.getField()) {
case "username":
if (!values.isEmpty()) {
@@ -228,7 +240,7 @@ public class SAML2UserManager {
default:
LOG.warn("Unsupported: {}", intAttrName.getField());
}
- } else if (intAttrName.getSchemaType() != null) {
+ } else if (intAttrName != null && intAttrName.getSchemaType() != null) {
switch (intAttrName.getSchemaType()) {
case PLAIN:
Optional<AttrTO> attr = userTO.getPlainAttr(intAttrName.getSchemaName());
http://git-wip-us.apache.org/repos/asf/syncope/blob/43fcd1d6/ext/saml2sp/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2IdPDataBinderImpl.java
----------------------------------------------------------------------
diff --git a/ext/saml2sp/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2IdPDataBinderImpl.java b/ext/saml2sp/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2IdPDataBinderImpl.java
index 4413fc3..7a15513 100644
--- a/ext/saml2sp/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2IdPDataBinderImpl.java
+++ b/ext/saml2sp/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2IdPDataBinderImpl.java
@@ -20,6 +20,7 @@ package org.apache.syncope.core.provisioning.java.data;
import java.util.Base64;
import java.util.stream.Collectors;
+import java.text.ParseException;
import org.apache.syncope.common.lib.SyncopeClientCompositeException;
import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.to.AnyTypeClassTO;
@@ -81,9 +82,10 @@ public class SAML2IdPDataBinderImpl implements SAML2IdPDataBinder {
final AnyTypeClassTO allowedSchemas) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
- SyncopeClientException invalidMapping = SyncopeClientException.build(ClientExceptionType.InvalidMapping);
- SyncopeClientException requiredValuesMissing = SyncopeClientException.build(
- ClientExceptionType.RequiredValuesMissing);
+ SyncopeClientException invalidMapping =
+ SyncopeClientException.build(ClientExceptionType.InvalidMapping);
+ SyncopeClientException requiredValuesMissing =
+ SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
for (ItemTO itemTO : idpTO.getItems()) {
if (itemTO == null) {
@@ -93,9 +95,14 @@ public class SAML2IdPDataBinderImpl implements SAML2IdPDataBinder {
requiredValuesMissing.getElements().add("intAttrName");
scce.addException(requiredValuesMissing);
} else {
- IntAttrName intAttrName = intAttrNameParser.parse(itemTO.getIntAttrName(), AnyTypeKind.USER);
+ IntAttrName intAttrName = null;
+ try {
+ intAttrName = intAttrNameParser.parse(itemTO.getIntAttrName(), AnyTypeKind.USER);
+ } catch (ParseException e) {
+ LOG.error("Invalid intAttrName '{}' specified, ignoring", itemTO.getIntAttrName(), e);
+ }
- if (intAttrName.getSchemaType() == null && intAttrName.getField() == null) {
+ if (intAttrName == null || intAttrName.getSchemaType() == null && intAttrName.getField() == null) {
LOG.error("'{}' not existing", itemTO.getIntAttrName());
invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not existing");
} else {
http://git-wip-us.apache.org/repos/asf/syncope/blob/43fcd1d6/ext/saml2sp/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SAML2IdPService.java
----------------------------------------------------------------------
diff --git a/ext/saml2sp/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SAML2IdPService.java b/ext/saml2sp/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SAML2IdPService.java
index fa5b5f3..a3c9bd5 100644
--- a/ext/saml2sp/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SAML2IdPService.java
+++ b/ext/saml2sp/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SAML2IdPService.java
@@ -83,6 +83,7 @@ public interface SAML2IdPService extends JAXRSService {
*/
@POST
@Consumes({ MediaType.APPLICATION_XML })
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response importFromMetadata(@NotNull InputStream input);
/**
@@ -94,6 +95,7 @@ public interface SAML2IdPService extends JAXRSService {
@PUT
@Path("{key}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response update(@NotNull SAML2IdPTO saml2IdpTO);
/**
@@ -104,5 +106,6 @@ public interface SAML2IdPService extends JAXRSService {
*/
@DELETE
@Path("{key}")
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response delete(@PathParam("key") String key);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/43fcd1d6/ext/scimv2/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SCIMConfService.java
----------------------------------------------------------------------
diff --git a/ext/scimv2/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SCIMConfService.java b/ext/scimv2/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SCIMConfService.java
index e877f2d..3a98255 100644
--- a/ext/scimv2/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SCIMConfService.java
+++ b/ext/scimv2/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/SCIMConfService.java
@@ -52,9 +52,10 @@ public interface SCIMConfService extends JAXRSService {
* Sets SCIM configuration.
*
* @param conf SCIM configuration
- * @return Response.noContent().build();
+ * @return an empty response if operation was successful
*/
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
Response set(@NotNull SCIMConf conf);
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/43fcd1d6/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java
index ba3f65c..28ae442 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java
@@ -126,16 +126,6 @@ public class AnyTypeITCase extends AbstractITCase {
}
@Test
- public void deleteInvalid() {
- try {
- anyTypeService.delete(AnyTypeKind.USER.name());
- fail("This should not happen");
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
- }
- }
-
- @Test
public void deleteTypeClass() {
AnyTypeClassTO newClass = new AnyTypeClassTO();
newClass.setKey("new class" + getUUIDString());
http://git-wip-us.apache.org/repos/asf/syncope/blob/43fcd1d6/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ExceptionMapperITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ExceptionMapperITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ExceptionMapperITCase.java
index 08f6532..83e0171 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ExceptionMapperITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ExceptionMapperITCase.java
@@ -29,11 +29,17 @@ import org.apache.syncope.common.lib.SyncopeClientException;
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.to.AnyTypeClassTO;
import org.apache.syncope.common.lib.to.GroupTO;
+import org.apache.syncope.common.lib.to.ItemTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.ResourceTO;
import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
import org.apache.syncope.common.lib.types.AttrSchemaType;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.lib.types.TaskType;
+import org.apache.syncope.common.rest.api.beans.TaskQuery;
+import org.apache.syncope.common.rest.api.service.AccessTokenService;
import org.apache.syncope.fit.AbstractITCase;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -146,4 +152,51 @@ public class ExceptionMapperITCase extends AbstractITCase {
assertEquals(2, e.getExceptions().size());
}
}
+
+ @Test
+ public void invalidRequests() {
+ try {
+ taskService.list(new TaskQuery.Builder(TaskType.NOTIFICATION).resource(RESOURCE_NAME_LDAP).build());
+ fail("This should not happen");
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+ try {
+ taskService.list(new TaskQuery.Builder(TaskType.PULL).anyTypeKind(AnyTypeKind.ANY_OBJECT).build());
+ fail("This should not happen");
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+ try {
+ taskService.list(new TaskQuery.Builder(TaskType.PULL).
+ notification("e00945b5-1184-4d43-8e45-4318a8dcdfd4").build());
+ fail("This should not happen");
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+
+ try {
+ anyTypeService.delete(AnyTypeKind.USER.name());
+ fail("This should not happen");
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+
+ try {
+ clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(AccessTokenService.class).login();
+ fail("This should not happen");
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+
+ try {
+ ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
+ ItemTO mapping = ldap.getProvisions().get(0).getMapping().getItems().get(0);
+ mapping.setIntAttrName("memberships.cn");
+ resourceService.update(ldap);
+ fail("This should not happen");
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidMapping, e.getType());
+ }
+ }
}