View Javadoc

1   /*
2    * Copyright [2007] [University Corporation for Advanced Internet Development, Inc.]
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.internet2.middleware.shibboleth.common.attribute.encoding.provider;
18  
19  import org.opensaml.Configuration;
20  import org.opensaml.common.SAMLObjectBuilder;
21  import org.opensaml.saml2.core.Attribute;
22  import org.opensaml.saml2.core.impl.AttributeBuilder;
23  
24  import edu.internet2.middleware.shibboleth.common.attribute.encoding.SAML2AttributeEncoder;
25  
26  /**
27   * Base for encoders that produce {@link Attribute}s.
28   */
29  public abstract class AbstractSAML2AttributeEncoder extends AbstractAttributeEncoder<Attribute> implements
30          SAML2AttributeEncoder {
31  
32      /** Builder for SAML 2 attribute XMLObjects. */
33      protected final SAMLObjectBuilder<Attribute> attributeBuilder;
34  
35      /** Format of attribute. */
36      private String format;
37  
38      /** Friendly name of attribute. */
39      private String friendlyName;
40  
41      /** Constructor. */
42      protected AbstractSAML2AttributeEncoder() {
43          attributeBuilder = (AttributeBuilder) Configuration.getBuilderFactory().getBuilder(
44                  Attribute.DEFAULT_ELEMENT_NAME);
45      }
46  
47      /** {@inheritDoc} */
48      public String getNameFormat() {
49          return format;
50      }
51  
52      /** {@inheritDoc} */
53      public String getFriendlyName() {
54          return friendlyName;
55      }
56  
57      /** {@inheritDoc} */
58      public void setNameFormat(String newFormat) {
59          format = newFormat;
60      }
61  
62      /** {@inheritDoc} */
63      public void setFriendlyName(String name) {
64          friendlyName = name;
65      }
66  
67      /**
68       * Populates the attribute with attribute name, name format, and friendly name information.
69       * 
70       * @param attribute to populate
71       */
72      protected void populateAttribute(Attribute attribute) {
73          attribute.setName(getAttributeName());
74          attribute.setNameFormat(getNameFormat());
75          attribute.setFriendlyName(getFriendlyName());
76      }
77  }