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