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

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


The following commit(s) were added to refs/heads/master by this push:
     new d03569b  [SYNCOPE-1588] Consent Policy (#215)
d03569b is described below

commit d03569bcd30de8f646c4587afe64ff72f61f53cf
Author: DimaAy <[email protected]>
AuthorDate: Mon Sep 14 14:10:31 2020 +0200

    [SYNCOPE-1588] Consent Policy (#215)
    
    * [SYNCOPE-1588] Consent Policy
    
    * consent policy change structure
    
    * fix
---
 .../lib/policy/AllowedAttrReleasePolicyConf.java   | 62 ++++++++++++++++++++++
 .../jpa/inner/AbstractClientAppTest.java           |  6 +++
 .../core/persistence/jpa/inner/PolicyTest.java     |  7 +++
 .../org/apache/syncope/fit/AbstractITCase.java     |  6 +++
 .../org/apache/syncope/fit/core/PolicyITCase.java  |  1 +
 .../org/apache/syncope/fit/core/RealmITCase.java   |  4 ++
 .../starter/mapping/AllowedAttrReleaseMapper.java  | 13 +++++
 7 files changed, 99 insertions(+)

diff --git 
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/policy/AllowedAttrReleasePolicyConf.java
 
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/policy/AllowedAttrReleasePolicyConf.java
index d72149f..310e8dc 100644
--- 
a/common/am/lib/src/main/java/org/apache/syncope/common/lib/policy/AllowedAttrReleasePolicyConf.java
+++ 
b/common/am/lib/src/main/java/org/apache/syncope/common/lib/policy/AllowedAttrReleasePolicyConf.java
@@ -18,8 +18,14 @@
  */
 package org.apache.syncope.common.lib.policy;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
+import 
com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 public class AllowedAttrReleasePolicyConf implements AttrReleasePolicyConf {
 
@@ -29,9 +35,65 @@ public class AllowedAttrReleasePolicyConf implements 
AttrReleasePolicyConf {
      * Specify the list of allowed attribute to release.
      * Use the special {@code *} to release everything.
      */
+    @JacksonXmlElementWrapper(localName = "allowedAttrs")
+    @JacksonXmlProperty(localName = "allowedAttrs")
+    @JsonProperty("allowedAttrs")
     private final List<String> allowedAttrs = new ArrayList<>();
 
+    private ConsentPolicy consentPolicy;
+
     public List<String> getAllowedAttrs() {
         return allowedAttrs;
     }
+
+    public ConsentPolicy getConsentPolicy() {
+        return consentPolicy;
+    }
+
+    public void setConsentPolicy(final ConsentPolicy consentPolicy) {
+        this.consentPolicy = consentPolicy;
+    }
+
+    public class ConsentPolicy implements Serializable {
+
+        private static final long serialVersionUID = 6744647343202583865L;
+
+        private Boolean status = null;
+
+        @JacksonXmlElementWrapper(localName = "excludedAttributes")
+        @JacksonXmlProperty(localName = "excludedAttributes")
+        @JsonProperty("excludedAttributes")
+        private final Set<String> excludedAttrs = new HashSet<>();
+
+        @JacksonXmlElementWrapper(localName = "includeOnlyAttrs")
+        @JacksonXmlProperty(localName = "includeOnlyAttrs")
+        @JsonProperty("includeOnlyAttrs")
+        private final Set<String> includeOnlyAttrs = new HashSet<>();
+
+        public Boolean getStatus() {
+            return status;
+        }
+
+        public void setStatus(final Boolean status) {
+            this.status = status;
+        }
+
+        public Set<String> getExcludedAttrs() {
+            return excludedAttrs;
+        }
+
+        public void addExcludedAttr(final String attr) {
+            excludedAttrs.add(attr);
+        }
+
+        public Set<String> getIncludeOnlyAttrs() {
+            return includeOnlyAttrs;
+        }
+
+        public void addIncludeOnlyAttribute(final String attr) {
+            includeOnlyAttrs.add(attr);
+        }
+
+    }
+
 }
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 e31a537..918e4c4 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
@@ -41,6 +41,12 @@ public class AbstractClientAppTest extends AbstractTest {
 
         AllowedAttrReleasePolicyConf conf = new AllowedAttrReleasePolicyConf();
         conf.getAllowedAttrs().addAll(List.of("cn", "givenName"));
+
+        AllowedAttrReleasePolicyConf.ConsentPolicy consentPolicy = conf.new 
ConsentPolicy();
+        consentPolicy.setStatus(Boolean.TRUE);
+        consentPolicy.getIncludeOnlyAttrs().addAll(Set.of("cn"));
+        conf.setConsentPolicy(consentPolicy);
+
         attrRelPolicy.setConf(conf);
 
         return policyDAO.save(attrRelPolicy);
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 7a14685..a1cae8f 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
@@ -227,12 +227,19 @@ public class PolicyTest extends AbstractTest {
 
         AllowedAttrReleasePolicyConf attrReleasePolicyConf = new 
AllowedAttrReleasePolicyConf();
         attrReleasePolicyConf.getAllowedAttrs().addAll(List.of("*"));
+
+        AllowedAttrReleasePolicyConf.ConsentPolicy consentPolicy = 
attrReleasePolicyConf.new ConsentPolicy();
+        consentPolicy.setStatus(Boolean.TRUE);
+        consentPolicy.getIncludeOnlyAttrs().addAll(Set.of("cn"));
+        attrReleasePolicyConf.setConsentPolicy(consentPolicy);
         attrReleasePolicy.setConf(attrReleasePolicyConf);
 
         attrReleasePolicy = policyDAO.save(attrReleasePolicy);
 
         assertNotNull(attrReleasePolicy);
         assertNotNull(attrReleasePolicy.getKey());
+        assertNotNull(((AllowedAttrReleasePolicyConf) 
attrReleasePolicy.getConf()).getAllowedAttrs());
+        assertNotNull(((AllowedAttrReleasePolicyConf) 
attrReleasePolicy.getConf()).getConsentPolicy());
 
         afterCount = policyDAO.findAll().size();
         assertEquals(afterCount, beforeCount + 1);
diff --git 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
index 726bb25..b4bac44 100644
--- 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
+++ 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/AbstractITCase.java
@@ -848,6 +848,12 @@ public abstract class AbstractITCase {
 
         AllowedAttrReleasePolicyConf conf = new AllowedAttrReleasePolicyConf();
         conf.getAllowedAttrs().addAll(List.of("cn", "givenName"));
+        
+        AllowedAttrReleasePolicyConf.ConsentPolicy consentPolicy = conf.new 
ConsentPolicy();
+        consentPolicy.setStatus(Boolean.TRUE);
+        consentPolicy.getIncludeOnlyAttrs().addAll(Set.of("cn"));
+        conf.setConsentPolicy(consentPolicy);
+        
         policy.setConf(conf);
 
         return policy;
diff --git 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
index 6721fd2..1e0162c 100644
--- 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
+++ 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/PolicyITCase.java
@@ -283,6 +283,7 @@ public class PolicyITCase extends AbstractITCase {
         assertTrue(policyConf.getAllowedAttrs().contains("cn"));
         assertTrue(policyConf.getAllowedAttrs().contains("postalCode"));
         assertTrue(policyConf.getAllowedAttrs().contains("givenName"));
+        
assertTrue(policyConf.getConsentPolicy().getIncludeOnlyAttrs().contains("cn"));
     }
 
     @Test
diff --git 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/RealmITCase.java 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/RealmITCase.java
index efdb83a..a2d196a 100644
--- 
a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/RealmITCase.java
+++ 
b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/RealmITCase.java
@@ -299,6 +299,10 @@ public class RealmITCase extends AbstractITCase {
         AllowedAttrReleasePolicyConf ruleConf = new 
AllowedAttrReleasePolicyConf();
         ruleConf.getAllowedAttrs().addAll(List.of("cn", "givenName"));
 
+        AllowedAttrReleasePolicyConf.ConsentPolicy consentPolicy1 = 
ruleConf.new ConsentPolicy();
+        consentPolicy1.getIncludeOnlyAttrs().addAll(Set.of("cn"));
+        ruleConf.setConsentPolicy(consentPolicy1);
+
         AttrReleasePolicyTO policy = new AttrReleasePolicyTO();
         policy.setDescription("Test Attribute Release policy");
         policy.setConf(ruleConf);
diff --git 
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
 
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
index b243ba6..9cdece1 100644
--- 
a/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
+++ 
b/wa/starter/src/main/java/org/apache/syncope/wa/starter/mapping/AllowedAttrReleaseMapper.java
@@ -22,7 +22,10 @@ import 
org.apache.syncope.common.lib.policy.AllowedAttrReleasePolicyConf;
 import org.apache.syncope.common.lib.policy.AttrReleasePolicyConf;
 import org.apereo.cas.services.DenyAllAttributeReleasePolicy;
 import org.apereo.cas.services.RegisteredServiceAttributeReleasePolicy;
+import org.apereo.cas.services.RegisteredServiceConsentPolicy;
 import org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy;
+import org.apereo.cas.services.consent.DefaultRegisteredServiceConsentPolicy;
+import org.apereo.cas.util.model.TriStateBoolean;
 import org.springframework.stereotype.Component;
 
 @AttrReleaseMapFor(attrReleasePolicyConfClass = 
AllowedAttrReleasePolicyConf.class)
@@ -40,6 +43,16 @@ public class AllowedAttrReleaseMapper implements 
AttrReleaseMapper {
             attributeReleasePolicy = new ReturnAllowedAttributeReleasePolicy();
             ((ReturnAllowedAttributeReleasePolicy) attributeReleasePolicy).
                     setAllowedAttributes((aarpc.getAllowedAttrs()));
+
+            if (aarpc.getConsentPolicy() != null) {
+                RegisteredServiceConsentPolicy consentPolicy =
+                        new 
DefaultRegisteredServiceConsentPolicy(aarpc.getConsentPolicy().getExcludedAttrs(),
+                                
aarpc.getConsentPolicy().getIncludeOnlyAttrs());
+                ((DefaultRegisteredServiceConsentPolicy) 
consentPolicy).setStatus(
+                        aarpc.getConsentPolicy().getStatus() == null ? 
TriStateBoolean.UNDEFINED
+                        : 
TriStateBoolean.fromBoolean(aarpc.getConsentPolicy().getStatus()));
+                ((ReturnAllowedAttributeReleasePolicy) 
attributeReleasePolicy).setConsentPolicy(consentPolicy);
+            }
         }
 
         return attributeReleasePolicy;

Reply via email to