This project has retired. For details please refer to its Attic page.
UddiDigitalSignatureSearch xref
View Javadoc
1   /*
2    * Copyright 2001-2013 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.samples;
18  
19  import java.util.List;
20  import org.apache.juddi.v3.client.UDDIConstants;
21  import org.apache.juddi.v3.client.config.UDDIClient;
22  import org.apache.juddi.v3.client.config.UDDIClientContainer;
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   * This class shows you how to search for services that are digitally signed
31   *
32   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
33   */
34  public class UddiDigitalSignatureSearch {
35  
36          private UDDISecurityPortType security = null;
37          private UDDIInquiryPortType inquiry = null;
38  
39          /**
40           * This sets up the ws proxies using uddi.xml in META-INF
41           */
42          public UddiDigitalSignatureSearch() {
43                  try {
44                          // create a manager and read the config in the archive; 
45                          // you can use your config file name
46                          UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
47                          Transport transport = clerkManager.getTransport();
48                          // Now you create a reference to the UDDI API
49                          security = transport.getUDDISecurityService();
50                          inquiry = transport.getUDDIInquiryService();
51                  } catch (Exception e) {
52                          e.printStackTrace();
53                  }
54          }
55  
56          /**
57           * Main entry point
58           *
59           * @param args
60           */
61          public static void main(String args[]) {
62  
63                  UddiDigitalSignatureSearch sp = new UddiDigitalSignatureSearch();
64                  sp.fire(null);
65          }
66  
67          public void fire(String token) {
68                  try {
69  
70                          FindService fs = new FindService();
71                          //optional, usually
72                          if (token == null) {
73                                  token = getAuthKey("root", "root");
74                          }
75                          fs.setAuthInfo(token);
76                          fs.setFindQualifiers(new FindQualifiers());
77                          fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.SORT_BY_DATE_ASC);
78                          fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
79                          fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.SIGNATURE_PRESENT);
80                          Name n = new Name();
81                          n.setValue("%");
82                          fs.getName().add(n);
83                          ServiceList findService = inquiry.findService(fs);
84                          for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
85                                  System.out.println(listToString(findService.getServiceInfos().getServiceInfo().get(i).getName()));
86                          }
87                  } catch (Exception e) {
88                          e.printStackTrace();
89                  }
90          }
91  
92          /**
93           * Gets a UDDI style auth token, otherwise, appends credentials to the
94           * ws proxies (not yet implemented)
95           *
96           * @param username
97           * @param password
98           * @param style
99           * @return
100          */
101         private String getAuthKey(String username, String password) {
102                 try {
103 
104                         GetAuthToken getAuthTokenRoot = new GetAuthToken();
105                         getAuthTokenRoot.setUserID(username);
106                         getAuthTokenRoot.setCred(password);
107 
108                         // Making API call that retrieves the authentication token for the 'root' user.
109                         AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
110                         System.out.println("root AUTHTOKEN = " + "dont log auth tokens!");
111                         return rootAuthToken.getAuthInfo();
112                 } catch (Exception ex) {
113                         System.out.println("Could not authenticate with the provided credentials " + ex.getMessage());
114                 }
115                 return null;
116         }
117 
118         private String listToString(List<Name> name) {
119                 StringBuilder sb = new StringBuilder();
120                 for (int i = 0; i < name.size(); i++) {
121                         sb.append(name.get(i).getValue()).append(" ");
122                 }
123                 return sb.toString();
124         }
125 }