View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.wss4j.common;
20  
21  import java.security.cert.X509Certificate;
22  import java.util.ArrayList;
23  import java.util.List;
24  import java.util.Properties;
25  
26  import org.apache.wss4j.common.crypto.Crypto;
27  import org.apache.wss4j.common.crypto.CryptoFactory;
28  import org.apache.wss4j.common.ext.WSSecurityException;
29  import org.apache.wss4j.common.util.Loader;
30  import org.w3c.dom.Element;
31  
32  /**
33   * This abstract class encapsulates configuration for Signature + Encryption Actions.
34   */
35  public abstract class SignatureEncryptionActionToken implements SecurityActionToken {
36  
37      private static final org.slf4j.Logger LOG =
38          org.slf4j.LoggerFactory.getLogger(SignatureEncryptionActionToken.class);
39  
40      private X509Certificate certificate;
41      private byte[] key;
42      private String user;
43      private Element keyInfoElement;
44      private Crypto crypto;
45      private String keyIdentifier;
46      private int keyIdentifierId;
47      private String digestAlgorithm;
48      private List<WSEncryptionPart> parts = new ArrayList<>();
49      private String optionalParts;
50      private String cryptoProperties;
51      private String tokenType;
52      private String tokenId;
53      private String sha1Value;
54      private String derivedKeyTokenReference;
55      private int derivedKeyLength;
56      private int derivedKeyIdentifier;
57      private boolean includeToken;
58  
59      public X509Certificate getCertificate() {
60          return certificate;
61      }
62      public void setCertificate(X509Certificate certificate) {
63          this.certificate = certificate;
64      }
65      public byte[] getKey() {
66          return key;
67      }
68      public void setKey(byte[] key) {
69          this.key = key;
70      }
71      public Element getKeyInfoElement() {
72          return keyInfoElement;
73      }
74      public void setKeyInfoElement(Element keyInfoElement) {
75          this.keyInfoElement = keyInfoElement;
76      }
77      public String getUser() {
78          return user;
79      }
80      public void setUser(String user) {
81          this.user = user;
82      }
83  
84      public synchronized Crypto getCrypto() throws WSSecurityException {
85          if (crypto != null) {
86              return crypto;
87          }
88          if (cryptoProperties != null) {
89              ClassLoader classLoader = null;
90              try {
91                  classLoader = Loader.getTCL();
92              } catch (Exception ex) {
93                  // Ignore
94                  LOG.debug(ex.getMessage(), ex);
95              }
96              Properties properties = CryptoFactory.getProperties(cryptoProperties, classLoader);
97              crypto =
98                  CryptoFactory.getInstance(properties, classLoader, null);
99          }
100         return crypto;
101     }
102 
103     public synchronized void setCrypto(Crypto crypto) {
104         this.crypto = crypto;
105     }
106     public String getKeyIdentifier() {
107         return keyIdentifier;
108     }
109     public void setKeyIdentifier(String keyIdentifier) {
110         this.keyIdentifier = keyIdentifier;
111     }
112     public String getDigestAlgorithm() {
113         return digestAlgorithm;
114     }
115     public void setDigestAlgorithm(String digestAlgorithm) {
116         this.digestAlgorithm = digestAlgorithm;
117     }
118     public String getOptionalParts() {
119         return optionalParts;
120     }
121     public void setOptionalParts(String optionalParts) {
122         this.optionalParts = optionalParts;
123     }
124     public int getKeyIdentifierId() {
125         return keyIdentifierId;
126     }
127     public void setKeyIdentifierId(int keyIdentifierId) {
128         this.keyIdentifierId = keyIdentifierId;
129     }
130     public List<WSEncryptionPart> getParts() {
131         return parts;
132     }
133     public void setParts(List<WSEncryptionPart> parts) {
134         this.parts = parts;
135     }
136 
137     public synchronized void setCryptoProperties(String cryptoProperties) {
138         this.cryptoProperties = cryptoProperties;
139     }
140 
141     public synchronized String getCryptoProperties() {
142         return cryptoProperties;
143     }
144 
145     public String getTokenType() {
146         return tokenType;
147     }
148     public void setTokenType(String tokenType) {
149         this.tokenType = tokenType;
150     }
151     public String getTokenId() {
152         return tokenId;
153     }
154     public void setTokenId(String tokenId) {
155         this.tokenId = tokenId;
156     }
157     public String getSha1Value() {
158         return sha1Value;
159     }
160     public void setSha1Value(String sha1Value) {
161         this.sha1Value = sha1Value;
162     }
163     public String getDerivedKeyTokenReference() {
164         return derivedKeyTokenReference;
165     }
166     public void setDerivedKeyTokenReference(String derivedKeyTokenReference) {
167         this.derivedKeyTokenReference = derivedKeyTokenReference;
168     }
169     public int getDerivedKeyLength() {
170         return derivedKeyLength;
171     }
172     public void setDerivedKeyLength(int derivedKeyLength) {
173         this.derivedKeyLength = derivedKeyLength;
174     }
175     public int getDerivedKeyIdentifier() {
176         return derivedKeyIdentifier;
177     }
178     public void setDerivedKeyIdentifier(int derivedKeyIdentifier) {
179         this.derivedKeyIdentifier = derivedKeyIdentifier;
180     }
181     public boolean isIncludeToken() {
182         return includeToken;
183     }
184     public void setIncludeToken(boolean includeToken) {
185         this.includeToken = includeToken;
186     }
187 }
188