View Javadoc
1   /*
2    * Copyright 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  package org.apache.juddi.v3.migration.tool;
17  
18  import java.rmi.RemoteException;
19  import java.util.logging.Level;
20  import java.util.logging.Logger;
21  import org.uddi.api_v3.GetAuthToken;
22  import org.uddi.api_v3.GetOperationalInfo;
23  import org.uddi.api_v3.OperationalInfos;
24  import org.uddi.v3_service.DispositionReportFaultMessage;
25  import org.uddi.v3_service.UDDIInquiryPortType;
26  import org.uddi.v3_service.UDDISecurityPortType;
27  
28  /**
29   * Some common functions for the migration tool
30   *
31   * @author Alex O'Ree
32   * @since 3.2
33   */
34  public class Common {
35  
36          public static String GetOwner(String key, String token, UDDIInquiryPortType inquiry) {
37                  GetOperationalInfo goi = new GetOperationalInfo();
38                  goi.setAuthInfo(token);
39                  goi.getEntityKey().add(key);
40                  OperationalInfos operationalInfo = null;
41                  try {
42                          operationalInfo = inquiry.getOperationalInfo(goi);
43                          if (operationalInfo != null && operationalInfo.getOperationalInfo() != null
44                               && !operationalInfo.getOperationalInfo().isEmpty()) {
45                                  return operationalInfo.getOperationalInfo().get(0).getAuthorizedName();
46                          }
47                  } catch (Exception ex) {
48                          ex.printStackTrace();
49                  }
50                  return null;
51          }
52  
53          public static String GetAuthToken(String username, String password, UDDISecurityPortType sec) {
54                  try {
55                          System.out.println(username + " logging in");
56                          GetAuthToken getAuthTokenRoot = new GetAuthToken();
57                          getAuthTokenRoot.setUserID(username);
58                          getAuthTokenRoot.setCred(password);
59                          String authInfo = sec.getAuthToken(getAuthTokenRoot).getAuthInfo();
60                          System.out.println(username + " login success");
61                          return authInfo;
62                  } catch (Exception ex) {
63                          ex.printStackTrace();
64                  }
65                  return null;
66          }
67  }