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:54 UTC
[06/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/188df890/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 b0f5956..f4374e6 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;
@@ -100,7 +101,13 @@ public class SAML2UserManager {
}
}
- IntAttrName intAttrName = intAttrNameParser.parse(connObjectKeyItem.getIntAttrName(), AnyTypeKind.USER);
+ IntAttrName intAttrName;
+ try {
+ intAttrName = intAttrNameParser.parse(connObjectKeyItem.getIntAttrName(), AnyTypeKind.USER);
+ } catch (ParseException e) {
+ LOG.error("Invalid intAttrName '{}' specified, ignoring", connObjectKeyItem.getIntAttrName(), e);
+ return result;
+ }
if (intAttrName.getField() != null) {
switch (intAttrName.getField()) {
@@ -187,8 +194,6 @@ public class SAML2UserManager {
private void fill(final SAML2IdPEntity idp, final SAML2LoginResponseTO responseTO, final UserTO userTO) {
for (ItemTO item : idp.getItems()) {
- IntAttrName intAttrName = intAttrNameParser.parse(item.getIntAttrName(), AnyTypeKind.USER);
-
List<String> values = Collections.emptyList();
AttrTO samlAttr = responseTO.getAttr(item.getExtAttrName());
if (samlAttr != null && !samlAttr.getValues().isEmpty()) {
@@ -204,7 +209,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()) {
@@ -215,7 +227,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:
AttrTO attr = userTO.getPlainAttr(intAttrName.getSchemaName());
http://git-wip-us.apache.org/repos/asf/syncope/blob/188df890/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 9e7af26..17842d3 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
@@ -18,6 +18,7 @@
*/
package org.apache.syncope.core.provisioning.java.data;
+import java.text.ParseException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.syncope.common.lib.SyncopeClientCompositeException;
import org.apache.syncope.common.lib.SyncopeClientException;
@@ -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/188df890/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/188df890/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/188df890/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 93cd326..a85677d 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();
- } 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/188df890/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 ac1cf5d..ed68dcc 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.BeforeClass;
import org.junit.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();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+ try {
+ taskService.list(new TaskQuery.Builder(TaskType.PULL).anyTypeKind(AnyTypeKind.ANY_OBJECT).build());
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+ try {
+ taskService.list(new TaskQuery.Builder(TaskType.PULL).
+ notification("e00945b5-1184-4d43-8e45-4318a8dcdfd4").build());
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+
+ try {
+ anyTypeService.delete(AnyTypeKind.USER.name());
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidRequest, e.getType());
+ }
+
+ try {
+ clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(AccessTokenService.class).login();
+ fail();
+ } 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();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidMapping, e.getType());
+ }
+ }
}