View Javadoc

1   /*
2    * Copyright [2005] [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 org.opensaml.saml2.metadata.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.opensaml.common.impl.AbstractSAMLObject;
24  import org.opensaml.saml2.metadata.EncryptionMethod;
25  import org.opensaml.saml2.metadata.KeyDescriptor;
26  import org.opensaml.xml.XMLObject;
27  import org.opensaml.xml.security.credential.UsageType;
28  import org.opensaml.xml.signature.KeyInfo;
29  import org.opensaml.xml.util.XMLObjectChildrenList;
30  
31  /**
32   * Concrete implementation of {@link org.opensaml.saml2.metadata.KeyDescriptor}.
33   */
34  public class KeyDescriptorImpl extends AbstractSAMLObject implements KeyDescriptor {
35  
36      /** Key usage type. */
37      private UsageType keyUseType;
38  
39      /** Key information. */
40      private KeyInfo keyInfo;
41  
42      /** Encryption methods supported by the entity. */
43      private final XMLObjectChildrenList<EncryptionMethod> encryptionMethods;
44  
45      /**
46       * Constructor.
47       * 
48       * @param namespaceURI the namespace the element is in
49       * @param elementLocalName the local name of the XML element this Object represents
50       * @param namespacePrefix the prefix for the given namespace
51       */
52      protected KeyDescriptorImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
53          super(namespaceURI, elementLocalName, namespacePrefix);
54          encryptionMethods = new XMLObjectChildrenList<EncryptionMethod>(this);
55          keyUseType = UsageType.UNSPECIFIED;
56      }
57  
58      /** {@inheritDoc} */
59      public UsageType getUse() {
60          return keyUseType;
61      }
62  
63      /** {@inheritDoc} */
64      public void setUse(UsageType newType) {
65          if (newType != null) {
66              keyUseType = prepareForAssignment(keyUseType, newType);
67          } else {
68              keyUseType = prepareForAssignment(keyUseType, UsageType.UNSPECIFIED);
69          }
70      }
71  
72      /** {@inheritDoc} */
73      public KeyInfo getKeyInfo() {
74          return keyInfo;
75      }
76  
77      /** {@inheritDoc} */
78      public void setKeyInfo(KeyInfo newKeyInfo) {
79          keyInfo = prepareForAssignment(keyInfo, newKeyInfo);
80      }
81  
82      /** {@inheritDoc} */
83      public List<EncryptionMethod> getEncryptionMethods() {
84          return encryptionMethods;
85      }
86  
87      /** {@inheritDoc} */
88      public List<XMLObject> getOrderedChildren() {
89          ArrayList<XMLObject> children = new ArrayList<XMLObject>();
90  
91          children.add(keyInfo);
92          children.addAll(encryptionMethods);
93  
94          return Collections.unmodifiableList(children);
95      }
96  }