1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.ws.security.message.token;
19
20 import org.apache.ws.security.WSConstants;
21 import org.apache.ws.security.WSSConfig;
22 import org.apache.ws.security.WSSecurityException;
23 import org.apache.ws.security.components.crypto.Crypto;
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26
27 import java.security.cert.X509Certificate;
28
29 /***
30 * PKIPath Security Token.
31 * <p/>
32 *
33 * @author Davanum Srinivas (dims@yahoo.com).
34 */
35 public class PKIPathSecurity extends BinarySecurity {
36 public static final String X509PKI_PATH = "X509PKIPathv1";
37
38 /***
39 * Constructor.
40 * <p/>
41 *
42 * @throws WSSecurityException
43 */
44 public PKIPathSecurity(WSSConfig wssConfig, Element elem)
45 throws WSSecurityException {
46 super(wssConfig, elem);
47 if (!getValueType().equals(getType(wssConfig))) {
48 throw new WSSecurityException(
49 WSSecurityException.INVALID_SECURITY_TOKEN,
50 "invalidValueType",
51 new Object[]{getType(wssConfig), getValueType()});
52 }
53 }
54
55 /***
56 * Constructor.
57 * <p/>
58 */
59 public PKIPathSecurity(WSSConfig wssConfig, Document doc) {
60 super(wssConfig, doc);
61 setValueType(getType(wssConfig));
62 }
63
64 /***
65 * get the X509Certificate array.
66 * <p/>
67 *
68 * @param reverse
69 * @param crypto
70 * @return array of certifcates
71 * @throws WSSecurityException
72 */
73 public X509Certificate[] getX509Certificates(boolean reverse, Crypto crypto)
74 throws WSSecurityException {
75 byte[] data = getToken();
76 if (data == null) {
77 return null;
78 }
79 X509Certificate[] certs = null;
80 certs = crypto.getX509Certificates(data, reverse);
81 return certs;
82 }
83
84 /***
85 * set the X509Certificate array.
86 * <p/>
87 *
88 * @param certs
89 * @param reverse
90 * @param crypto
91 * @throws WSSecurityException
92 */
93 public void setX509Certificates(X509Certificate[] certs,
94 boolean reverse,
95 Crypto crypto)
96 throws WSSecurityException {
97 if (certs == null) {
98 throw new WSSecurityException(WSSecurityException.FAILURE,
99 "noCert");
100 }
101 byte[] data = crypto.getCertificateData(reverse, certs);
102 setToken(data);
103 }
104
105 public static String getType(WSSConfig wssConfig) {
106 return WSConstants.X509TOKEN_NS + "#" + X509PKI_PATH;
107 }
108 }