import java.rmi.RemoteException; import com.sas.metadata.remote.AssociationList; import com.sas.metadata.remote.CMetadata; import com.sas.metadata.remote.Person; import com.sas.metadata.remote.MdException; import com.sas.metadata.remote.MdFactory; import com.sas.metadata.remote.MdFactoryImpl; import com.sas.metadata.remote.MdOMIUtil; import com.sas.metadata.remote.MdOMRConnection; import com.sas.metadata.remote.MdObjectStore; import com.sas.metadata.remote.MetadataObjects; import com.sas.metadata.remote.PrimaryType; import com.sas.metadata.remote.Tree; import com.sas.meta.SASOMI.ISecurity_1_1; import com.sas.iom.SASIOMDefs.VariableArray2dOfStringHolder; public class setPasswd { public setPasswd(){}; public int changePasswd(String IdentityName, String IdentityPassword) { try { MdFactoryImpl _factory = new MdFactoryImpl(false); MdOMRConnection connection = _factory.getConnection(); String serverName = "localhost"; String serverPort = "8561"; String serverUser = "sasadm@saspw"; String serverPass = "{SAS002}99999999999999999999999999999999"; connection.makeOMRConnection(serverName, serverPort, serverUser, serverPass); ISecurity_1_1 iSecurity = connection.MakeISecurityConnection(); // // This block obtains the person metadata ID that is needed to change the password // // Defines the GetIdentityInfo 'ReturnUnrestrictedSource' option. final String[][] options ={{"ReturnUnrestrictedSource",""}}; // Defines a stringholder for the info output parameter. VariableArray2dOfStringHolder info = new VariableArray2dOfStringHolder(); // Issues the GetInfo method for the provided iSecurity connection user. iSecurity.GetInfo("GetIdentityInfo","Person:"+IdentityName, options, info); String[][] returnArray = info.value; String personMetaID = new String(); for (int i=0; i< returnArray.length; i++ ) { System.out.println(returnArray[i][0] + "=" + returnArray[i][1]); if (returnArray[i][0].compareTo("IdentityObjectID") == 0) { personMetaID = returnArray[i][1]; } } MdObjectStore objectStore = _factory.createObjectStore(); Person person = (Person) _factory.createComplexMetadataObject(objectStore, IdentityName, MetadataObjects.PERSON, personMetaID); iSecurity.SetInternalPassword(IdentityName, IdentityPassword); person.updateMetadataAll(); System.out.println("Password has been changed."); return 0; // success } catch (MdException e) { Throwable t = e.getCause(); if (t != null) { String ErrorType = e.getSASMessageSeverity(); String ErrorMsg = e.getSASMessage(); if (ErrorType == null) { // If there is no SAS server message, write a Java/CORBA message. } else { // If there is a message from the server: System.out.println(ErrorType + ": " + ErrorMsg); } if (t instanceof org.omg.CORBA.COMM_FAILURE) { // If there is an invalid port number or host name: System.out.println(e.getLocalizedMessage()); } else if (t instanceof org.omg.CORBA.NO_PERMISSION) { // If there is an invalid user ID or password: System.out.println(e.getLocalizedMessage()); } } else { // If we cannot find a nested exception, get message and print. System.out.println(e.getLocalizedMessage()); } // If there is an error, print the entire stack trace. e.printStackTrace(); } catch (RemoteException e) { // Unknown exception. e.printStackTrace(); } catch (Exception e) { // Unknown exception. e.printStackTrace(); } System.out.println("Failure: Password has NOT been changed."); return 1; // failure } }