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.attribute.encoding.provider;
19  
20  import org.opensaml.Configuration;
21  import org.opensaml.common.SAMLObjectBuilder;
22  import org.opensaml.saml2.core.Attribute;
23  import org.opensaml.saml2.core.impl.AttributeBuilder;
24  
25  import edu.internet2.middleware.shibboleth.common.attribute.encoding.SAML2AttributeEncoder;
26  
27  /**
28   * Base for encoders that produce {@link Attribute}s.
29   */
30  public abstract class AbstractSAML2AttributeEncoder extends AbstractAttributeEncoder<Attribute> implements
31          SAML2AttributeEncoder {
32  
33      /** Builder for SAML 2 attribute XMLObjects. */
34      protected final SAMLObjectBuilder<Attribute> attributeBuilder;
35  
36      /** Format of attribute. */
37      private String format;
38  
39      /** Friendly name of attribute. */
40      private String friendlyName;
41  
42      /** Constructor. */
43      protected AbstractSAML2AttributeEncoder() {
44          attributeBuilder = (AttributeBuilder) Configuration.getBuilderFactory().getBuilder(
45                  Attribute.DEFAULT_ELEMENT_NAME);
46      }
47  
48      /** {@inheritDoc} */
49      public String getNameFormat() {
50          return format;
51      }
52  
53      /** {@inheritDoc} */
54      public String getFriendlyName() {
55          return friendlyName;
56      }
57  
58      /** {@inheritDoc} */
59      public void setNameFormat(String newFormat) {
60          format = newFormat;
61      }
62  
63      /** {@inheritDoc} */
64      public void setFriendlyName(String name) {
65          friendlyName = name;
66      }
67  
68      /**
69       * Populates the attribute with attribute name, name format, and friendly name information.
70       * 
71       * @param attribute to populate
72       */
73      protected void populateAttribute(Attribute attribute) {
74          attribute.setName(getAttributeName());
75          attribute.setNameFormat(getNameFormat());
76          attribute.setFriendlyName(getFriendlyName());
77      }
78  }