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.str;
21
22 import java.security.Principal;
23 import java.security.PublicKey;
24 import java.security.cert.X509Certificate;
25
26 import org.apache.wss4j.dom.str.STRParser.REFERENCE_TYPE;
27
28 /**
29 * This class holds the results from parsing a SecurityTokenReference Element by a STRParser implementation.
30 */
31 public class STRParserResult {
32
33 private X509Certificate[] certs;
34
35 private byte[] secretKey;
36
37 private PublicKey publicKey;
38
39 private Principal principal;
40
41 private boolean trustedCredential;
42
43 private REFERENCE_TYPE referenceType;
44
45 /**
46 * Get the X509Certificates associated with this SecurityTokenReference
47 * @return the X509Certificates associated with this SecurityTokenReference
48 */
49 public X509Certificate[] getCertificates() {
50 return certs;
51 }
52
53 /**
54 * Get the Principal associated with this SecurityTokenReference
55 * @return the Principal associated with this SecurityTokenReference
56 */
57 public Principal getPrincipal() {
58 if (principal == null && certs != null && certs.length > 0) {
59 principal = certs[0].getSubjectX500Principal();
60 }
61
62 return principal;
63 }
64
65 /**
66 * Get the PublicKey associated with this SecurityTokenReference
67 * @return the PublicKey associated with this SecurityTokenReference
68 */
69 public PublicKey getPublicKey() {
70 return publicKey;
71 }
72
73 /**
74 * Get the Secret Key associated with this SecurityTokenReference
75 * @return the Secret Key associated with this SecurityTokenReference
76 */
77 public byte[] getSecretKey() {
78 return secretKey;
79 }
80
81 /**
82 * Get whether the returned credential is already trusted or not. This is currently
83 * applicable in the case of a credential extracted from a trusted HOK SAML Assertion,
84 * and a BinarySecurityToken that has been processed by a Validator. In these cases,
85 * the SignatureProcessor does not need to verify trust on the credential.
86 * @return true if trust has already been verified on the returned Credential
87 */
88 public boolean isTrustedCredential() {
89 return trustedCredential;
90 }
91
92 /**
93 * Get how the certificates were referenced
94 * @return how the certificates were referenced
95 */
96 public REFERENCE_TYPE getCertificatesReferenceType() {
97 return referenceType;
98 }
99
100 public void setCerts(X509Certificate[] certs) {
101 this.certs = certs;
102 }
103
104 public void setSecretKey(byte[] secretKey) {
105 this.secretKey = secretKey;
106 }
107
108 public void setPublicKey(PublicKey publicKey) {
109 this.publicKey = publicKey;
110 }
111
112 public void setPrincipal(Principal principal) {
113 this.principal = principal;
114 }
115
116 public void setTrustedCredential(boolean trustedCredential) {
117 this.trustedCredential = trustedCredential;
118 }
119
120 public void setReferenceType(REFERENCE_TYPE referenceType) {
121 this.referenceType = referenceType;
122 }
123
124
125 }