View Javadoc

1   /*
2    * Licensed to the University Corporation for Advanced Internet Development, 
3    * Inc. (UCAID) under one or more contributor license agreements.  See the 
4    * NOTICE file distributed with this work for additional information regarding
5    * copyright ownership. The UCAID licenses this file to You under the Apache 
6    * License, Version 2.0 (the "License"); you may not use this file except in 
7    * compliance with the License.  You may obtain a copy of the License at
8    *
9    *    http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package edu.internet2.middleware.shibboleth.common.config.attribute.resolver.attributeDefinition;
19  
20  import java.util.List;
21  import java.util.Locale;
22  import java.util.Map;
23  
24  import org.opensaml.xml.util.DatatypeHelper;
25  
26  import edu.internet2.middleware.shibboleth.common.attribute.encoding.AttributeEncoder;
27  import edu.internet2.middleware.shibboleth.common.attribute.resolver.provider.attributeDefinition.BaseAttributeDefinition;
28  import edu.internet2.middleware.shibboleth.common.config.attribute.resolver.AbstractResolutionPluginFactoryBean;
29  
30  /**
31   * Base Spring factory bean that produces attribute definitions.
32   */
33  public abstract class BaseAttributeDefinitionFactoryBean extends AbstractResolutionPluginFactoryBean {
34  
35      /** Attribute ID of the source attribute. */
36      private String sourceAttributeId;
37  
38      /** Whether attributes produced by the definition should be released outside the resolver. */
39      private boolean dependencyOnly;
40  
41      /** Encoders for the attributes. */
42      private List<AttributeEncoder> attributeEncoders;
43  
44      /** Localized human intelligible attribute name. */
45      private Map<Locale, String> displayNames;
46  
47      /** Localized human readable description of attribute. */
48      private Map<Locale, String> displayDescriptions;
49  
50      /**
51       * Gets the encoders for the attributes.
52       * 
53       * @return encoders for the attributes
54       */
55      public List<AttributeEncoder> getAttributeEncoders() {
56          return attributeEncoders;
57      }
58  
59      /**
60       * Gets the localized human readable description of attribute.
61       * 
62       * @return human readable description of attribute
63       */
64      public Map<Locale, String> getDisplayDescriptions() {
65          return displayDescriptions;
66      }
67  
68      /**
69       * Gets the localized human readable name of the attribute.
70       * 
71       * @return human readable name of the attribute
72       */
73      public Map<Locale, String> getDisplayNames() {
74          return displayNames;
75      }
76  
77      /**
78       * Gets the ID of the attribute that serves as the source of information for the attribute definition.
79       * 
80       * @return ID of the attribute that serves as the source of information for the attribute definition
81       */
82      public String getSourceAttributeId() {
83          return sourceAttributeId;
84      }
85  
86      /**
87       * Gets whether attributes produced by the definition should be released outside the resolver.
88       * 
89       * @return whether attributes produced by the definition should be released outside the resolver
90       */
91      public boolean isDependencyOnly() {
92          return dependencyOnly;
93      }
94  
95      /**
96       * Populates the attribute definition with information from this factory.
97       * 
98       * @param definition attribute definition to populate
99       */
100     protected void populateAttributeDefinition(BaseAttributeDefinition definition) {
101         definition.setDependencyOnly(isDependencyOnly());
102 
103         if (getDisplayNames() != null) {
104             definition.getDisplayNames().putAll(getDisplayNames());
105         }
106 
107         if (getDisplayDescriptions() != null) {
108             definition.getDisplayDescriptions().putAll(getDisplayDescriptions());
109         }
110 
111         if (getDependencyIds() != null) {
112             definition.getDependencyIds().addAll(getDependencyIds());
113         }
114 
115         if (getAttributeEncoders() != null) {
116             definition.getAttributeEncoders().addAll(getAttributeEncoders());
117         }
118 
119         definition.setId(getPluginId());
120         definition.setSourceAttributeID(getSourceAttributeId());
121     }
122 
123     /**
124      * Sets the encoders for the attributes.
125      * 
126      * @param encoders encoders for the attributes
127      */
128     public void setAttributeEncoders(List<AttributeEncoder> encoders) {
129         attributeEncoders = encoders;
130     }
131 
132     /**
133      * Sets whether attributes produced by the definition should be released outside the resolver.
134      * 
135      * @param isDependencyOnly whether attributes produced by the definition should be released outside the resolver
136      */
137     public void setDependencyOnly(boolean isDependencyOnly) {
138         dependencyOnly = isDependencyOnly;
139     }
140 
141     /**
142      * Sets the human readable description of attribute.
143      * 
144      * @param descriptions human readable descriptions of attribute
145      */
146     public void setDisplayDescriptions(Map<Locale, String> descriptions) {
147         displayDescriptions = descriptions;
148     }
149 
150     /**
151      * Sets the human readable name of the attribute.
152      * 
153      * @param names human readable names of the attribute
154      */
155     public void setDisplayNames(Map<Locale, String> names) {
156         displayNames = names;
157     }
158 
159     /**
160      * Sets the ID of the attribute that serves as the source of information for the attribute definition.
161      * 
162      * @param id ID of the attribute that serves as the source of information for the attribute definition
163      */
164     public void setSourceAttributeId(String id) {
165         sourceAttributeId = DatatypeHelper.safeTrimOrNullString(id);
166     }
167 }