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  
20  package org.apache.wss4j.dom.validate;
21  
22  import java.security.Principal;
23  import java.security.PublicKey;
24  import java.security.cert.X509Certificate;
25  
26  import javax.security.auth.Subject;
27  
28  import org.apache.wss4j.common.saml.SamlAssertionWrapper;
29  import org.apache.wss4j.common.token.BinarySecurity;
30  import org.apache.wss4j.dom.message.token.SecurityContextToken;
31  import org.apache.wss4j.dom.message.token.Timestamp;
32  import org.apache.wss4j.dom.message.token.UsernameToken;
33  
34  /**
35   * This class stores various Credential types that can be validated and/or returned by a
36   * Validator implementation. It also stores an optional Principal object which can provide
37   * context information to the validators.
38   */
39  public class Credential {
40  
41      private PublicKey publicKey;
42      private X509Certificate[] certs;
43      private Timestamp timestamp;
44      private UsernameToken usernametoken;
45      private BinarySecurity binarySecurityToken;
46      private SamlAssertionWrapper samlAssertion;
47      private SamlAssertionWrapper transformedToken;
48      private SecurityContextToken securityContextToken;
49      private Principal principal;
50      private byte[] secretKey;
51      private Subject subject;
52      private Object delegationCredential;
53  
54      /**
55       * Set a SecurityContextToken to be validated
56       * @param securityContextToken a SecurityContextToken to be validated
57       */
58      public void setSecurityContextToken(SecurityContextToken securityContextToken) {
59          this.securityContextToken = securityContextToken;
60      }
61  
62      /**
63       * Get a SecurityContextToken to be validated
64       * @return a SecurityContextToken to be validated
65       */
66      public SecurityContextToken getSecurityContextToken() {
67          return securityContextToken;
68      }
69  
70      /**
71       * Set a SecretKey (byte[]) to be validated
72       * @param secretKey a SecretKey (byte) to be validated
73       */
74      public void setSecretKey(byte[] secretKey) {
75          this.secretKey = secretKey;
76      }
77  
78      /**
79       * Get a SecretKey (byte[]) to be validated
80       * @return a SecretKey (byte[]) to be validated
81       */
82      public byte[] getSecretKey() {
83          return secretKey;
84      }
85  
86  
87      /**
88       * Set a PublicKey to be validated
89       * @param publicKey a PublicKey to be validated
90       */
91      public void setPublicKey(PublicKey publicKey) {
92          this.publicKey = publicKey;
93      }
94  
95      /**
96       * Get a PublicKey to be validated
97       * @return a PublicKey to be validated
98       */
99      public PublicKey getPublicKey() {
100         return publicKey;
101     }
102 
103     /**
104      * Set an X509Certificate chain to be validated
105      * @param certs an X509Certificate chain to be validated
106      */
107     public void setCertificates(X509Certificate[] certs) {
108         this.certs = certs;
109     }
110 
111     /**
112      * Get an X509Certificate chain to be validated
113      * @return an X509Certificate chain to be validated
114      */
115     public X509Certificate[] getCertificates() {
116         return certs;
117     }
118 
119     /**
120      * Set a Timestamp to be validated
121      * @param timestamp a Timestamp to be validated
122      */
123     public void setTimestamp(Timestamp timestamp) {
124         this.timestamp = timestamp;
125     }
126 
127     /**
128      * Get a Timestamp to be validated
129      * @return a Timestamp to be validated
130      */
131     public Timestamp getTimestamp() {
132         return timestamp;
133     }
134 
135     /**
136      * Set a UsernameToken to be validated
137      * @param usernametoken a UsernameToken to be validated
138      */
139     public void setUsernametoken(UsernameToken usernametoken) {
140         this.usernametoken = usernametoken;
141     }
142 
143     /**
144      * Get a UsernameToken to be validated
145      * @return a UsernameToken to be validated
146      */
147     public UsernameToken getUsernametoken() {
148         return usernametoken;
149     }
150 
151     /**
152      * Set the BinarySecurityToken to be validated
153      * @param binarySecurityToken the BinarySecurityToken to be validated
154      */
155     public void setBinarySecurityToken(BinarySecurity binarySecurityToken) {
156         this.binarySecurityToken = binarySecurityToken;
157     }
158 
159     /**
160      * Get the BinarySecurityToken to be validated
161      * @return the BinarySecurityToken to be validated
162      */
163     public BinarySecurity getBinarySecurityToken() {
164         return binarySecurityToken;
165     }
166 
167     /**
168      * Set an SamlAssertionWrapper to be validated
169      * @param samlAssertion an SamlAssertionWrapper to be validated
170      */
171     public void setSamlAssertion(SamlAssertionWrapper samlAssertion) {
172         this.samlAssertion = samlAssertion;
173     }
174 
175     /**
176      * Get an SamlAssertionWrapper to be validated
177      * @return an SamlAssertionWrapper to be validated
178      */
179     public SamlAssertionWrapper getSamlAssertion() {
180         return samlAssertion;
181     }
182 
183     /**
184      * Set an SamlAssertionWrapper instance which corresponds to a Transformed Token.
185      * @param transformedToken a transformed SamlAssertionWrapper instance
186      */
187     public void setTransformedToken(SamlAssertionWrapper transformedToken) {
188         this.transformedToken = transformedToken;
189     }
190 
191     /**
192      * Get an SamlAssertionWrapper instance which corresponds to a Transformed Token.
193      * @return a transformed SamlAssertionWrapper instance
194      */
195     public SamlAssertionWrapper getTransformedToken() {
196         return transformedToken;
197     }
198 
199     /**
200      * Set the principal that supplies context information to the validators.
201      * @param principal the principal that supplies context information to the validators
202      */
203     public void setPrincipal(Principal principal) {
204         this.principal = principal;
205     }
206 
207     /**
208      * Get the principal
209      * @return the principal
210      */
211     public Principal getPrincipal() {
212         return principal;
213     }
214 
215     /**
216      * Set the subject that may result from the Validation process
217      * @param subject the subject that may result from the Validation process
218      */
219     public void setSubject(Subject subject) {
220         this.subject = subject;
221     }
222 
223     /**
224      * Get the subject that may result from the Validation process
225      * @return the subject that may result from the Validation process
226      */
227     public Subject getSubject() {
228         return subject;
229     }
230 
231     public Object getDelegationCredential() {
232         return delegationCredential;
233     }
234 
235     public void setDelegationCredential(Object delegationCredential) {
236         this.delegationCredential = delegationCredential;
237     }
238 
239 }