View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.common.lib.policy;
20  
21  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
22  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
23  import java.io.Serializable;
24  import java.util.ArrayList;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.concurrent.TimeUnit;
29  
30  public class DefaultAttrReleasePolicyConf implements AttrReleasePolicyConf {
31  
32      private static final long serialVersionUID = -1969836661359025380L;
33  
34      public enum PrincipalAttrRepoMergingStrategy {
35          /**
36           * Replace attributes. Overwrites existing attribute values, if any.
37           */
38          REPLACE,
39          /**
40           * Add attributes.
41           * Retains existing attribute values if any, and ignores values from subsequent sources in the resolution chain.
42           */
43          ADD,
44          /**
45           * No merging.
46           * Doesn't merge attributes, ignores attributes from non-authentication attribute repositories.
47           */
48          NONE,
49          /**
50           * Multivalued attributes.
51           * Combines all values into a single attribute, essentially creating a multi-valued attribute.
52           */
53          MULTIVALUED;
54  
55      }
56  
57      public static class PrincipalAttrRepoConf implements Serializable {
58  
59          private static final long serialVersionUID = 6369987956789092057L;
60  
61          private PrincipalAttrRepoMergingStrategy mergingStrategy = PrincipalAttrRepoMergingStrategy.MULTIVALUED;
62  
63          private boolean ignoreResolvedAttributes;
64  
65          private long expiration;
66  
67          private TimeUnit timeUnit = TimeUnit.HOURS;
68  
69          private final List<String> attrRepos = new ArrayList<>();
70  
71          public PrincipalAttrRepoMergingStrategy getMergingStrategy() {
72              return mergingStrategy;
73          }
74  
75          public void setMergingStrategy(final PrincipalAttrRepoMergingStrategy mergingStrategy) {
76              this.mergingStrategy = mergingStrategy;
77          }
78  
79          public boolean isIgnoreResolvedAttributes() {
80              return ignoreResolvedAttributes;
81          }
82  
83          public void setIgnoreResolvedAttributes(final boolean ignoreResolvedAttributes) {
84              this.ignoreResolvedAttributes = ignoreResolvedAttributes;
85          }
86  
87          public long getExpiration() {
88              return expiration;
89          }
90  
91          public void setExpiration(final long expiration) {
92              this.expiration = expiration;
93          }
94  
95          public TimeUnit getTimeUnit() {
96              return timeUnit;
97          }
98  
99          public void setTimeUnit(final TimeUnit timeUnit) {
100             this.timeUnit = timeUnit;
101         }
102 
103         @JacksonXmlElementWrapper(localName = "attrRepos")
104         @JacksonXmlProperty(localName = "attrRepo")
105         public List<String> getAttrRepos() {
106             return attrRepos;
107         }
108     }
109 
110     private final Map<String, Object> releaseAttrs = new HashMap<>();
111 
112     /**
113      * Specify the list of allowed attribute to release.
114      * Use the special {@code *} to release everything.
115      */
116     private final List<String> allowedAttrs = new ArrayList<>();
117 
118     private final List<String> excludedAttrs = new ArrayList<>();
119 
120     private final List<String> includeOnlyAttrs = new ArrayList<>();
121 
122     private String principalIdAttr;
123 
124     private final PrincipalAttrRepoConf principalAttrRepoConf = new PrincipalAttrRepoConf();
125 
126     public Map<String, Object> getReleaseAttrs() {
127         return releaseAttrs;
128     }
129 
130     @JacksonXmlElementWrapper(localName = "allowedAttrs")
131     @JacksonXmlProperty(localName = "allowedAttr")
132     public List<String> getAllowedAttrs() {
133         return allowedAttrs;
134     }
135 
136     @JacksonXmlElementWrapper(localName = "excludedAttrs")
137     @JacksonXmlProperty(localName = "excludedAttr")
138     public List<String> getExcludedAttrs() {
139         return excludedAttrs;
140     }
141 
142     @JacksonXmlElementWrapper(localName = "includeOnlyAttrs")
143     @JacksonXmlProperty(localName = "includeOnlyAttr")
144     public List<String> getIncludeOnlyAttrs() {
145         return includeOnlyAttrs;
146     }
147 
148     public String getPrincipalIdAttr() {
149         return principalIdAttr;
150     }
151 
152     public void setPrincipalIdAttr(final String principalIdAttr) {
153         this.principalIdAttr = principalIdAttr;
154     }
155 
156     public PrincipalAttrRepoConf getPrincipalAttrRepoConf() {
157         return principalAttrRepoConf;
158     }
159 }