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.v3.client.cli;
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.transport.Transport;
23  import org.uddi.api_v3.*;
24  import org.uddi.v3_service.UDDIInquiryPortType;
25  import org.uddi.v3_service.UDDISecurityPortType;
26  
27  /**
28   * This class shows you how to search for services that are digitally signed
29   *
30   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
31   */
32  public class UddiDigitalSignatureSearch {
33  
34          private UDDISecurityPortType security = null;
35          private UDDIInquiryPortType inquiry = null;
36  
37          /**
38           * This sets up the ws proxies using uddi.xml in META-INF
39           */
40          public UddiDigitalSignatureSearch() {
41                  try {
42              // create a manager and read the config in the archive; 
43                          // you can use your config file name
44                          UDDIClient clerkManager = new UDDIClient("META-INF/simple-publish-uddi.xml");
45                          Transport transport = clerkManager.getTransport();
46                          // Now you create a reference to the UDDI API
47                          security = transport.getUDDISecurityService();
48                          inquiry = transport.getUDDIInquiryService();
49                  } catch (Exception e) {
50                          e.printStackTrace();
51                  }
52          }
53  
54          /**
55           * Main entry point
56           *
57           * @param args
58           */
59          public static void main(String args[]) {
60  
61                  UddiDigitalSignatureSearch sp = new UddiDigitalSignatureSearch();
62                  sp.fire(null);
63          }
64  
65          public void fire(String token) {
66                  try {
67  
68                          FindService fs = new FindService();
69                          //optional, usually
70                          if (token == null) {
71                                  token = GetAuthKey("root", "root");
72                          }
73                          fs.setAuthInfo(token);
74                          fs.setFindQualifiers(new FindQualifiers());
75                          fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.SORT_BY_DATE_ASC);
76                          fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.APPROXIMATE_MATCH);
77                          fs.getFindQualifiers().getFindQualifier().add(UDDIConstants.SIGNATURE_PRESENT);
78                          Name n = new Name();
79                          n.setValue("%");
80                          fs.getName().add(n);
81                          ServiceList findService = inquiry.findService(fs);
82                          if (findService != null && findService.getServiceInfos() != null) {
83                                  for (int i = 0; i < findService.getServiceInfos().getServiceInfo().size(); i++) {
84                                          System.out.println(listToString(findService.getServiceInfos().getServiceInfo().get(i).getName()));
85                                  }
86                          } else
87                                  System.out.println("no results found.");
88                  } catch (Exception e) {
89                          e.printStackTrace();
90                  }
91          }
92  
93          /**
94           * Gets a UDDI style auth token, otherwise, appends credentials to the
95           * ws proxies (not yet implemented)
96           *
97           * @param username
98           * @param password
99           * @param style
100          * @return
101          */
102         private String GetAuthKey(String username, String password) {
103                 try {
104 
105                         GetAuthToken getAuthTokenRoot = new GetAuthToken();
106                         getAuthTokenRoot.setUserID(username);
107                         getAuthTokenRoot.setCred(password);
108 
109                         // Making API call that retrieves the authentication token for the 'root' user.
110                         AuthToken rootAuthToken = security.getAuthToken(getAuthTokenRoot);
111                         System.out.println("root AUTHTOKEN = " + "dont log auth tokens!");
112                         return rootAuthToken.getAuthInfo();
113                 } catch (Exception ex) {
114                         System.out.println("Could not authenticate with the provided credentials " + ex.getMessage());
115                 }
116                 return null;
117         }
118 
119         private String listToString(List<Name> name) {
120                 StringBuilder sb = new StringBuilder();
121                 for (int i = 0; i < name.size(); i++) {
122                         sb.append(name.get(i).getValue()).append(" ");
123                 }
124                 return sb.toString();
125         }
126 }