This project has retired. For details please refer to its
Attic page.
UddiDigitalSignatureService xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juddi.v3.client.cli;
18
19 import java.util.concurrent.atomic.AtomicReference;
20 import org.apache.juddi.v3.client.config.UDDIClient;
21 import org.apache.juddi.v3.client.cryptor.DigSigUtil;
22 import org.apache.juddi.v3.client.transport.Transport;
23 import org.uddi.api_v3.*;
24 import org.uddi.v3_service.UDDIInquiryPortType;
25 import org.uddi.v3_service.UDDIPublicationPortType;
26 import org.uddi.v3_service.UDDISecurityPortType;
27
28
29
30
31
32
33 public class UddiDigitalSignatureService {
34
35 private UDDISecurityPortType security = null;
36 private UDDIInquiryPortType inquiry = null;
37 private UDDIPublicationPortType publish = null;
38 private UDDIClient clerkManager = null;
39
40
41
42
43 public UddiDigitalSignatureService() {
44 try {
45
46
47 clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
48 Transport transport = clerkManager.getTransport();
49
50 security = transport.getUDDISecurityService();
51 inquiry = transport.getUDDIInquiryService();
52 publish = transport.getUDDIPublishService();
53 } catch (Exception e) {
54 e.printStackTrace();
55 }
56 }
57
58
59
60
61
62
63 public static void main(String args[]) {
64
65 UddiDigitalSignatureService sp = new UddiDigitalSignatureService();
66 sp.fire(null, null);
67 }
68
69 public void fire(String token, String key) {
70 try {
71
72 DigSigUtil ds = null;
73
74 ds = new DigSigUtil();
75
76 ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE, "keystore.jks");
77 ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILETYPE, "JKS");
78 ds.put(DigSigUtil.SIGNATURE_KEYSTORE_FILE_PASSWORD, "Test");
79 ds.put(DigSigUtil.SIGNATURE_KEYSTORE_KEY_ALIAS, "Test");
80 ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_BASE64, "true");
81
82 ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SERIAL, "true");
83 ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SUBJECTDN, "true");
84 ds.put(DigSigUtil.TRUSTSTORE_FILE, "truststore.jks");
85 ds.put(DigSigUtil.TRUSTSTORE_FILETYPE, "JKS");
86 ds.put(DigSigUtil.TRUSTSTORE_FILE_PASSWORD, "Test");
87
88
89
90
91
92 if (token == null)
93 {
94 token = getAuthKey(clerkManager.getClerk("default").getPublisher(),
95 clerkManager.getClerk("default").getPassword());
96 }
97
98 if (key == null) {
99 SaveBusiness sb = new SaveBusiness();
100 sb.setAuthInfo(token);
101 BusinessEntity ob = new BusinessEntity();
102 Name name = new Name();
103 name.setValue("My Signed Business");
104 ob.getName().add(name);
105 ob.setBusinessServices(new BusinessServices());
106 BusinessService bs = new BusinessService();
107 bs.getName().add(new Name("My signed service", null));
108 ob.getBusinessServices().getBusinessService().add(bs);
109 sb.getBusinessEntity().add(ob);
110
111 BusinessDetail saveBusiness = publish.saveBusiness(sb);
112
113 System.out.println("business created with key " + saveBusiness.getBusinessEntity().get(0).getBusinessKey());
114
115 key = saveBusiness.getBusinessEntity().get(0).getBusinessServices().getBusinessService().get(0).getServiceKey();
116 }
117
118 BusinessService be = null;
119 be = getServiceDetails(key);
120 if (!be.getSignature().isEmpty())
121 {
122 System.out.println("WARN, the entity with the key " + key + " is already signed! aborting");
123 return;
124 }
125
126
127 System.out.println("signing");
128 BusinessService signUDDI_JAXBObject = ds.signUddiEntity(be);
129 DigSigUtil.JAXB_ToStdOut(signUDDI_JAXBObject);
130 System.out.println("signed, saving");
131
132 SaveService sb = new SaveService();
133 sb.setAuthInfo(token);
134 sb.getBusinessService().add(signUDDI_JAXBObject);
135 publish.saveService(sb);
136 System.out.println("saved, fetching");
137
138 be = getServiceDetails(key);
139 DigSigUtil.JAXB_ToStdOut(be);
140 System.out.println("verifing");
141 AtomicReference<String> msg = new AtomicReference<String>();
142 boolean verifySigned_UDDI_JAXB_Object = ds.verifySignedUddiEntity(be, msg);
143 if (verifySigned_UDDI_JAXB_Object) {
144 System.out.println("signature validation passed (expected)");
145 } else {
146 System.out.println("signature validation failed (not expected)");
147 }
148 System.out.println(msg.get());
149
150 } catch (Exception e) {
151 e.printStackTrace();
152 }
153 }
154
155 private BusinessService getServiceDetails(String key) throws Exception {
156
157 GetServiceDetail r = new GetServiceDetail();
158
159 r.getServiceKey().add(key);
160 return inquiry.getServiceDetail(r).getBusinessService().get(0);
161 }
162
163
164
165
166
167
168
169
170
171
172 private String getAuthKey(String username, String password) {
173 try {
174
175 GetAuthToken getAuthTokenRoot = new GetAuthToken();
176 getAuthTokenRoot.setUserID(username);
177 getAuthTokenRoot.setCred(password);
178
179
180 AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
181 System.out.println("root AUTHTOKEN = " + "don't log auth tokens!");
182 return rootAuthToken.getAuthInfo();
183 } catch (Exception ex) {
184 System.out.println("Could not authenticate with the provided credentials " + ex.getMessage());
185 }
186 return null;
187 }
188 }