You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by di...@apache.org on 2020/03/10 16:33:29 UTC
[syncope] branch SYNCOPE-163-1 updated: [SYNCOPE-163] remove AM
policies DAOs
This is an automated email from the ASF dual-hosted git repository.
dimaayash pushed a commit to branch SYNCOPE-163-1
in repository https://gitbox.apache.org/repos/asf/syncope.git
The following commit(s) were added to refs/heads/SYNCOPE-163-1 by this push:
new fff90a3 [SYNCOPE-163] remove AM policies DAOs
fff90a3 is described below
commit fff90a3d394eec604e24c7e5f20717d52c4f1967
Author: dima.ayash <di...@tirasa.net>
AuthorDate: Tue Mar 10 17:32:42 2020 +0100
[SYNCOPE-163] remove AM policies DAOs
---
.../syncope/common/lib/to/client/ClientAppTO.java | 62 ++++----
.../api/dao/authentication/AccessPolicyDAO.java | 38 -----
.../dao/authentication/AttrReleasePolicyDAO.java | 38 -----
.../authentication/AuthenticationPolicyDAO.java | 38 -----
.../core/persistence/jpa/dao/JPAPolicyDAO.java | 4 +-
.../jpa/dao/authentication/JPAAccessPolicyDAO.java | 69 ---------
.../authentication/JPAAttrReleasePolicyDAO.java | 69 ---------
.../authentication/JPAAuthenticationPolicyDAO.java | 67 ---------
.../jpa/inner/AbstractClientAppTest.java | 17 +--
.../persistence/jpa/inner/AccessPolicyTest.java | 107 --------------
.../jpa/inner/AttrReleasePolicyTest.java | 103 --------------
.../jpa/inner/AuthenticationPolicyTest.java | 103 --------------
.../core/persistence/jpa/inner/PolicyTest.java | 158 ++++++++++++++++++---
.../java/data/OIDCRelyingPartyDataBinderImpl.java | 70 ++++++---
.../data/SAML2ServiceProviderDataBinderImpl.java | 77 ++++++----
.../syncope/fit/core/OIDCRelyingPartyITCase.java | 7 +-
.../fit/core/SAML2ServiceProviderITCase.java | 7 +-
17 files changed, 279 insertions(+), 755 deletions(-)
diff --git a/common/am/lib/src/main/java/org/apache/syncope/common/lib/to/client/ClientAppTO.java b/common/am/lib/src/main/java/org/apache/syncope/common/lib/to/client/ClientAppTO.java
index 0dc8052..97164e7 100644
--- a/common/am/lib/src/main/java/org/apache/syncope/common/lib/to/client/ClientAppTO.java
+++ b/common/am/lib/src/main/java/org/apache/syncope/common/lib/to/client/ClientAppTO.java
@@ -16,7 +16,6 @@
* under the License.
*
*/
-
package org.apache.syncope.common.lib.to.client;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
@@ -25,9 +24,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.syncope.common.lib.BaseBean;
-import org.apache.syncope.common.lib.to.AccessPolicyTO;
-import org.apache.syncope.common.lib.to.AttrReleasePolicyTO;
-import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
import org.apache.syncope.common.lib.to.EntityTO;
import javax.xml.bind.annotation.XmlRootElement;
@@ -36,11 +32,11 @@ import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "clientApp")
@XmlType
-@XmlSeeAlso({OIDCRelyingPartyTO.class, SAML2ServiceProviderTO.class})
+@XmlSeeAlso({ OIDCRelyingPartyTO.class, SAML2ServiceProviderTO.class })
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "@class")
-@JsonPropertyOrder(value = {"@class", "key", "name", "description",
- "authenticationPolicy", "accessPolicy", "attReleasePolicy"})
-@Schema(subTypes = {OIDCRelyingPartyTO.class, SAML2ServiceProviderTO.class}, discriminatorProperty = "@class")
+@JsonPropertyOrder(value = { "@class", "key", "name", "description",
+ "authenticationPolicy", "accessPolicy", "attReleasePolicy" })
+@Schema(subTypes = { OIDCRelyingPartyTO.class, SAML2ServiceProviderTO.class }, discriminatorProperty = "@class")
public abstract class ClientAppTO extends BaseBean implements EntityTO {
private static final long serialVersionUID = 6577639976115661357L;
@@ -51,33 +47,33 @@ public abstract class ClientAppTO extends BaseBean implements EntityTO {
private String description;
- private AuthenticationPolicyTO authenticationPolicy;
+ private String authenticationPolicy;
- private AccessPolicyTO accessPolicy;
+ private String accessPolicy;
- private AttrReleasePolicyTO attrReleasePolicy;
+ private String attrReleasePolicy;
- public AttrReleasePolicyTO getAttrReleasePolicy() {
+ public String getAttrReleasePolicy() {
return attrReleasePolicy;
}
- public void setAttrReleasePolicy(final AttrReleasePolicyTO attrReleasePolicy) {
+ public void setAttrReleasePolicy(final String attrReleasePolicy) {
this.attrReleasePolicy = attrReleasePolicy;
}
- public AccessPolicyTO getAccessPolicy() {
+ public String getAccessPolicy() {
return accessPolicy;
}
- public void setAccessPolicy(final AccessPolicyTO accessPolicy) {
+ public void setAccessPolicy(final String accessPolicy) {
this.accessPolicy = accessPolicy;
}
- public AuthenticationPolicyTO getAuthenticationPolicy() {
+ public String getAuthenticationPolicy() {
return authenticationPolicy;
}
- public void setAuthenticationPolicy(final AuthenticationPolicyTO authenticationPolicy) {
+ public void setAuthenticationPolicy(final String authenticationPolicy) {
this.authenticationPolicy = authenticationPolicy;
}
@@ -113,14 +109,14 @@ public abstract class ClientAppTO extends BaseBean implements EntityTO {
@Override
public int hashCode() {
return new HashCodeBuilder()
- .appendSuper(super.hashCode())
- .append(key)
- .append(name)
- .append(description)
- .append(authenticationPolicy)
- .append(accessPolicy)
- .append(attrReleasePolicy)
- .toHashCode();
+ .appendSuper(super.hashCode())
+ .append(key)
+ .append(name)
+ .append(description)
+ .append(authenticationPolicy)
+ .append(accessPolicy)
+ .append(attrReleasePolicy)
+ .toHashCode();
}
@Override
@@ -136,13 +132,13 @@ public abstract class ClientAppTO extends BaseBean implements EntityTO {
}
ClientAppTO rhs = (ClientAppTO) obj;
return new EqualsBuilder()
- .appendSuper(super.equals(obj))
- .append(this.key, rhs.key)
- .append(this.name, rhs.name)
- .append(this.description, rhs.description)
- .append(this.authenticationPolicy, rhs.authenticationPolicy)
- .append(this.accessPolicy, rhs.accessPolicy)
- .append(this.attrReleasePolicy, rhs.attrReleasePolicy)
- .isEquals();
+ .appendSuper(super.equals(obj))
+ .append(this.key, rhs.key)
+ .append(this.name, rhs.name)
+ .append(this.description, rhs.description)
+ .append(this.authenticationPolicy, rhs.authenticationPolicy)
+ .append(this.accessPolicy, rhs.accessPolicy)
+ .append(this.attrReleasePolicy, rhs.attrReleasePolicy)
+ .isEquals();
}
}
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AccessPolicyDAO.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AccessPolicyDAO.java
deleted file mode 100644
index 5867b93..0000000
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AccessPolicyDAO.java
+++ /dev/null
@@ -1,38 +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.api.dao.authentication;
-
-import org.apache.syncope.core.persistence.api.dao.DAO;
-import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
-
-import java.util.List;
-
-public interface AccessPolicyDAO extends DAO<AccessPolicy> {
-
- AccessPolicy find(String key);
-
- List<AccessPolicy> findAll();
-
- AccessPolicy save(AccessPolicy policy);
-
- void delete(String key);
-
- void delete(AccessPolicy policy);
-
-}
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AttrReleasePolicyDAO.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AttrReleasePolicyDAO.java
deleted file mode 100644
index b2c1d19..0000000
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AttrReleasePolicyDAO.java
+++ /dev/null
@@ -1,38 +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.api.dao.authentication;
-
-import org.apache.syncope.core.persistence.api.dao.DAO;
-import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
-
-import java.util.List;
-
-public interface AttrReleasePolicyDAO extends DAO<AttrReleasePolicy> {
-
- AttrReleasePolicy find(String key);
-
- List<AttrReleasePolicy> findAll();
-
- AttrReleasePolicy save(AttrReleasePolicy authenticationModule);
-
- void delete(String key);
-
- void delete(AttrReleasePolicy authenticationModule);
-
-}
diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AuthenticationPolicyDAO.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AuthenticationPolicyDAO.java
deleted file mode 100644
index 30f4276..0000000
--- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/authentication/AuthenticationPolicyDAO.java
+++ /dev/null
@@ -1,38 +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.api.dao.authentication;
-
-import org.apache.syncope.core.persistence.api.dao.DAO;
-import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
-
-import java.util.List;
-
-public interface AuthenticationPolicyDAO extends DAO<AuthenticationPolicy> {
-
- AuthenticationPolicy find(String key);
-
- List<AuthenticationPolicy> findAll();
-
- AuthenticationPolicy save(AuthenticationPolicy authenticationModule);
-
- void delete(String key);
-
- void delete(AuthenticationPolicy authenticationModule);
-
-}
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java
index fbaad71..6ee0369 100644
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java
+++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAPolicyDAO.java
@@ -72,9 +72,9 @@ public class JPAPolicyDAO extends AbstractDAO<Policy> implements PolicyDAO {
: AuthenticationPolicy.class.isAssignableFrom(reference)
? JPAAuthenticationPolicy.class
: AccessPolicy.class.isAssignableFrom(reference)
- ? JPAAttrReleasePolicy.class
- : AttrReleasePolicy.class.isAssignableFrom(reference)
? JPAAccessPolicy.class
+ : AttrReleasePolicy.class.isAssignableFrom(reference)
+ ? JPAAttrReleasePolicy.class
: null;
}
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAccessPolicyDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAccessPolicyDAO.java
deleted file mode 100644
index 6fd120b..0000000
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAccessPolicyDAO.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.AccessPolicyDAO;
-import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
-import org.apache.syncope.core.persistence.jpa.dao.AbstractDAO;
-import org.apache.syncope.core.persistence.jpa.entity.policy.JPAAccessPolicy;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.persistence.TypedQuery;
-
-import java.util.List;
-
-@Repository
-public class JPAAccessPolicyDAO extends AbstractDAO<AccessPolicy> implements AccessPolicyDAO {
-
- @Override
- public AccessPolicy find(final String key) {
- return entityManager().find(JPAAccessPolicy.class, key);
- }
-
- @Transactional(readOnly = true)
- @Override
- public List<AccessPolicy> findAll() {
- TypedQuery<AccessPolicy> query = entityManager().createQuery(
- "SELECT e FROM " + JPAAccessPolicy.class.getSimpleName() + " e", AccessPolicy.class);
-
- return query.getResultList();
- }
-
- @Override
- public AccessPolicy save(final AccessPolicy policy) {
- return entityManager().merge(policy);
- }
-
- @Override
- public void delete(final String key) {
- AccessPolicy policy = find(key);
- if (policy == null) {
- return;
- }
-
- delete(policy);
- }
-
- @Override
- public void delete(final AccessPolicy policy) {
- entityManager().remove(policy);
- }
-
-}
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAttrReleasePolicyDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAttrReleasePolicyDAO.java
deleted file mode 100644
index c210fda..0000000
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAttrReleasePolicyDAO.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.AttrReleasePolicyDAO;
-import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
-import org.apache.syncope.core.persistence.jpa.dao.AbstractDAO;
-import org.apache.syncope.core.persistence.jpa.entity.policy.JPAAttrReleasePolicy;
-import org.springframework.stereotype.Repository;
-import org.springframework.transaction.annotation.Transactional;
-
-import javax.persistence.TypedQuery;
-
-import java.util.List;
-
-@Repository
-public class JPAAttrReleasePolicyDAO extends AbstractDAO<AttrReleasePolicy> implements AttrReleasePolicyDAO {
-
- @Override
- public AttrReleasePolicy find(final String key) {
- return entityManager().find(JPAAttrReleasePolicy.class, key);
- }
-
- @Transactional(readOnly = true)
- @Override
- public List<AttrReleasePolicy> findAll() {
- TypedQuery<AttrReleasePolicy> query = entityManager().createQuery(
- "SELECT e FROM " + JPAAttrReleasePolicy.class.getSimpleName() + " e", AttrReleasePolicy.class);
-
- return query.getResultList();
- }
-
- @Override
- public AttrReleasePolicy save(final AttrReleasePolicy policy) {
- return entityManager().merge(policy);
- }
-
- @Override
- public void delete(final String key) {
- AttrReleasePolicy policy = find(key);
- if (policy == null) {
- return;
- }
-
- delete(policy);
- }
-
- @Override
- public void delete(final AttrReleasePolicy policy) {
- entityManager().remove(policy);
- }
-
-}
diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAuthenticationPolicyDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAuthenticationPolicyDAO.java
deleted file mode 100644
index 452102b..0000000
--- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/authentication/JPAAuthenticationPolicyDAO.java
+++ /dev/null
@@ -1,67 +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 JPAAuthenticationPolicyDAO 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/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java
index 03491f1..4738e82 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AbstractClientAppTest.java
@@ -16,32 +16,27 @@
* under the License.
*
*/
-
package org.apache.syncope.core.persistence.jpa.inner;
+import java.util.List;
+import java.util.Map;
import org.apache.syncope.common.lib.access.DefaultAccessPolicyConf;
import org.apache.syncope.common.lib.authentication.policy.DefaultAuthenticationPolicyConf;
import org.apache.syncope.common.lib.types.AMImplementationType;
import org.apache.syncope.common.lib.types.ImplementationEngine;
import org.apache.syncope.core.persistence.api.dao.ImplementationDAO;
-import org.apache.syncope.core.persistence.api.dao.authentication.AccessPolicyDAO;
-import org.apache.syncope.core.persistence.api.dao.authentication.AuthenticationPolicyDAO;
import org.apache.syncope.core.persistence.api.entity.Implementation;
import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
+import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
import org.apache.syncope.core.persistence.jpa.AbstractTest;
import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
import org.springframework.beans.factory.annotation.Autowired;
-import java.util.List;
-import java.util.Map;
-
public class AbstractClientAppTest extends AbstractTest {
- @Autowired
- protected AuthenticationPolicyDAO authenticationPolicyDAO;
@Autowired
- protected AccessPolicyDAO accessPolicyDAO;
+ protected PolicyDAO policyDAO;
@Autowired
protected ImplementationDAO implementationDAO;
@@ -65,7 +60,7 @@ public class AbstractClientAppTest extends AbstractTest {
type = implementationDAO.save(type);
accessPolicy.addConfiguration(type);
- return accessPolicyDAO.save(accessPolicy);
+ return policyDAO.save(accessPolicy);
}
@@ -85,7 +80,7 @@ public class AbstractClientAppTest extends AbstractTest {
type = implementationDAO.save(type);
authenticationPolicy.addConfiguration(type);
- return authenticationPolicyDAO.save(authenticationPolicy);
+ return policyDAO.save(authenticationPolicy);
}
}
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AccessPolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AccessPolicyTest.java
deleted file mode 100644
index cf0004d8..0000000
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AccessPolicyTest.java
+++ /dev/null
@@ -1,107 +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.inner;
-
-import org.apache.syncope.common.lib.access.DefaultAccessPolicyConf;
-import org.apache.syncope.common.lib.attrs.AllowedAttrReleasePolicyConf;
-import org.apache.syncope.common.lib.types.AMImplementationType;
-import org.apache.syncope.common.lib.types.ImplementationEngine;
-import org.apache.syncope.core.persistence.api.dao.ImplementationDAO;
-import org.apache.syncope.core.persistence.api.dao.authentication.AccessPolicyDAO;
-import org.apache.syncope.core.persistence.api.entity.Implementation;
-import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
-import org.apache.syncope.core.persistence.jpa.AbstractTest;
-import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-@Transactional("Master")
-public class AccessPolicyTest extends AbstractTest {
-
- @Autowired
- private AccessPolicyDAO accessPolicyDAO;
-
- @Autowired
- private ImplementationDAO implementationDAO;
-
- @Test
- public void find() {
- AccessPolicy policy = accessPolicyDAO.find("617735c7-deb3-40b3-8a9a-683037e523a2");
- assertNull(policy);
- policy = accessPolicyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
- assertNotNull(policy);
- policy = accessPolicyDAO.find(UUID.randomUUID().toString());
- assertNull(policy);
- }
-
- @Test
- public void findAll() {
- List<AccessPolicy> policies = accessPolicyDAO.findAll();
- assertNotNull(policies);
- assertEquals(1, policies.size());
- }
-
- @Test
- public void save() {
- int beforeCount = accessPolicyDAO.findAll().size();
- AccessPolicy policy = entityFactory.newEntity(AccessPolicy.class);
- policy.setName("AttrReleasePolicyAllowEverything");
- policy.setDescription("This is a sample attr release policy that releases everything");
-
- DefaultAccessPolicyConf conf = new DefaultAccessPolicyConf();
- conf.setRequiredAttributes(Map.of("cn", List.of("syncope")));
- conf.setName("AttrReleasePolicyAllowEverything");
-
- Implementation type = entityFactory.newEntity(Implementation.class);
- type.setKey("AttrReleasePolicyAllowEverything");
- type.setEngine(ImplementationEngine.JAVA);
- type.setType(AMImplementationType.ACCESS_POLICY_CONFIGURATIONS);
- type.setBody(POJOHelper.serialize(conf));
- type = implementationDAO.save(type);
-
- policy.addConfiguration(type);
- accessPolicyDAO.save(policy);
-
- assertNotNull(policy);
- assertNotNull(policy.getKey());
-
- int afterCount = accessPolicyDAO.findAll().size();
- assertEquals(afterCount, beforeCount + 1);
- }
-
- @Test
- public void delete() {
- AccessPolicy policy = accessPolicyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
- assertNotNull(policy);
- accessPolicyDAO.delete("419935c7-deb3-40b3-8a9a-683037e523a2");
- policy = accessPolicyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
- assertNull(policy);
- }
-}
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AttrReleasePolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AttrReleasePolicyTest.java
deleted file mode 100644
index f801229..0000000
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AttrReleasePolicyTest.java
+++ /dev/null
@@ -1,103 +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.inner;
-
-import org.apache.syncope.common.lib.attrs.AllowedAttrReleasePolicyConf;
-import org.apache.syncope.common.lib.types.AMImplementationType;
-import org.apache.syncope.common.lib.types.ImplementationEngine;
-import org.apache.syncope.core.persistence.api.dao.ImplementationDAO;
-import org.apache.syncope.core.persistence.api.dao.authentication.AttrReleasePolicyDAO;
-import org.apache.syncope.core.persistence.api.entity.Implementation;
-import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
-import org.apache.syncope.core.persistence.jpa.AbstractTest;
-import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.UUID;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-@Transactional("Master")
-public class AttrReleasePolicyTest extends AbstractTest {
-
- @Autowired
- private AttrReleasePolicyDAO attrReleasePolicyDAO;
-
- @Autowired
- private ImplementationDAO implementationDAO;
-
- @Test
- public void find() {
- AttrReleasePolicy policy = attrReleasePolicyDAO.find("019935c7-deb3-40b3-8a9a-683037e523a2");
- assertNull(policy);
- policy = attrReleasePolicyDAO.find("319935c7-deb3-40b3-8a9a-683037e523a2");
- assertNotNull(policy);
- policy = attrReleasePolicyDAO.find(UUID.randomUUID().toString());
- assertNull(policy);
- }
-
- @Test
- public void findAll() {
- List<AttrReleasePolicy> policies = attrReleasePolicyDAO.findAll();
- assertNotNull(policies);
- assertEquals(2, policies.size());
- }
-
- @Test
- public void save() {
- int beforeCount = attrReleasePolicyDAO.findAll().size();
- AttrReleasePolicy policy = entityFactory.newEntity(AttrReleasePolicy.class);
- policy.setName("AttrReleasePolicyAllowEverything");
- policy.setDescription("This is a sample attr release policy that releases everything");
-
- AllowedAttrReleasePolicyConf conf = new AllowedAttrReleasePolicyConf();
- conf.setAllowedAttributes(List.of("*"));
- conf.setName("AttrReleasePolicyAllowEverything");
-
- Implementation type = entityFactory.newEntity(Implementation.class);
- type.setKey("AttrReleasePolicyAllowEverything");
- type.setEngine(ImplementationEngine.JAVA);
- type.setType(AMImplementationType.ATTR_RELEASE_POLICY_CONFIGURATIONS);
- type.setBody(POJOHelper.serialize(conf));
- type = implementationDAO.save(type);
-
- policy.addConfiguration(type);
- attrReleasePolicyDAO.save(policy);
-
- assertNotNull(policy);
- assertNotNull(policy.getKey());
-
- int afterCount = attrReleasePolicyDAO.findAll().size();
- assertEquals(afterCount, beforeCount + 1);
- }
-
- @Test
- public void delete() {
- AttrReleasePolicy policy = attrReleasePolicyDAO.find("319935c7-deb3-40b3-8a9a-683037e523a2");
- assertNotNull(policy);
- attrReleasePolicyDAO.delete("319935c7-deb3-40b3-8a9a-683037e523a2");
- policy = attrReleasePolicyDAO.find("319935c7-deb3-40b3-8a9a-683037e523a2");
- assertNull(policy);
- }
-}
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AuthenticationPolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AuthenticationPolicyTest.java
deleted file mode 100644
index d5f2942..0000000
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/AuthenticationPolicyTest.java
+++ /dev/null
@@ -1,103 +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.inner;
-
-import org.apache.syncope.common.lib.authentication.policy.DefaultAuthenticationPolicyConf;
-import org.apache.syncope.common.lib.types.AMImplementationType;
-import org.apache.syncope.common.lib.types.ImplementationEngine;
-import org.apache.syncope.core.persistence.api.dao.ImplementationDAO;
-import org.apache.syncope.core.persistence.api.dao.authentication.AuthenticationPolicyDAO;
-import org.apache.syncope.core.persistence.api.entity.Implementation;
-import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
-import org.apache.syncope.core.persistence.jpa.AbstractTest;
-import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.UUID;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-
-@Transactional("Master")
-public class AuthenticationPolicyTest extends AbstractTest {
-
- @Autowired
- private AuthenticationPolicyDAO authenticationPolicyDAO;
-
- @Autowired
- private ImplementationDAO implementationDAO;
-
- @Test
- public void find() {
- AuthenticationPolicy authenticationPolicy = authenticationPolicyDAO.find("b912a0d4-a890-416f-9ab8-84ab077eb028");
- assertNotNull(authenticationPolicy);
- authenticationPolicy = authenticationPolicyDAO.find("659b9906-4b6e-4bc0-aca0-6809dff346d4");
- assertNotNull(authenticationPolicy);
- authenticationPolicy = authenticationPolicyDAO.find(UUID.randomUUID().toString());
- assertNull(authenticationPolicy);
- }
-
- @Test
- public void findAll() {
- List<AuthenticationPolicy> authenticationPolicies = authenticationPolicyDAO.findAll();
- assertNotNull(authenticationPolicies);
- assertEquals(2, authenticationPolicies.size());
- }
-
- @Test
- public void save() {
- int beforeCount = authenticationPolicyDAO.findAll().size();
- AuthenticationPolicy authenticationPolicy = entityFactory.newEntity(AuthenticationPolicy.class);
- authenticationPolicy.setName("AuthenticationPolicyTest");
- authenticationPolicy.setDescription("This is a sample authentication policy");
-
- DefaultAuthenticationPolicyConf conf = new DefaultAuthenticationPolicyConf();
- conf.setAuthenticationModules(List.of("LdapAuthentication1", "DatabaseAuthentication2"));
-
- Implementation type = entityFactory.newEntity(Implementation.class);
- type.setKey("AuthPolicyConfKey");
- type.setEngine(ImplementationEngine.JAVA);
- type.setType(AMImplementationType.AUTH_POLICY_CONFIGURATIONS);
- type.setBody(POJOHelper.serialize(conf));
- type = implementationDAO.save(type);
-
- authenticationPolicy.addConfiguration(type);
- authenticationPolicyDAO.save(authenticationPolicy);
-
- assertNotNull(authenticationPolicy);
- assertNotNull(authenticationPolicy.getKey());
-
- int afterCount = authenticationPolicyDAO.findAll().size();
- assertEquals(afterCount, beforeCount + 1);
- }
-
- @Test
- public void delete() {
- AuthenticationPolicy authenticationPolicy = authenticationPolicyDAO.find("b912a0d4-a890-416f-9ab8-84ab077eb028");
- assertNotNull(authenticationPolicy);
- authenticationPolicyDAO.delete("b912a0d4-a890-416f-9ab8-84ab077eb028");
- authenticationPolicy = authenticationPolicyDAO.find("b912a0d4-a890-416f-9ab8-84ab077eb028");
- assertNull(authenticationPolicy);
- }
-
-}
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
index c8f3b6b..89ae701 100644
--- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
@@ -18,6 +18,15 @@
*/
package org.apache.syncope.core.persistence.jpa.inner;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Map;
+import java.util.List;
+import java.util.UUID;
import org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf;
import org.apache.syncope.common.lib.policy.DefaultPullCorrelationRuleConf;
import org.apache.syncope.common.lib.policy.DefaultPushCorrelationRuleConf;
@@ -37,21 +46,18 @@ import org.apache.syncope.core.persistence.api.entity.policy.PullCorrelationRule
import org.apache.syncope.core.persistence.api.entity.policy.PullPolicy;
import org.apache.syncope.core.persistence.api.entity.policy.PushCorrelationRuleEntity;
import org.apache.syncope.core.persistence.api.entity.policy.PushPolicy;
+import org.apache.syncope.common.lib.access.DefaultAccessPolicyConf;
+import org.apache.syncope.common.lib.attrs.AllowedAttrReleasePolicyConf;
+import org.apache.syncope.common.lib.authentication.policy.DefaultAuthenticationPolicyConf;
+import org.apache.syncope.common.lib.types.AMImplementationType;
+import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
import org.apache.syncope.core.persistence.jpa.AbstractTest;
import org.apache.syncope.core.provisioning.api.serialization.POJOHelper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
-import java.util.List;
-import java.util.UUID;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
@Transactional("Master")
public class PolicyTest extends AbstractTest {
@@ -79,7 +85,7 @@ public class PolicyTest extends AbstractTest {
PullCorrelationRuleEntity pullCR = pullPolicy.getCorrelationRule(anyTypeDAO.findUser()).orElse(null);
assertNotNull(pullCR);
DefaultPullCorrelationRuleConf pullCRConf =
- POJOHelper.deserialize(pullCR.getImplementation().getBody(), DefaultPullCorrelationRuleConf.class);
+ POJOHelper.deserialize(pullCR.getImplementation().getBody(), DefaultPullCorrelationRuleConf.class);
assertNotNull(pullCRConf);
assertEquals(2, pullCRConf.getSchemas().size());
assertTrue(pullCRConf.getSchemas().contains("username"));
@@ -91,20 +97,51 @@ public class PolicyTest extends AbstractTest {
PushCorrelationRuleEntity pushCR = pushPolicy.getCorrelationRule(anyTypeDAO.findUser()).orElse(null);
assertNotNull(pushCR);
DefaultPushCorrelationRuleConf pushCRConf =
- POJOHelper.deserialize(pushCR.getImplementation().getBody(), DefaultPushCorrelationRuleConf.class);
+ POJOHelper.deserialize(pushCR.getImplementation().getBody(), DefaultPushCorrelationRuleConf.class);
assertNotNull(pushCRConf);
assertEquals(1, pushCRConf.getSchemas().size());
assertTrue(pushCRConf.getSchemas().contains("surname"));
+ AccessPolicy accessPolicy = policyDAO.find("617735c7-deb3-40b3-8a9a-683037e523a2");
+ assertNull(accessPolicy);
+ accessPolicy = policyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
+ assertNotNull(accessPolicy);
+ accessPolicy = policyDAO.find(UUID.randomUUID().toString());
+ assertNull(accessPolicy);
+
AuthenticationPolicy authenticationPolicy = policyDAO.find("b912a0d4-a890-416f-9ab8-84ab077eb028");
assertNotNull(authenticationPolicy);
+ authenticationPolicy = policyDAO.find("659b9906-4b6e-4bc0-aca0-6809dff346d4");
+ assertNotNull(authenticationPolicy);
+ authenticationPolicy = policyDAO.find(UUID.randomUUID().toString());
+ assertNull(authenticationPolicy);
+
+ AttrReleasePolicy attrReleasePolicy = policyDAO.find("019935c7-deb3-40b3-8a9a-683037e523a2");
+ assertNull(attrReleasePolicy);
+ attrReleasePolicy = policyDAO.find("319935c7-deb3-40b3-8a9a-683037e523a2");
+ assertNotNull(attrReleasePolicy);
+ attrReleasePolicy = policyDAO.find(UUID.randomUUID().toString());
+ assertNull(attrReleasePolicy);
+
}
@Test
public void findByType() {
- List<PullPolicy> policies = policyDAO.find(PullPolicy.class);
- assertNotNull(policies);
- assertFalse(policies.isEmpty());
+ List<PullPolicy> pullPolicies = policyDAO.find(PullPolicy.class);
+ assertNotNull(pullPolicies);
+ assertFalse(pullPolicies.isEmpty());
+
+ List<AccessPolicy> accessPolicies = policyDAO.find(AccessPolicy.class);
+ assertNotNull(accessPolicies);
+ assertEquals(1, accessPolicies.size());
+
+ List<AuthenticationPolicy> authenticationPolicies = policyDAO.find(AuthenticationPolicy.class);
+ assertNotNull(authenticationPolicies);
+ assertEquals(2, authenticationPolicies.size());
+
+ List<AttrReleasePolicy> attrReleasePolicies = policyDAO.find(AttrReleasePolicy.class);
+ assertNotNull(attrReleasePolicies);
+ assertEquals(2, attrReleasePolicies.size());
}
@Test
@@ -146,14 +183,83 @@ public class PolicyTest extends AbstractTest {
assertNotNull(policy);
assertEquals(pullURuleName,
- policy.getCorrelationRule(anyTypeDAO.findUser()).get().getImplementation().getKey());
+ policy.getCorrelationRule(anyTypeDAO.findUser()).get().getImplementation().getKey());
assertEquals(pullGRuleName,
- policy.getCorrelationRule(anyTypeDAO.findGroup()).get().getImplementation().getKey());
+ policy.getCorrelationRule(anyTypeDAO.findGroup()).get().getImplementation().getKey());
+
+ int beforeCount = policyDAO.findAll().size();
+ AccessPolicy accessPolicy = entityFactory.newEntity(AccessPolicy.class);
+ accessPolicy.setName("AttrReleasePolicyAllowEverything");
+ accessPolicy.setDescription("This is a sample attr release policy that releases everything");
+
+ DefaultAccessPolicyConf conf = new DefaultAccessPolicyConf();
+ conf.setRequiredAttributes(Map.of("cn", List.of("syncope")));
+ conf.setName("AttrReleasePolicyAllowEverything");
+
+ Implementation type = entityFactory.newEntity(Implementation.class);
+ type.setKey("AttrReleasePolicyAllowEverything");
+ type.setEngine(ImplementationEngine.JAVA);
+ type.setType(AMImplementationType.ACCESS_POLICY_CONFIGURATIONS);
+ type.setBody(POJOHelper.serialize(conf));
+ type = implementationDAO.save(type);
+
+ accessPolicy.addConfiguration(type);
+ accessPolicy = policyDAO.save(accessPolicy);
+ assertNotNull(accessPolicy);
+ assertNotNull(accessPolicy.getKey());
+
+ int afterCount = policyDAO.findAll().size();
+ assertEquals(afterCount, beforeCount + 1);
+
+ beforeCount = policyDAO.findAll().size();
AuthenticationPolicy authenticationPolicy = entityFactory.newEntity(AuthenticationPolicy.class);
- authenticationPolicy.setDescription("Syncope Account Policy");
+ authenticationPolicy.setName("AuthenticationPolicyTest");
+ authenticationPolicy.setDescription("This is a sample authentication policy");
+
+ DefaultAuthenticationPolicyConf authPolicyConf = new DefaultAuthenticationPolicyConf();
+ authPolicyConf.setAuthenticationModules(List.of("LdapAuthentication1", "DatabaseAuthentication2"));
+
+ Implementation authPolicyType = entityFactory.newEntity(Implementation.class);
+ authPolicyType.setKey("AuthPolicyConfKey");
+ authPolicyType.setEngine(ImplementationEngine.JAVA);
+ authPolicyType.setType(AMImplementationType.AUTH_POLICY_CONFIGURATIONS);
+ authPolicyType.setBody(POJOHelper.serialize(authPolicyConf));
+ authPolicyType = implementationDAO.save(authPolicyType);
+
+ authenticationPolicy.addConfiguration(authPolicyType);
authenticationPolicy = policyDAO.save(authenticationPolicy);
+
assertNotNull(authenticationPolicy);
+ assertNotNull(authenticationPolicy.getKey());
+
+ afterCount = policyDAO.findAll().size();
+ assertEquals(afterCount, beforeCount + 1);
+
+ beforeCount = policyDAO.findAll().size();
+ AttrReleasePolicy attrReleasepolicy = entityFactory.newEntity(AttrReleasePolicy.class);
+ attrReleasepolicy.setName("AttrReleasePolicyAllowEverything");
+ attrReleasepolicy.setDescription("This is a sample attr release policy that releases everything");
+
+ AllowedAttrReleasePolicyConf attrReleasePolicyConf = new AllowedAttrReleasePolicyConf();
+ attrReleasePolicyConf.setAllowedAttributes(List.of("*"));
+ attrReleasePolicyConf.setName("AttrReleasePolicyAllowEverything");
+
+ Implementation attrReleasePolicyType = entityFactory.newEntity(Implementation.class);
+ attrReleasePolicyType.setKey("AttrReleasePolicyAllowEverything");
+ attrReleasePolicyType.setEngine(ImplementationEngine.JAVA);
+ attrReleasePolicyType.setType(AMImplementationType.ATTR_RELEASE_POLICY_CONFIGURATIONS);
+ attrReleasePolicyType.setBody(POJOHelper.serialize(attrReleasePolicyConf));
+ attrReleasePolicyType = implementationDAO.save(attrReleasePolicyType);
+
+ attrReleasepolicy.addConfiguration(attrReleasePolicyType);
+ attrReleasepolicy = policyDAO.save(attrReleasepolicy);
+
+ assertNotNull(attrReleasepolicy);
+ assertNotNull(attrReleasepolicy.getKey());
+
+ afterCount = policyDAO.findAll().size();
+ assertEquals(afterCount, beforeCount + 1);
}
@@ -196,5 +302,23 @@ public class PolicyTest extends AbstractTest {
Policy actual = policyDAO.find("66691e96-285f-4464-bc19-e68384ea4c85");
assertNull(actual);
+
+ AccessPolicy accessPolicy = policyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
+ assertNotNull(accessPolicy);
+ policyDAO.delete(accessPolicy);
+ accessPolicy = policyDAO.find("419935c7-deb3-40b3-8a9a-683037e523a2");
+ assertNull(accessPolicy);
+
+ AuthenticationPolicy authenticationPolicy = policyDAO.find("b912a0d4-a890-416f-9ab8-84ab077eb028");
+ assertNotNull(authenticationPolicy);
+ policyDAO.delete(authenticationPolicy);
+ authenticationPolicy = policyDAO.find("b912a0d4-a890-416f-9ab8-84ab077eb028");
+ assertNull(authenticationPolicy);
+
+ AttrReleasePolicy attrReleasepolicy = policyDAO.find("319935c7-deb3-40b3-8a9a-683037e523a2");
+ assertNotNull(attrReleasepolicy);
+ policyDAO.delete(attrReleasepolicy);
+ attrReleasepolicy = policyDAO.find("319935c7-deb3-40b3-8a9a-683037e523a2");
+ assertNull(attrReleasepolicy);
}
}
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCRelyingPartyDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCRelyingPartyDataBinderImpl.java
index c96ea2a..ad43917 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCRelyingPartyDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/OIDCRelyingPartyDataBinderImpl.java
@@ -19,8 +19,6 @@
package org.apache.syncope.core.provisioning.java.data;
import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AccessPolicyTO;
-import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
import org.apache.syncope.common.lib.to.client.OIDCRelyingPartyTO;
import org.apache.syncope.common.lib.types.ClientExceptionType;
import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
@@ -28,7 +26,9 @@ import org.apache.syncope.core.persistence.api.dao.authentication.OIDCRelyingPar
import org.apache.syncope.core.persistence.api.entity.EntityFactory;
import org.apache.syncope.core.persistence.api.entity.authentication.OIDCRelyingParty;
import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.Policy;
import org.apache.syncope.core.provisioning.api.data.OIDCRelyingPartyDataBinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -63,18 +63,47 @@ public class OIDCRelyingPartyDataBinderImpl implements OIDCRelyingPartyDataBinde
application.setClientId(applicationTO.getClientId());
application.setRedirectUris(applicationTO.getRedirectUris());
- AuthenticationPolicy authenticationPolicy = policyDAO.
- find(applicationTO.getAuthenticationPolicy().getKey());
- if (authenticationPolicy == null) {
- SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidEntity);
- sce.getElements().add("Unable to locate authentication policy "
- + applicationTO.getAuthenticationPolicy().getKey());
- throw sce;
+ if (applicationTO.getAuthenticationPolicy() == null) {
+ application.setAuthenticationPolicy(null);
+ } else {
+ Policy policy = policyDAO.find(applicationTO.getAuthenticationPolicy());
+ if (policy instanceof AuthenticationPolicy) {
+ application.setAuthenticationPolicy((AuthenticationPolicy) policy);
+ } else {
+ SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
+ sce.getElements().add("Expected " + AuthenticationPolicy.class.getSimpleName()
+ + ", found " + policy.getClass().getSimpleName());
+ throw sce;
+ }
}
- application.setAuthenticationPolicy(authenticationPolicy);
- AccessPolicy accessPolicy = policyDAO.find(applicationTO.getAccessPolicy().getKey());
- application.setAccessPolicy(accessPolicy);
+ if (applicationTO.getAccessPolicy() == null) {
+ application.setAccessPolicy(null);
+ } else {
+ Policy policy = policyDAO.find(applicationTO.getAccessPolicy());
+ if (policy instanceof AccessPolicy) {
+ application.setAccessPolicy((AccessPolicy) policy);
+ } else {
+ SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
+ sce.getElements().add("Expected " + AccessPolicy.class.getSimpleName()
+ + ", found " + policy.getClass().getSimpleName());
+ throw sce;
+ }
+ }
+
+ if (applicationTO.getAttrReleasePolicy() == null) {
+ application.setAttrReleasePolicy(null);
+ } else {
+ Policy policy = policyDAO.find(applicationTO.getAttrReleasePolicy());
+ if (policy instanceof AttrReleasePolicy) {
+ application.setAttrReleasePolicy((AttrReleasePolicy) policy);
+ } else {
+ SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
+ sce.getElements().add("Expected " + AttrReleasePolicy.class.getSimpleName()
+ + ", found " + policy.getClass().getSimpleName());
+ throw sce;
+ }
+ }
return application;
}
@@ -90,17 +119,12 @@ public class OIDCRelyingPartyDataBinderImpl implements OIDCRelyingPartyDataBinde
applicationTO.setRedirectUris(rp.getRedirectUris());
applicationTO.setName(rp.getName());
- AuthenticationPolicyTO authenticationPolicyTO = new AuthenticationPolicyTO();
- authenticationPolicyTO.setDescription(rp.getAuthenticationPolicy().getDescription());
- authenticationPolicyTO.setKey(rp.getAuthenticationPolicy().getKey());
- applicationTO.setAuthenticationPolicy(authenticationPolicyTO);
-
- if (rp.getAccessPolicy() != null) {
- AccessPolicyTO accessPolicyTO = new AccessPolicyTO();
- accessPolicyTO.setDescription(rp.getAccessPolicy().getDescription());
- accessPolicyTO.setKey(rp.getAccessPolicy().getKey());
- applicationTO.setAccessPolicy(accessPolicyTO);
- }
+ applicationTO.setAuthenticationPolicy(rp.getAuthenticationPolicy() == null
+ ? null : rp.getAuthenticationPolicy().getKey());
+ applicationTO.setAccessPolicy(rp.getAccessPolicy() == null
+ ? null : rp.getAccessPolicy().getKey());
+ applicationTO.setAttrReleasePolicy(rp.getAttrReleasePolicy() == null
+ ? null : rp.getAttrReleasePolicy().getKey());
return applicationTO;
}
diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2ServiceProviderDataBinderImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2ServiceProviderDataBinderImpl.java
index bedfc98..7c24b39 100644
--- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2ServiceProviderDataBinderImpl.java
+++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/SAML2ServiceProviderDataBinderImpl.java
@@ -19,17 +19,16 @@
package org.apache.syncope.core.provisioning.java.data;
import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AccessPolicyTO;
-import org.apache.syncope.common.lib.to.AuthenticationPolicyTO;
import org.apache.syncope.common.lib.to.client.SAML2ServiceProviderTO;
import org.apache.syncope.common.lib.types.ClientExceptionType;
-import org.apache.syncope.core.persistence.api.dao.authentication.AccessPolicyDAO;
-import org.apache.syncope.core.persistence.api.dao.authentication.AuthenticationPolicyDAO;
+import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
import org.apache.syncope.core.persistence.api.dao.authentication.SAML2ServiceProviderDAO;
import org.apache.syncope.core.persistence.api.entity.EntityFactory;
import org.apache.syncope.core.persistence.api.entity.authentication.SAML2ServiceProvider;
import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.AttrReleasePolicy;
import org.apache.syncope.core.persistence.api.entity.policy.AuthenticationPolicy;
+import org.apache.syncope.core.persistence.api.entity.policy.Policy;
import org.apache.syncope.core.provisioning.api.data.SAML2ServiceProviderDataBinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -44,10 +43,7 @@ public class SAML2ServiceProviderDataBinderImpl implements SAML2ServiceProviderD
private EntityFactory entityFactory;
@Autowired
- private AuthenticationPolicyDAO authenticationPolicyDAO;
-
- @Autowired
- private AccessPolicyDAO accessPolicyDAO;
+ private PolicyDAO policyDAO;
@Override
public SAML2ServiceProvider create(final SAML2ServiceProviderTO applicationTO) {
@@ -66,19 +62,47 @@ public class SAML2ServiceProviderDataBinderImpl implements SAML2ServiceProviderD
application.setEntityId(applicationTO.getEntityId());
application.setMetadataLocation(applicationTO.getMetadataLocation());
- AuthenticationPolicy authenticationPolicy = authenticationPolicyDAO.
- find(applicationTO.getAuthenticationPolicy().getKey());
- if (authenticationPolicy == null) {
- SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidEntity);
- sce.getElements().add("Unable to locate authentication policy "
- + applicationTO.getAuthenticationPolicy().getKey());
- throw sce;
+ if (applicationTO.getAuthenticationPolicy() == null) {
+ application.setAuthenticationPolicy(null);
+ } else {
+ Policy policy = policyDAO.find(applicationTO.getAuthenticationPolicy());
+ if (policy instanceof AuthenticationPolicy) {
+ application.setAuthenticationPolicy((AuthenticationPolicy) policy);
+ } else {
+ SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
+ sce.getElements().add("Expected " + AuthenticationPolicy.class.getSimpleName()
+ + ", found " + policy.getClass().getSimpleName());
+ throw sce;
+ }
}
- application.setAuthenticationPolicy(authenticationPolicy);
- AccessPolicy accessPolicy = accessPolicyDAO.find(applicationTO.getAccessPolicy().getKey());
- application.setAccessPolicy(accessPolicy);
+ if (applicationTO.getAccessPolicy() == null) {
+ application.setAccessPolicy(null);
+ } else {
+ Policy policy = policyDAO.find(applicationTO.getAccessPolicy());
+ if (policy instanceof AccessPolicy) {
+ application.setAccessPolicy((AccessPolicy) policy);
+ } else {
+ SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
+ sce.getElements().add("Expected " + AccessPolicy.class.getSimpleName()
+ + ", found " + policy.getClass().getSimpleName());
+ throw sce;
+ }
+ }
+ if (applicationTO.getAttrReleasePolicy() == null) {
+ application.setAttrReleasePolicy(null);
+ } else {
+ Policy policy = policyDAO.find(applicationTO.getAttrReleasePolicy());
+ if (policy instanceof AttrReleasePolicy) {
+ application.setAttrReleasePolicy((AttrReleasePolicy) policy);
+ } else {
+ SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPolicy);
+ sce.getElements().add("Expected " + AttrReleasePolicy.class.getSimpleName()
+ + ", found " + policy.getClass().getSimpleName());
+ throw sce;
+ }
+ }
return application;
}
@@ -92,17 +116,12 @@ public class SAML2ServiceProviderDataBinderImpl implements SAML2ServiceProviderD
applicationTO.setMetadataLocation(sp.getMetadataLocation());
applicationTO.setName(sp.getName());
- AuthenticationPolicyTO authenticationPolicyTO = new AuthenticationPolicyTO();
- authenticationPolicyTO.setDescription(sp.getAuthenticationPolicy().getDescription());
- authenticationPolicyTO.setKey(sp.getAuthenticationPolicy().getKey());
- applicationTO.setAuthenticationPolicy(authenticationPolicyTO);
-
- if (sp.getAccessPolicy() != null) {
- AccessPolicyTO accessPolicyTO = new AccessPolicyTO();
- accessPolicyTO.setDescription(sp.getAccessPolicy().getDescription());
- accessPolicyTO.setKey(sp.getAccessPolicy().getKey());
- applicationTO.setAccessPolicy(accessPolicyTO);
- }
+ applicationTO.setAuthenticationPolicy(sp.getAuthenticationPolicy() == null
+ ? null : sp.getAuthenticationPolicy().getKey());
+ applicationTO.setAccessPolicy(sp.getAccessPolicy() == null
+ ? null : sp.getAccessPolicy().getKey());
+ applicationTO.setAttrReleasePolicy(sp.getAttrReleasePolicy() == null
+ ? null : sp.getAttrReleasePolicy().getKey());
return applicationTO;
}
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java
index 96a05d5..b7fa266 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/OIDCRelyingPartyITCase.java
@@ -66,7 +66,7 @@ public class OIDCRelyingPartyITCase extends AbstractITCase {
assertNotNull(accessPolicyTO);
rpTO.setClientId("newClientId");
- rpTO.setAccessPolicy(accessPolicyTO);
+ rpTO.setAccessPolicy(accessPolicyTO.getKey());
oidcRelyingPartyService.update(rpTO);
OIDCRelyingPartyTO updated = oidcRelyingPartyService.read(rpTO.getKey());
@@ -74,7 +74,6 @@ public class OIDCRelyingPartyITCase extends AbstractITCase {
assertNotNull(updated);
assertEquals("newClientId", updated.getClientId());
assertNotNull(updated.getAccessPolicy());
- assertEquals("New Access policy", updated.getAccessPolicy().getDescription());
}
@Test
@@ -110,8 +109,8 @@ public class OIDCRelyingPartyITCase extends AbstractITCase {
rpTO.setDescription("Example OIDC RP application");
rpTO.setClientId("clientId_" + getUUIDString());
rpTO.setClientSecret(StringUtils.EMPTY);
- rpTO.setAuthenticationPolicy(authPolicyTO);
- rpTO.setAccessPolicy(accessPolicyTO);
+ rpTO.setAuthenticationPolicy(authPolicyTO.getKey());
+ rpTO.setAccessPolicy(accessPolicyTO.getKey());
return rpTO;
}
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SAML2ServiceProviderITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SAML2ServiceProviderITCase.java
index cc6856b..32cd25a 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SAML2ServiceProviderITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/SAML2ServiceProviderITCase.java
@@ -64,7 +64,7 @@ public class SAML2ServiceProviderITCase extends AbstractITCase {
assertNotNull(accessPolicyTO);
samlSpTO.setEntityId("newEntityId");
- samlSpTO.setAccessPolicy(accessPolicyTO);
+ samlSpTO.setAccessPolicy(accessPolicyTO.getKey());
saml2ServiceProviderService.update(samlSpTO);
SAML2ServiceProviderTO updated = saml2ServiceProviderService.read(samlSpTO.getKey());
@@ -72,7 +72,6 @@ public class SAML2ServiceProviderITCase extends AbstractITCase {
assertNotNull(updated);
assertEquals("newEntityId", updated.getEntityId());
assertNotNull(updated.getAccessPolicy());
- assertEquals("New Access policy", updated.getAccessPolicy().getDescription());
}
@Test
@@ -108,8 +107,8 @@ public class SAML2ServiceProviderITCase extends AbstractITCase {
saml2spto.setDescription("Example SAML 2.0 service provider");
saml2spto.setEntityId("SAML2SPEntityId_" + getUUIDString());
saml2spto.setMetadataLocation("file:./test");
- saml2spto.setAuthenticationPolicy(authPolicyTO);
- saml2spto.setAccessPolicy(accessPolicyTO);
+ saml2spto.setAuthenticationPolicy(authPolicyTO.getKey());
+ saml2spto.setAccessPolicy(accessPolicyTO.getKey());
return saml2spto;
}