View Javadoc

1   /*
2    * The MIT License
3    *
4    * Original work sponsored and donated by National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
5    *
6    * Copyright (C) 2011 National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   *
26   * $HeadURL$
27   * $Id$
28   */
29  
30  package dk.sosi.seal.model;
31  
32  
33  import org.w3c.dom.Node;
34  
35  /**
36   *
37   * A simple class holding configuration parameters when generating XML signatures using @link{SignatureUtil}
38   *
39   * @author $LastChangedBy:$ $LastChangedDate:$
40   * @version $Revision:$
41   */
42  public class SignatureConfiguration {
43  
44      static enum Type { DIRECT_REFERENCE, SECURITY_TOKEN_REFERENCE }
45  
46      static class Reference {
47  
48          private final String uri;
49          private final Type type;
50  
51          public Reference(String uri, Type type) {
52              this.uri = uri;
53              this.type = type;
54          }
55  
56          private static Reference[] fromDirectReferenceStringArray(String[] referenceURIs) {
57              Reference[] references = new Reference[referenceURIs.length];
58              for (int i = 0; i < referenceURIs.length; i++) {
59                  references[i] = new Reference(referenceURIs[i], Type.DIRECT_REFERENCE);
60              }
61              return references;
62          }
63  
64          public String getURI() {
65              return uri;
66          }
67  
68          public Type getType() {
69              return type;
70          }
71      }
72  
73      private final Reference[] references;
74      private final String signatureParentID;
75      private final String idAttributeName;
76  
77      private boolean addCertAsRef;
78      private Node signatureSiblingNode;
79      private String keyInfoId;
80  
81      public SignatureConfiguration(Reference[] references, String signatureParentID, String idAttributeName) {
82          this.references = references;
83          this.signatureParentID = signatureParentID;
84          this.idAttributeName = idAttributeName;
85          this.addCertAsRef = false;
86      }
87  
88      public SignatureConfiguration(String[] referenceURIs, String signatureParentID, String idAttributeName) {
89          this(Reference.fromDirectReferenceStringArray(referenceURIs), signatureParentID, idAttributeName);
90      }
91  
92      public void setAddCertificateAsReference(boolean addCertAsRef) {
93          this.addCertAsRef = addCertAsRef;
94      }
95  
96      public void setSignatureSiblingNode(Node signatureSiblingNode) {
97          this.signatureSiblingNode = signatureSiblingNode;
98      }
99  
100     public void setKeyInfoId(String keyInfoId) {
101         this.keyInfoId = keyInfoId;
102     }
103 
104     public Reference[] getReferences() {
105         return references;
106     }
107 
108     public String getSignatureParentID() {
109         return signatureParentID;
110     }
111 
112     public boolean isAddCertificateAsReference() {
113         return addCertAsRef;
114     }
115 
116     public Node getSignatureSiblingNode() {
117         return signatureSiblingNode;
118     }
119 
120     public String getIdAttributeName() {
121         return idAttributeName;
122     }
123 
124     public String getKeyInfoId() {
125         return keyInfoId;
126     }
127 }