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 2020/04/10 05:10:51 UTC

[syncope] branch 2_1_X updated: Avoiding unneeded AnyTypeClass check

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch 2_1_X
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/2_1_X by this push:
     new 7f11b12  Avoiding unneeded AnyTypeClass check
7f11b12 is described below

commit 7f11b12386da0d2c0c89d35dae334e3153865364
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Fri Apr 10 07:10:30 2020 +0200

    Avoiding unneeded AnyTypeClass check
---
 .../java/data/OIDCProviderDataBinderImpl.java      | 111 +++++++--------------
 .../java/data/SAML2IdPDataBinderImpl.java          | 108 ++++++--------------
 2 files changed, 67 insertions(+), 152 deletions(-)

diff --git a/ext/oidcclient/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCProviderDataBinderImpl.java b/ext/oidcclient/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCProviderDataBinderImpl.java
index dcfb1a5..202f0b9 100644
--- a/ext/oidcclient/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCProviderDataBinderImpl.java
+++ b/ext/oidcclient/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCProviderDataBinderImpl.java
@@ -19,10 +19,8 @@
 package org.apache.syncope.core.provisioning.java.data;
 
 import java.text.ParseException;
-import java.util.stream.Collectors;
 import org.apache.syncope.common.lib.SyncopeClientCompositeException;
 import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AnyTypeClassTO;
 import org.apache.syncope.common.lib.to.ItemTO;
 import org.apache.syncope.common.lib.to.OIDCProviderTO;
 import org.apache.syncope.common.lib.to.UserTO;
@@ -32,7 +30,6 @@ import org.apache.syncope.common.lib.types.MappingPurpose;
 import org.apache.syncope.common.lib.types.SchemaType;
 import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
 import org.apache.syncope.core.persistence.api.dao.OIDCProviderDAO;
-import org.apache.syncope.core.persistence.api.entity.Entity;
 import org.apache.syncope.core.persistence.api.entity.OIDCEntityFactory;
 import org.apache.syncope.core.persistence.api.entity.OIDCProvider;
 import org.apache.syncope.core.persistence.api.entity.OIDCProviderItem;
@@ -66,21 +63,16 @@ public class OIDCProviderDataBinderImpl implements OIDCProviderDataBinder {
     @Override
     public OIDCProvider create(final OIDCProviderTO opTO) {
         return update(entityFactory.newEntity(OIDCProvider.class), opTO);
-
     }
 
-    private void populateItems(
-            final OIDCProviderTO opTO,
-            final OIDCProvider op,
-            final AnyTypeClassTO allowedSchemas) {
-
+    private void populateItems(final OIDCProviderTO opTO, final OIDCProvider op) {
         SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
         SyncopeClientException invalidMapping =
                 SyncopeClientException.build(ClientExceptionType.InvalidMapping);
         SyncopeClientException requiredValuesMissing =
                 SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
 
-        for (ItemTO itemTO : opTO.getItems()) {
+        opTO.getItems().forEach(itemTO -> {
             if (itemTO == null) {
                 LOG.error("Null {}", ItemTO.class.getSimpleName());
                 invalidMapping.getElements().add("Null " + ItemTO.class.getSimpleName());
@@ -97,71 +89,45 @@ public class OIDCProviderDataBinderImpl implements OIDCProviderDataBinder {
 
                 if (intAttrName == null || intAttrName.getSchemaType() == null && intAttrName.getField() == null) {
                     LOG.error("'{}' not existing", itemTO.getIntAttrName());
-                    invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not existing");
+                    invalidMapping.getElements().add('\'' + itemTO.getIntAttrName() + "' not existing");
                 } else {
-                    boolean allowed = true;
-                    if (intAttrName.getSchemaType() != null
-                            && intAttrName.getEnclosingGroup() == null
-                            && intAttrName.getRelatedAnyObject() == null) {
-                        switch (intAttrName.getSchemaType()) {
-                            case PLAIN:
-                                allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchema().getKey());
-                                break;
-
-                            case DERIVED:
-                                allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchema().getKey());
-                                break;
-
-                            case VIRTUAL:
-                                allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchema().getKey());
-                                break;
-
-                            default:
-                        }
+                    // no mandatory condition implies mandatory condition false
+                    if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null
+                            ? "false" : itemTO.getMandatoryCondition())) {
+
+                        SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(
+                                ClientExceptionType.InvalidValues);
+                        invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
+                        scce.addException(invalidMandatoryCondition);
                     }
 
-                    if (allowed) {
-                        // no mandatory condition implies mandatory condition false
-                        if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null
-                                ? "false" : itemTO.getMandatoryCondition())) {
-
-                            SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(
-                                    ClientExceptionType.InvalidValues);
-                            invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
-                            scce.addException(invalidMandatoryCondition);
+                    OIDCProviderItem item = entityFactory.newEntity(OIDCProviderItem.class);
+                    item.setIntAttrName(itemTO.getIntAttrName());
+                    item.setExtAttrName(itemTO.getExtAttrName());
+                    item.setMandatoryCondition(itemTO.getMandatoryCondition());
+                    item.setConnObjectKey(itemTO.isConnObjectKey());
+                    item.setPassword(itemTO.isPassword());
+                    item.setPropagationJEXLTransformer(itemTO.getPropagationJEXLTransformer());
+                    item.setPullJEXLTransformer(itemTO.getPullJEXLTransformer());
+                    item.setOP(op);
+                    item.setPurpose(MappingPurpose.NONE);
+                    if (item.isConnObjectKey()) {
+                        if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
+                            invalidMapping.getElements().
+                                    add("Virtual attributes cannot be set as ConnObjectKey");
                         }
-
-                        OIDCProviderItem item = entityFactory.newEntity(OIDCProviderItem.class);
-                        item.setIntAttrName(itemTO.getIntAttrName());
-                        item.setExtAttrName(itemTO.getExtAttrName());
-                        item.setMandatoryCondition(itemTO.getMandatoryCondition());
-                        item.setConnObjectKey(itemTO.isConnObjectKey());
-                        item.setPassword(itemTO.isPassword());
-                        item.setPropagationJEXLTransformer(itemTO.getPropagationJEXLTransformer());
-                        item.setPullJEXLTransformer(itemTO.getPullJEXLTransformer());
-                        item.setOP(op);
-                        item.setPurpose(MappingPurpose.NONE);
-                        if (item.isConnObjectKey()) {
-                            if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
-                                invalidMapping.getElements().
-                                        add("Virtual attributes cannot be set as ConnObjectKey");
-                            }
-                            if ("password".equals(intAttrName.getField())) {
-                                invalidMapping.getElements().add(
-                                        "Password attributes cannot be set as ConnObjectKey");
-                            }
-
-                            op.setConnObjectKeyItem(item);
-                        } else {
-                            op.add(item);
+                        if ("password".equals(intAttrName.getField())) {
+                            invalidMapping.getElements().add(
+                                    "Password attributes cannot be set as ConnObjectKey");
                         }
+
+                        op.setConnObjectKeyItem(item);
                     } else {
-                        LOG.error("'{}' not allowed", itemTO.getIntAttrName());
-                        invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not allowed");
+                        op.add(item);
                     }
                 }
             }
-        }
+        });
 
         if (!invalidMapping.getElements().isEmpty()) {
             scce.addException(invalidMapping);
@@ -201,16 +167,7 @@ public class OIDCProviderDataBinderImpl implements OIDCProviderDataBinder {
         }
 
         op.getItems().clear();
-        AnyTypeClassTO allowedSchemas = new AnyTypeClassTO();
-        anyTypeDAO.findUser().getClasses().forEach(anyTypeClass -> {
-            allowedSchemas.getPlainSchemas().addAll(anyTypeClass.getPlainSchemas().stream().
-                    map(Entity::getKey).collect(Collectors.toList()));
-            allowedSchemas.getDerSchemas().addAll(anyTypeClass.getDerSchemas().stream().
-                    map(Entity::getKey).collect(Collectors.toList()));
-            allowedSchemas.getVirSchemas().addAll(anyTypeClass.getVirSchemas().stream().
-                    map(Entity::getKey).collect(Collectors.toList()));
-        });
-        populateItems(opTO, op, allowedSchemas);
+        populateItems(opTO, op);
 
         op.getActionsClassNames().clear();
         op.getActionsClassNames().addAll(opTO.getActionsClassNames());
@@ -218,7 +175,7 @@ public class OIDCProviderDataBinderImpl implements OIDCProviderDataBinder {
         return oidcOPDAO.save(op);
     }
 
-    private void populateItems(final OIDCProvider op, final OIDCProviderTO opTO) {
+    private static void populateItems(final OIDCProvider op, final OIDCProviderTO opTO) {
         op.getItems().forEach(item -> {
             ItemTO itemTO = new ItemTO();
             itemTO.setKey(item.getKey());
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 0b7c261..87b38c2 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,10 +20,8 @@ package org.apache.syncope.core.provisioning.java.data;
 
 import java.text.ParseException;
 import java.util.Base64;
-import java.util.stream.Collectors;
 import org.apache.syncope.common.lib.SyncopeClientCompositeException;
 import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AnyTypeClassTO;
 import org.apache.syncope.common.lib.to.ItemTO;
 import org.apache.syncope.common.lib.to.SAML2IdPTO;
 import org.apache.syncope.common.lib.to.UserTO;
@@ -33,7 +31,6 @@ import org.apache.syncope.common.lib.types.MappingPurpose;
 import org.apache.syncope.common.lib.types.SchemaType;
 import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
 import org.apache.syncope.core.persistence.api.dao.SAML2IdPDAO;
-import org.apache.syncope.core.persistence.api.entity.Entity;
 import org.apache.syncope.core.persistence.api.entity.SAML2EntityFactory;
 import org.apache.syncope.core.persistence.api.entity.SAML2IdP;
 import org.apache.syncope.core.persistence.api.entity.SAML2IdPItem;
@@ -69,18 +66,14 @@ public class SAML2IdPDataBinderImpl implements SAML2IdPDataBinder {
         return update(entityFactory.newEntity(SAML2IdP.class), idpTO);
     }
 
-    private void populateItems(
-            final SAML2IdPTO idpTO,
-            final SAML2IdP idp,
-            final AnyTypeClassTO allowedSchemas) {
-
+    private void populateItems(final SAML2IdPTO idpTO, final SAML2IdP idp) {
         SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
         SyncopeClientException invalidMapping =
                 SyncopeClientException.build(ClientExceptionType.InvalidMapping);
         SyncopeClientException requiredValuesMissing =
                 SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
 
-        for (ItemTO itemTO : idpTO.getItems()) {
+        idpTO.getItems().forEach(itemTO -> {
             if (itemTO == null) {
                 LOG.error("Null {}", ItemTO.class.getSimpleName());
                 invalidMapping.getElements().add("Null " + ItemTO.class.getSimpleName());
@@ -99,69 +92,43 @@ public class SAML2IdPDataBinderImpl implements SAML2IdPDataBinder {
                     LOG.error("'{}' not existing", itemTO.getIntAttrName());
                     invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not existing");
                 } else {
-                    boolean allowed = true;
-                    if (intAttrName.getSchemaType() != null
-                            && intAttrName.getEnclosingGroup() == null
-                            && intAttrName.getRelatedAnyObject() == null) {
-                        switch (intAttrName.getSchemaType()) {
-                            case PLAIN:
-                                allowed = allowedSchemas.getPlainSchemas().contains(intAttrName.getSchema().getKey());
-                                break;
-
-                            case DERIVED:
-                                allowed = allowedSchemas.getDerSchemas().contains(intAttrName.getSchema().getKey());
-                                break;
-
-                            case VIRTUAL:
-                                allowed = allowedSchemas.getVirSchemas().contains(intAttrName.getSchema().getKey());
-                                break;
-
-                            default:
-                        }
+                    // no mandatory condition implies mandatory condition false
+                    if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null
+                            ? "false" : itemTO.getMandatoryCondition())) {
+
+                        SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(
+                                ClientExceptionType.InvalidValues);
+                        invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
+                        scce.addException(invalidMandatoryCondition);
                     }
 
-                    if (allowed) {
-                        // no mandatory condition implies mandatory condition false
-                        if (!JexlUtils.isExpressionValid(itemTO.getMandatoryCondition() == null
-                                ? "false" : itemTO.getMandatoryCondition())) {
-
-                            SyncopeClientException invalidMandatoryCondition = SyncopeClientException.build(
-                                    ClientExceptionType.InvalidValues);
-                            invalidMandatoryCondition.getElements().add(itemTO.getMandatoryCondition());
-                            scce.addException(invalidMandatoryCondition);
+                    SAML2IdPItem item = entityFactory.newEntity(SAML2IdPItem.class);
+                    item.setIntAttrName(itemTO.getIntAttrName());
+                    item.setExtAttrName(itemTO.getExtAttrName());
+                    item.setMandatoryCondition(itemTO.getMandatoryCondition());
+                    item.setConnObjectKey(itemTO.isConnObjectKey());
+                    item.setPassword(itemTO.isPassword());
+                    item.setPropagationJEXLTransformer(itemTO.getPropagationJEXLTransformer());
+                    item.setPullJEXLTransformer(itemTO.getPullJEXLTransformer());
+                    item.setIdP(idp);
+                    item.setPurpose(MappingPurpose.NONE);
+                    if (item.isConnObjectKey()) {
+                        if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
+                            invalidMapping.getElements().
+                                    add("Virtual attributes cannot be set as ConnObjectKey");
                         }
-
-                        SAML2IdPItem item = entityFactory.newEntity(SAML2IdPItem.class);
-                        item.setIntAttrName(itemTO.getIntAttrName());
-                        item.setExtAttrName(itemTO.getExtAttrName());
-                        item.setMandatoryCondition(itemTO.getMandatoryCondition());
-                        item.setConnObjectKey(itemTO.isConnObjectKey());
-                        item.setPassword(itemTO.isPassword());
-                        item.setPropagationJEXLTransformer(itemTO.getPropagationJEXLTransformer());
-                        item.setPullJEXLTransformer(itemTO.getPullJEXLTransformer());
-                        item.setIdP(idp);
-                        item.setPurpose(MappingPurpose.NONE);
-                        if (item.isConnObjectKey()) {
-                            if (intAttrName.getSchemaType() == SchemaType.VIRTUAL) {
-                                invalidMapping.getElements().
-                                        add("Virtual attributes cannot be set as ConnObjectKey");
-                            }
-                            if ("password".equals(intAttrName.getField())) {
-                                invalidMapping.getElements().add(
-                                        "Password attributes cannot be set as ConnObjectKey");
-                            }
-
-                            idp.setConnObjectKeyItem(item);
-                        } else {
-                            idp.add(item);
+                        if ("password".equals(intAttrName.getField())) {
+                            invalidMapping.getElements().add(
+                                    "Password attributes cannot be set as ConnObjectKey");
                         }
+
+                        idp.setConnObjectKeyItem(item);
                     } else {
-                        LOG.error("'{}' not allowed", itemTO.getIntAttrName());
-                        invalidMapping.getElements().add("'" + itemTO.getIntAttrName() + "' not allowed");
+                        idp.add(item);
                     }
                 }
             }
-        }
+        });
 
         if (!invalidMapping.getElements().isEmpty()) {
             scce.addException(invalidMapping);
@@ -197,16 +164,7 @@ public class SAML2IdPDataBinderImpl implements SAML2IdPDataBinder {
         }
 
         idp.getItems().clear();
-        AnyTypeClassTO allowedSchemas = new AnyTypeClassTO();
-        anyTypeDAO.findUser().getClasses().forEach(anyTypeClass -> {
-            allowedSchemas.getPlainSchemas().addAll(anyTypeClass.getPlainSchemas().stream().
-                    map(Entity::getKey).collect(Collectors.toList()));
-            allowedSchemas.getDerSchemas().addAll(anyTypeClass.getDerSchemas().stream().
-                    map(Entity::getKey).collect(Collectors.toList()));
-            allowedSchemas.getVirSchemas().addAll(anyTypeClass.getVirSchemas().stream().
-                    map(Entity::getKey).collect(Collectors.toList()));
-        });
-        populateItems(idpTO, idp, allowedSchemas);
+        populateItems(idpTO, idp);
 
         idp.getActionsClassNames().clear();
         idp.getActionsClassNames().addAll(idpTO.getActionsClassNames());
@@ -216,7 +174,7 @@ public class SAML2IdPDataBinderImpl implements SAML2IdPDataBinder {
         return saml2IdPDAO.save(idp);
     }
 
-    private void populateItems(final SAML2IdP idp, final SAML2IdPTO idpTO) {
+    private static void populateItems(final SAML2IdP idp, final SAML2IdPTO idpTO) {
         idp.getItems().forEach(item -> {
             ItemTO itemTO = new ItemTO();
             itemTO.setKey(item.getKey());