import com.tarantella.tta.webservices.*; //import com.tarantella.tta.webservices.impl.ImplConstants; import com.tarantella.tta.webservices.client.views.SessionBean; import com.tarantella.tta.webservices.client.apis.apache.ServiceLocator; import java.util.Properties; import java.io.FileInputStream; import java.io.IOException; import java.util.Enumeration; import java.util.Vector; import com.tarantella.tta.webservices.parser.*; import com.tarantella.tta.webservices.client.views.SessionBean; import com.tarantella.tta.webservices.client.apis.apache.ServiceLocator; /** * * @author pwalker */ public class SGDHelper { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try{ /* SGDHelper.cleanSGDPassCache( "pwalker", "superman", "andyhall");*/ SGDHelper.kill("pwalker"); } catch(Exception e){ e.printStackTrace(); } } public static String arrayToString(String[] a, String separator) { StringBuffer result = new StringBuffer(); if (a.length > 0) { result.append(a[0]); for (int i=1; i sess = new Vector(); IResponse resp = parser.parse(xml); Enumeration enm = resp.getChildren(); while (enm.hasMoreElements()) { resp = (IResponse)enm.nextElement(); String eid = resp.getAttribute(ISchemaNames.SESSION_ID)[0]; System.out.println("USER="+resp.getAttribute(ISchemaNames.USER)[0]); System.out.println("eid="+eid); sess.addElement(eid); } // End all emulator sessions. if (sess.size() > 0) { String[] dat = sess.toArray(new String[1]); System.out.println("About to end " + dat.length + " emulator sessions"); es.endSessions(cookie, dat); System.out.println("Ended " + dat.length + " emulator sessions"); // Check if all emulator sessions were ended as expected by // repeating the search. sess = new Vector(); xml = es.search(cookie, "(scottasessionowner=*"+idToKill+"*)", desAttr); resp = parser.parse(xml); enm = resp.getChildren(); while (enm.hasMoreElements()) { resp = (IResponse)enm.nextElement(); sess.addElement(resp.getAttribute(ISchemaNames.SESSION_ID)[0]); } if (sess.size() > 0) { dat = sess.toArray(new String[1]); System.out.println(dat.length + " emulator sessions remain"); } else System.out.println("No emulator sessions remain"); } else System.out.println("No emulator sessions to end"); } // If user wants to logout webtop sessions, log them out. if (logoutWS) { // Get an interface to the webtop session APIs. ITarantellaWebtopSession ws = locator.getWebtopSession(); // Search for the webtop sessions. String[] desAttr = { ISchemaNames.SESSION_ID }; xml = ws.adminSearchSession(cookie, "(scottasessionowner=*"+idToKill+"*)", desAttr); // Parse the search response and extract the sessionIds for the // webtop sessions. Vector sess = new Vector(); IResponse resp = parser.parse(xml); Enumeration enm = new PreOrderEnumeration(resp); while (enm.hasMoreElements()) { resp = (IResponse)enm.nextElement(); String wid = resp.getAttribute(ISchemaNames.SESSION_ID)[0]; System.out.println("wid="+wid); // Don't end the webtop session for this application. if (wid != null && !sid.equals(wid)) sess.addElement(wid); } // End selected webtop sessions. if (sess.size() > 0) { String[] dat = sess.toArray(new String[1]); System.out.println("About to end " + dat.length + " webtop sessions"); ws.adminEndSessions(cookie, dat, true); System.out.println("Ended " + dat.length + " webtop sessions"); // Check if any webtop sessions have not been logged out. sess = new Vector(); xml = ws.adminSearchSession(cookie, "(scottasessionowner=*"+idToKill+"*)", desAttr); resp = parser.parse(xml); enm = resp.getChildren(); while (enm.hasMoreElements()) { resp = (IResponse)enm.nextElement(); sess.addElement(resp.getAttribute(ISchemaNames.SESSION_ID)[0]); } if (sess.size() > 0) { dat = sess.toArray(new String[1]); System.out.println(dat.length + " webtop sessions remain"); } else System.out.println("No webtop sessions remain"); } else System.out.println("No webtop sessions to end"); } if (!logoutES && !logoutWS) System.out.println("Well that did a lot!"); // End this webtop session. System.out.println("Logging out..."); session.endSession(true); System.out.println("Logged out"); } catch (java.rmi.RemoteException excp) { System.out.println("RMI Exception: " + excp); } catch (Exception excp) { System.out.println("Exception: " + excp); } } /* * @author Paul Walker, credit to Peter Cartwright SGD Engineering * @param sgdUserName * @param resourceUserName The unique Id of the target resource user account * @param newUserPassword The new password to set on the target * * * This static method expects to find a properties file c:\sgdhelper.properties * the format of this file should be as follows: * * sgdurl=http://batty.france.sun.com.example * sgdauthuser=Administrator.example * sgdauthuserpassword=Passw0rd.example * */ public static void cleanSGDPassCache( String sgdUserName, String resourceUserName, String newUserPassword) throws java.io.FileNotFoundException, java.io.IOException,java.lang.Exception{ Properties _props = null; String _sgdUrl = null; String _sgdAuthUserName = null; String _sgdAuthUserPassword = null; try{ _props = SGDHelper.readProperties(); _sgdUrl = _props.getProperty("sgdurl"); System.out.println("SGD Url is " + _sgdUrl); _sgdAuthUserName = _props.getProperty("sgdauthuser"); System.out.println("SGD Admin to auth as is " + _sgdAuthUserName); _sgdAuthUserPassword = _props.getProperty("sgdauthuserpassword"); System.out.println("SGD Admin password is " + _sgdAuthUserPassword); }catch(java.io.FileNotFoundException fnfe){ throw fnfe; }catch(java.io.IOException ioe){ throw ioe; } if ((_sgdUrl == null) || (_sgdAuthUserName == null) || (_sgdAuthUserPassword == null)) throw new java.lang.Exception ("One or more required authentication properties are null"); String sessionCookie = null; ITarantellaAdmin admin = null; // Authenticate the session try { SessionBean session = new SessionBean(); session.setLocator(new ServiceLocator(_sgdUrl)); session.authenticate(_sgdAuthUserName, _sgdAuthUserPassword, "PasswordCache", "en"); System.out.println("Session authenticated ? = " + session.isAuthenticated()); sessionCookie = session.getSessionCookie(); admin = session.getLocator().getAdmin(); } catch (java.rmi.RemoteException re) { re.printStackTrace(); System.exit(1); } try { // Delete existing entry String cmdOutput = null; String command = "passcache"; String subCommand = "delete"; String parameters[] = new String[]{ "--person", ".../_service/sco/tta/ldapcache/uid="+sgdUserName+",ou=people,dc=france,dc=sun,dc=com", " --resource ", " .../_wns/ApplicationServerDomain" }; cmdOutput = admin.runCommand(sessionCookie, command, subCommand, parameters); System.out.println("delete passcache = " + cmdOutput); } catch (java.rmi.RemoteException re) { re.printStackTrace(); } try { // Create new entry String cmdOutput = null; String command = "passcache"; String subCommand = "new"; String parameters[] = new String[]{ "--person", ".../_service/sco/tta/ldapcache/uid="+sgdUserName+",ou=people,dc=france,dc=sun,dc=com", " --resource ", " .../_wns/ApplicationServerDomain", "--resuser", resourceUserName , "--respass", newUserPassword }; System.out.println("parameters being passed are " + SGDHelper.arrayToString(parameters," ")); cmdOutput = admin.runCommand(sessionCookie, command, subCommand, parameters); System.out.println("add passache " + cmdOutput); } catch (java.rmi.RemoteException re) { re.printStackTrace(); } } }