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/01/09 11:52:50 UTC

[syncope] branch master updated (62507c5 -> b30a93b)

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

ilgrosso pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git.


    from 62507c5  Back to Wicket 8.6.1
     new 77f0944  Unit Test for DBPasswordPullActions (#156)
     new b30a93b  Small cleanup

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../client/console/rest/ResourceRestClient.java    |  4 +-
 .../init/ClassPathScanImplementationLookup.java    | 22 ++----
 .../client/console/panels/ConsoleLogPanel.java     |  4 +-
 .../client/console/rest/LoggerRestClient.java      |  4 +-
 ...onsTest.java => DBPasswordPullActionsTest.java} | 88 +++++++++++++---------
 5 files changed, 64 insertions(+), 58 deletions(-)
 copy core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/{LDAPPasswordPullActionsTest.java => DBPasswordPullActionsTest.java} (53%)


[syncope] 02/02: Small cleanup

Posted by il...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b30a93bda0935962469a3f30b9ad93f301e5073a
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Thu Jan 9 12:51:54 2020 +0100

    Small cleanup
---
 .../client/console/rest/ResourceRestClient.java    |  4 ++--
 .../init/ClassPathScanImplementationLookup.java    | 22 ++++++----------------
 .../client/console/panels/ConsoleLogPanel.java     |  4 ++--
 .../client/console/rest/LoggerRestClient.java      |  4 ++--
 4 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java
index 92f79f3..62adc54 100644
--- a/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java
+++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/rest/ResourceRestClient.java
@@ -19,9 +19,9 @@
 package org.apache.syncope.client.console.rest;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import javax.ws.rs.core.Response;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.ConnObjectTO;
 import org.apache.syncope.common.lib.to.PagedConnObjectTOResult;
@@ -87,7 +87,7 @@ public class ResourceRestClient extends BaseRestClient {
         List<ResourceTO> resources = List.of();
         try {
             resources = getService(ResourceService.class).list();
-            resources.sort((o1, o2) -> ObjectUtils.compare(o1.getKey(), o2.getKey()));
+            resources.sort(Comparator.comparing(ResourceTO::getKey));
         } catch (Exception e) {
             LOG.error("Could not fetch the Resource list", e);
         }
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java
index e980fce..3064747 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/init/ClassPathScanImplementationLookup.java
@@ -23,6 +23,7 @@ import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -30,7 +31,6 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.syncope.client.console.annotations.AMPage;
 import org.apache.syncope.client.console.annotations.ExtPage;
 import org.apache.syncope.client.console.pages.BaseExtPage;
@@ -238,29 +238,19 @@ public class ClassPathScanImplementationLookup {
         pages = Collections.unmodifiableList(pages);
         previewers = Collections.unmodifiableList(previewers);
 
-        idmPages.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(IdMPage.class).priority(),
-                o2.getAnnotation(IdMPage.class).priority()));
+        idmPages.sort(Comparator.comparing(o -> o.getAnnotation(IdMPage.class).priority()));
         idmPages = Collections.unmodifiableList(idmPages);
 
-        amPages.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(IdMPage.class).priority(),
-                o2.getAnnotation(IdMPage.class).priority()));
+        amPages.sort(Comparator.comparing(o -> o.getAnnotation(IdMPage.class).priority()));
         amPages = Collections.unmodifiableList(amPages);
 
-        extPages.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(ExtPage.class).priority(),
-                o2.getAnnotation(ExtPage.class).priority()));
+        extPages.sort(Comparator.comparing(o -> o.getAnnotation(ExtPage.class).priority()));
         extPages = Collections.unmodifiableList(extPages);
 
-        extWidgets.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(ExtWidget.class).priority(),
-                o2.getAnnotation(ExtWidget.class).priority()));
+        extWidgets.sort(Comparator.comparing(o -> o.getAnnotation(ExtWidget.class).priority()));
         extWidgets = Collections.unmodifiableList(extWidgets);
 
-        extAlertWidgets.sort((o1, o2) -> ObjectUtils.compare(
-                o1.getAnnotation(ExtWidget.class).priority(),
-                o2.getAnnotation(ExtWidget.class).priority()));
+        extAlertWidgets.sort(Comparator.comparing(o -> o.getAnnotation(ExtWidget.class).priority()));
         extAlertWidgets = Collections.unmodifiableList(extAlertWidgets);
 
         ssoLoginFormPanels = Collections.unmodifiableList(ssoLoginFormPanels);
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java
index 1c5c703..b0f7f68 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/panels/ConsoleLogPanel.java
@@ -20,8 +20,8 @@ package org.apache.syncope.client.console.panels;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.LoggerConfig;
@@ -61,7 +61,7 @@ public class ConsoleLogPanel extends AbstractLogsPanel<LoggerTO> {
                     result.add(loggerTO);
                 }
             });
-            result.sort((o1, o2) -> ObjectUtils.compare(o1.getKey(), o2.getKey()));
+            result.sort(Comparator.comparing(LoggerTO::getKey));
 
             return result;
         }
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
index ff4bef0..c283c02 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/rest/LoggerRestClient.java
@@ -19,13 +19,13 @@
 package org.apache.syncope.client.console.rest;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.stream.Collectors;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.syncope.common.lib.log.EventCategory;
 import org.apache.syncope.common.lib.log.LogAppender;
 import org.apache.syncope.common.lib.log.LogStatement;
@@ -56,7 +56,7 @@ public class LoggerRestClient extends BaseRestClient {
 
     public static List<LoggerTO> listLogs() {
         List<LoggerTO> logs = getService(LoggerService.class).list(LoggerType.LOG);
-        logs.sort((o1, o2) -> ObjectUtils.compare(o1.getKey(), o2.getKey()));
+        logs.sort(Comparator.comparing(LoggerTO::getKey));
 
         return logs;
     }


[syncope] 01/02: Unit Test for DBPasswordPullActions (#156)

Posted by il...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 77f09445c5ec791aa0ef2639364d0bd26cf39ebc
Author: Davide Cortellucci <da...@gmail.com>
AuthorDate: Thu Jan 9 11:48:01 2020 +0100

    Unit Test for DBPasswordPullActions (#156)
---
 .../java/pushpull/DBPasswordPullActionsTest.java   | 147 +++++++++++++++++++++
 1 file changed, 147 insertions(+)

diff --git a/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/DBPasswordPullActionsTest.java b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/DBPasswordPullActionsTest.java
new file mode 100644
index 0000000..01f7a55
--- /dev/null
+++ b/core/provisioning-java/src/test/java/org/apache/syncope/core/provisioning/java/pushpull/DBPasswordPullActionsTest.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.provisioning.java.pushpull;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.request.PasswordPatch;
+import org.apache.syncope.common.lib.request.UserCR;
+import org.apache.syncope.common.lib.request.UserUR;
+import org.apache.syncope.common.lib.to.ProvisioningReport;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.CipherAlgorithm;
+import org.apache.syncope.common.lib.types.ConnConfPropSchema;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.ConnInstance;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.provisioning.api.Connector;
+import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile;
+import org.apache.syncope.core.provisioning.java.AbstractTest;
+import org.identityconnectors.framework.common.objects.SyncDelta;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.quartz.JobExecutionException;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class DBPasswordPullActionsTest extends AbstractTest {
+
+    @Mock
+    private SyncDelta syncDelta;
+
+    @Mock
+    private ProvisioningProfile<?, ?> profile;
+
+    @Mock
+    private UserDAO userDAO;
+
+    @Mock
+    private ProvisioningReport result;
+
+    @Mock
+    private Connector connector;
+
+    @InjectMocks
+    private DBPasswordPullActions dBPasswordPullActions;
+
+    @Mock
+    private ConnInstance connInstance;
+
+    private Set<ConnConfProperty> connConfProperties;
+
+    private UserTO userTO;
+
+    private UserCR userCR;
+
+    private UserUR userUR;
+
+    private String encodedPassword;
+
+    private CipherAlgorithm cipher;
+
+    private ConnConfProperty connConfProperty;
+
+    @BeforeEach
+    public void initTest() {
+        userTO = new UserTO();
+        encodedPassword = "s3cureP4ssw0rd";
+        cipher = CipherAlgorithm.SHA512;
+        ConnConfPropSchema connConfPropSchema = new ConnConfPropSchema();
+        connConfPropSchema.setName("cipherAlgorithm");
+        connConfProperty = new ConnConfProperty();
+        connConfProperty.setSchema(connConfPropSchema);
+        connConfProperties = new HashSet<>();
+        connConfProperties.add(connConfProperty);
+
+        ReflectionTestUtils.setField(dBPasswordPullActions, "encodedPassword", encodedPassword);
+        ReflectionTestUtils.setField(dBPasswordPullActions, "cipher", cipher);
+
+        lenient().when(profile.getConnector()).thenReturn(connector);
+        lenient().when(connector.getConnInstance()).thenReturn(connInstance);
+        lenient().when(connInstance.getConf()).thenReturn(connConfProperties);
+    }
+
+    @Test
+    public void beforeProvision() throws JobExecutionException {
+        String digest = "SHA256";
+        String password = "t3stPassw0rd";
+        userCR = new UserCR.Builder(SyncopeConstants.ROOT_REALM, "user").password(password).build();
+        connConfProperty.getValues().clear();
+        connConfProperty.getValues().add(digest);
+
+        dBPasswordPullActions.beforeProvision(profile, syncDelta, userCR);
+
+        assertEquals(CipherAlgorithm.valueOf(digest), ReflectionTestUtils.getField(dBPasswordPullActions, "cipher"));
+        assertEquals(password, ReflectionTestUtils.getField(dBPasswordPullActions, "encodedPassword"));
+    }
+
+    @Test
+    public void beforeUpdate() throws JobExecutionException {
+        userUR = new UserUR.Builder(null).
+                password(new PasswordPatch.Builder().value("an0therTestP4ss").build()).
+                build();
+
+        dBPasswordPullActions.beforeUpdate(profile, syncDelta, userTO, userUR);
+
+        assertEquals(cipher, ReflectionTestUtils.getField(dBPasswordPullActions, "cipher"));
+        assertEquals(encodedPassword, ReflectionTestUtils.getField(dBPasswordPullActions, "encodedPassword"));
+    }
+
+    @Test
+    public void after(@Mock User user) throws JobExecutionException {
+        when(userDAO.find(user.getKey())).thenReturn(user);
+
+        dBPasswordPullActions.after(profile, syncDelta, userTO, result);
+
+        verify(user).setEncodedPassword(anyString(), any(CipherAlgorithm.class));
+        assertNull(ReflectionTestUtils.getField(dBPasswordPullActions, "encodedPassword"));
+        assertNull(ReflectionTestUtils.getField(dBPasswordPullActions, "cipher"));
+    }
+}