You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by mm...@apache.org on 2020/02/27 08:17:33 UTC

[syncope] 04/12: resume on auth modules; clean up to base essentials

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

mmoayyed pushed a commit to branch SYNCOPE-163-1
in repository https://gitbox.apache.org/repos/asf/syncope.git

commit 3a2bce298cc52099d91145f1d86e1eaa1bba9016
Author: Misagh Moayyed <mm...@gmail.com>
AuthorDate: Mon Feb 24 13:42:09 2020 +0330

    resume on auth modules; clean up to base essentials
---
 .../authentication/JPAClientApplicationDAO.java    | 69 ----------------------
 .../JPAOpenIdConnectRelyingPartyDAO.java           | 11 ++--
 .../jpa/inner/OpenIdConnectRelyingPartyTest.java   | 63 ++++++++++++++++++++
 .../jpa/inner/SAML2ServiceProviderTest.java        | 64 ++++++++++++++++++++
 4 files changed, 134 insertions(+), 73 deletions(-)

diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAClientApplicationDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAClientApplicationDAO.java
deleted file mode 100644
index 7e8d1ce..0000000
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAClientApplicationDAO.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.persistence.jpa.dao.authentication;
-
-import org.apache.syncope.core.persistence.api.dao.authentication.AuthenticationPolicyDAO;
-import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
-import org.apache.syncope.core.persistence.jpa.dao.AbstractDAO;
-import org.apache.syncope.core.persistence.jpa.entity.policy.JPAAuthenticationPolicy;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.persistence.TypedQuery;
-
-import java.util.List;
-
-@Repository
-public class JPAClientApplicationDAO extends AbstractDAO<AuthenticationPolicy> implements AuthenticationPolicyDAO {
-
-    @Override
-    public AuthenticationPolicy find(final String key) {
-        return entityManager().find(JPAAuthenticationPolicy.class, key);
-    }
-
-    @Transactional(readOnly = true)
-    @Override
-    public List<AuthenticationPolicy> findAll() {
-        TypedQuery<AuthenticationPolicy> query = entityManager().createQuery(
-            "SELECT e FROM " + JPAAuthenticationPolicy.class.getSimpleName() + " e", AuthenticationPolicy.class);
-
-        return query.getResultList();
-    }
-
-    @Override
-    public AuthenticationPolicy save(final AuthenticationPolicy policy) {
-        return entityManager().merge(policy);
-    }
-
-    @Override
-    public void delete(final String key) {
-        AuthenticationPolicy policy = find(key);
-        if (policy == null) {
-            return;
-        }
-
-        delete(policy);
-    }
-
-    @Override
-    public void delete(final AuthenticationPolicy policy) {
-        entityManager().remove(policy);
-    }
-
-}
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAOpenIdConnectRelyingPartyDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAOpenIdConnectRelyingPartyDAO.java
index b6b3355..17a9ad7 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAOpenIdConnectRelyingPartyDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAOpenIdConnectRelyingPartyDAO.java
@@ -43,7 +43,8 @@ public class JPAOpenIdConnectRelyingPartyDAO extends AbstractDAO<OpenIdConnectRe
     @Override
     public OpenIdConnectRelyingParty findByName(final String name) {
         TypedQuery<OpenIdConnectRelyingParty> query = entityManager().createQuery(
-            "SELECT e FROM " + JPAOpenIdConnectRelyingParty.class.getSimpleName() + " e WHERE e.name=:name", OpenIdConnectRelyingParty.class);
+            "SELECT e FROM " + JPAOpenIdConnectRelyingParty.class.getSimpleName()
+                + " e WHERE e.name=:name", OpenIdConnectRelyingParty.class);
         query.setParameter("name", name);
 
         OpenIdConnectRelyingParty result = null;
@@ -59,8 +60,9 @@ public class JPAOpenIdConnectRelyingPartyDAO extends AbstractDAO<OpenIdConnectRe
     @Override
     public OpenIdConnectRelyingParty findByClientId(final String clientId) {
         TypedQuery<OpenIdConnectRelyingParty> query = entityManager().createQuery(
-            "SELECT e FROM " + JPAOpenIdConnectRelyingParty.class.getSimpleName() + " e WHERE e.clientId=:clientId", OpenIdConnectRelyingParty.class);
-        query.setParameter(clientId, clientId);
+            "SELECT e FROM " + JPAOpenIdConnectRelyingParty.class.getSimpleName()
+                + " e WHERE e.clientId=:clientId", OpenIdConnectRelyingParty.class);
+        query.setParameter("clientId", clientId);
 
         OpenIdConnectRelyingParty result = null;
         try {
@@ -76,7 +78,8 @@ public class JPAOpenIdConnectRelyingPartyDAO extends AbstractDAO<OpenIdConnectRe
     @Override
     public List<OpenIdConnectRelyingParty> findAll() {
         TypedQuery<OpenIdConnectRelyingParty> query = entityManager().createQuery(
-            "SELECT e FROM " + JPAOpenIdConnectRelyingParty.class.getSimpleName() + " e", OpenIdConnectRelyingParty.class);
+            "SELECT e FROM " + JPAOpenIdConnectRelyingParty.class.getSimpleName()
+                + " e", OpenIdConnectRelyingParty.class);
 
         return query.getResultList();
     }
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/OpenIdConnectRelyingPartyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/OpenIdConnectRelyingPartyTest.java
new file mode 100644
index 0000000..d671e0b
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/OpenIdConnectRelyingPartyTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.persistence.jpa.inner;
+
+import org.apache.syncope.core.persistence.api.dao.authentication.OpenIdConnectRelyingPartyDAO;
+import org.apache.syncope.core.persistence.api.entity.authentication.OpenIdConnectRelyingParty;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@Transactional("Master")
+public class OpenIdConnectRelyingPartyTest extends AbstractTest {
+
+    @Autowired
+    private OpenIdConnectRelyingPartyDAO openIdConnectRelyingPartyDAO;
+
+    @Test
+    public void find() {
+        int beforeCount = openIdConnectRelyingPartyDAO.findAll().size();
+        OpenIdConnectRelyingParty rp = entityFactory.newEntity(OpenIdConnectRelyingParty.class);
+        rp.setName("OIDC");
+        rp.setDescription("This is a sample OIDC RP");
+        rp.setClientId("clientid");
+        rp.setClientSecret("secret");
+        openIdConnectRelyingPartyDAO.save(rp);
+
+        assertNotNull(rp);
+        assertNotNull(rp.getKey());
+
+        int afterCount = openIdConnectRelyingPartyDAO.findAll().size();
+        assertEquals(afterCount, beforeCount + 1);
+
+        rp = openIdConnectRelyingPartyDAO.findByClientId("clientid");
+        assertNotNull(rp);
+
+        rp = openIdConnectRelyingPartyDAO.findByName("OIDC");
+        assertNotNull(rp);
+
+        openIdConnectRelyingPartyDAO.deleteByClientId("clientid");
+        assertNull(openIdConnectRelyingPartyDAO.findByName("OIDC"));
+    }
+
+}
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/SAML2ServiceProviderTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/SAML2ServiceProviderTest.java
new file mode 100644
index 0000000..4eb988e
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/SAML2ServiceProviderTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.persistence.jpa.inner;
+
+import org.apache.syncope.core.persistence.api.dao.authentication.SAML2ServiceProviderDAO;
+import org.apache.syncope.core.persistence.api.entity.authentication.OpenIdConnectRelyingParty;
+import org.apache.syncope.core.persistence.api.entity.authentication.SAML2ServiceProvider;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+@Transactional("Master")
+public class SAML2ServiceProviderTest extends AbstractTest {
+
+    @Autowired
+    private SAML2ServiceProviderDAO saml2ServiceProviderDAO;
+
+    @Test
+    public void find() {
+        int beforeCount = saml2ServiceProviderDAO.findAll().size();
+        SAML2ServiceProvider rp = entityFactory.newEntity(SAML2ServiceProvider.class);
+        rp.setName("OIDC");
+        rp.setDescription("This is a sample OIDC RP");
+        rp.setEntityId("urn:example:saml2:sp");
+        rp.setMetadataLocation("https://example.org/metadata.xml");
+        saml2ServiceProviderDAO.save(rp);
+
+        assertNotNull(rp);
+        assertNotNull(rp.getKey());
+
+        int afterCount = saml2ServiceProviderDAO.findAll().size();
+        assertEquals(afterCount, beforeCount + 1);
+
+        rp = saml2ServiceProviderDAO.findByEntityId(rp.getEntityId());
+        assertNotNull(rp);
+
+        rp = saml2ServiceProviderDAO.findByName("OIDC");
+        assertNotNull(rp);
+
+        saml2ServiceProviderDAO.deleteByEntityId(rp.getEntityId());
+        assertNull(saml2ServiceProviderDAO.findByName("OIDC"));
+    }
+
+}