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.xml.signature.impl;
18  
19  import java.util.LinkedList;
20  import java.util.List;
21  
22  import org.apache.xml.security.signature.XMLSignature;
23  import org.opensaml.xml.AbstractXMLObject;
24  import org.opensaml.xml.XMLObject;
25  import org.opensaml.xml.security.credential.Credential;
26  import org.opensaml.xml.signature.ContentReference;
27  import org.opensaml.xml.signature.KeyInfo;
28  import org.opensaml.xml.signature.Signature;
29  
30  /**
31   * XMLObject representing an enveloped or detached XML Digital Signature, version 20020212, Signature element.
32   */
33  public class SignatureImpl extends AbstractXMLObject implements Signature {
34      
35      /** Canonicalization algorithm used in signature. */
36      private String canonicalizationAlgorithm;
37      
38      /** Algorithm used to generate the signature. */
39      private String signatureAlgorithm;
40      
41      /** Optional HMAC output length parameter to the signature algorithm. */
42      private Integer hmacOutputLength;
43      
44      /** Key used to sign the signature. */
45      private Credential signingCredential;
46      
47      /** Public key information to embed in the signature. */
48      private KeyInfo keyInfo;
49      
50      /** References to content to be signed. */
51      private List<ContentReference> contentReferences;
52      
53      /** Constructed Apache XML Security signature object. */
54      private XMLSignature xmlSignature;
55      
56      /**
57       * Constructor.
58       * 
59       * @param namespaceURI the namespace the element is in
60       * @param elementLocalName the local name of the XML element this Object represents
61       * @param namespacePrefix the prefix for the given namespace
62       */
63      protected SignatureImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
64          super(namespaceURI, elementLocalName, namespacePrefix);
65          contentReferences = new LinkedList<ContentReference>();
66      }
67  
68      /** {@inheritDoc} */
69      public String getCanonicalizationAlgorithm() {
70          return canonicalizationAlgorithm;
71      }
72  
73      /** {@inheritDoc} */
74      public void setCanonicalizationAlgorithm(String newAlgorithm) {
75          canonicalizationAlgorithm = prepareForAssignment(canonicalizationAlgorithm, newAlgorithm);
76      }
77  
78      /** {@inheritDoc} */
79      public String getSignatureAlgorithm() {
80          return signatureAlgorithm;
81      }
82  
83      /** {@inheritDoc} */
84      public void setSignatureAlgorithm(String newAlgorithm) {
85          signatureAlgorithm  = prepareForAssignment(signatureAlgorithm, newAlgorithm);
86      }
87  
88      /** {@inheritDoc} */
89      public Integer getHMACOutputLength() {
90          return hmacOutputLength;
91      }
92  
93      /** {@inheritDoc} */
94      public void setHMACOutputLength(Integer length) {
95          hmacOutputLength = prepareForAssignment(hmacOutputLength, length);
96      }
97  
98      /** {@inheritDoc} */
99      public Credential getSigningCredential() {
100         return signingCredential;
101     }
102 
103     /** {@inheritDoc} */
104     public void setSigningCredential(Credential newCredential) {
105         signingCredential = prepareForAssignment(signingCredential, newCredential);
106     }
107 
108     /** {@inheritDoc} */
109     public KeyInfo getKeyInfo() {
110         return keyInfo;
111     }
112 
113     /** {@inheritDoc} */
114     public void setKeyInfo(KeyInfo newKeyInfo) {
115         keyInfo = prepareForAssignment(keyInfo, newKeyInfo);
116     }
117 
118     /** {@inheritDoc} */
119     public List<ContentReference> getContentReferences() {
120         // TODO worry about detecting changes and releasing this object's and parent's DOM?
121         // would need something like an Observable list/collection impl or something similar
122         return contentReferences;
123     }
124 
125     /** {@inheritDoc} */
126     public List<XMLObject> getOrderedChildren() {
127         // Children
128         return null;
129     }
130     
131     /** {@inheritDoc} */
132     public void releaseDOM() {
133         super.releaseDOM();
134         xmlSignature = null;
135     }
136 
137     /**
138      * Get the Apache XML Security signature instance held by this object.
139      * 
140      * @return an Apache XML Security signature object
141      */
142     public XMLSignature getXMLSignature(){
143         return xmlSignature;
144     }
145     
146     /**
147      * Set the Apache XML Security signature instance held by this object.
148      * 
149      * @param signature an Apache XML Security signature object
150      */
151     public void setXMLSignature(XMLSignature signature){
152         xmlSignature = prepareForAssignment(xmlSignature, signature);
153     }
154 }