001/* 002 * Copyright (c) 2003-2010 The Regents of the University of California. 003 * All rights reserved. 004 * 005 * '$Author: barseghian $' 006 * '$Date: 2013-01-16 23:42:20 +0000 (Wed, 16 Jan 2013) $' 007 * '$Revision: 31342 $' 008 * 009 * Permission is hereby granted, without written agreement and without 010 * license or royalty fees, to use, copy, modify, and distribute this 011 * software and its documentation for any purpose, provided that the above 012 * copyright notice and the following two paragraphs appear in all copies 013 * of this software. 014 * 015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 019 * SUCH DAMAGE. 020 * 021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 026 * ENHANCEMENTS, OR MODIFICATIONS. 027 * 028 */ 029 030package org.kepler.authentication; 031 032import javax.xml.rpc.ParameterMode; 033 034import org.apache.axis.client.Call; 035import org.apache.axis.client.Service; 036import org.apache.axis.encoding.XMLType; 037import org.kepler.authentication.gui.GAMALoginGUI; 038import org.kepler.gui.ProgressMonitorSwingWorker; 039 040/** 041 * AuthenticationService is responsible for contact the GAMA service and get 042 * back the credential for the user 043 * 044 * @author Zhijie Guan guan@sdsc.edu 045 * 046 */ 047 048public class GAMAAuthenticationService extends AuthenticationService { 049 050 /** 051 * Use the GAMA authentication service to get credential returns null if the 052 * user cancels the action. 053 */ 054 public synchronized ProxyEntity authenticate(Domain d) 055 throws AuthenticationException { 056 /* 057 * STEPS: 1) open the gui to get user info 2) authenticate the user 058 * based on the info 3) if user is authenticated, create ProxyEntity and 059 * return it 060 */ 061 062 GAMALoginGUI.fire(); 063 while (GAMALoginGUI.getUsername() == null) { 064 } // wait for the input to be made and the 'ok' button to be pressed 065 066 // user canceled the action 067 if (GAMALoginGUI.getUsername().equals(GAMALoginGUI.USERNAME_BREAK)) { 068 return null; 069 } 070 071 String userName = GAMALoginGUI.getUsername(); 072 String password = GAMALoginGUI.getPassword(); 073 074 ProgressMonitorSwingWorker worker = new ProgressMonitorSwingWorker( 075 "Authenticating..."); 076 worker.execute(); 077 078 ProxyEntity pentity = new ProxyEntity(); 079 try { 080 System.out.println("1"); 081 Service service = new Service(); // GAMA web service 082 System.out.println("2"); 083 Call call = (Call) service.createCall(); // Service call 084 System.out.println("3"); 085 086 System.out.println("serviceURL: " + serviceURL); 087 System.out.println("4"); 088 call.setTargetEndpointAddress(new java.net.URL(serviceURL)); 089 System.out.println("5"); 090 call.setOperationName(operationName); 091 System.out.println("7"); 092 093 // call parameters 094 call.addParameter("username", XMLType.XSD_STRING, ParameterMode.IN); 095 System.out.println("8"); 096 call.addParameter("passwd", XMLType.XSD_STRING, ParameterMode.IN); 097 System.out.println("9"); 098 call.setReturnType(XMLType.XSD_STRING); 099 System.out.println("10: " + userName + "/" + password); 100 Object[] o = new Object[] { userName, password }; 101 System.out.println("o: " + o[0] + "/" + o[1]); 102 103 Object returnObject = call.invoke(o); 104 if (returnObject == null) { 105 System.out.println("11"); 106 System.out.println("returnobj is null"); 107 credential = null; 108 System.out.println("12"); 109 } else { 110 System.out.println("returnobj is " + (String) returnObject); 111 credential = (String) returnObject; 112 } 113 114 pentity = new ProxyEntity(); 115 pentity.setDomain(d); 116 pentity.setCredential(credential); 117 pentity.setUserName(userName); 118 119 worker.done(); 120 worker.cancel(true); 121 return pentity; 122 } catch (Exception e) { 123 worker.done(); 124 worker.cancel(true); 125 throw new AuthenticationException( 126 "GAMA Authentication Service error: " + e.toString()); 127 } 128 } 129 130 public void unauthenticate(ProxyEntity pentity) 131 throws AuthenticationException { 132 // TODO: implement the unauth method BRL20071129 133 throw new AuthenticationException( 134 "GAMA unauthenticate method is not implemented"); 135 } 136}