This code demonstrates the two required tasks; firstly,locate the user, and then secondly modify the password value for that user
// com.emc.rsa.mjbond.ct.AdminChangePassword package com.emc.rsa.mjbond.ct;
import sirrus.connect.ConnectionDescriptor;
import sirrus.api.client.APIServerProxy; import sirrus.api.client.IUser; import sirrus.api.client.search.IUserSearch; import sirrus.api.client.criteria.UserPropertyCriterion; import sirrus.api.client.criteria.StringCriterion; import sirrus.api.client.ISparseData;
/** * <p>Title: Adding a user to ClearTrust</p> * * <p> * Description: This sample code demonstrates locating anexisting user in CT * and updating the password for the user. * <br> * This code is not supported by RSA in anyway and is supplied 'as is' to demonstate * specific behaviour * </p> * * <p>Copyright: Copyright (c) 2011</p> * * <p>Company: RSA, The Security Division of EMC</p> * * @author Matthew J Bond * @version 1.1 */ public class AdminChangePassword { private static final String ESERVERIP = "10.32.27.98"; // $NON-NLS-1$ private static final int ESERVERPORT = 5601; private static final int ESERVERTIMEOUT = 60000;
private static final String ADMINUSER = "administrator"; // $NON-NLS-1$ private static final String ADMINPW = "passwd01"; // $NON-NLS-1$ private static final String ADMINGROUP = "Default Administrative Group"; // $NON-NLS-1$ private static final String ADMINROLE = "Default Administrative Role"; // $NON-NLS-1$
/** * Given a valid eserver authenticated connection and the loginID of a user * this method shows a way in which a search mechanism might be used * to locate the user and return the IUser object * * @param proxy APIServerProxy * @param userID String * @return IUser * @throws sirrus.api.client.ObjectNotFoundException * @throws sirrus.api.client.TransportException * @throws java.io.IOException */ private static IUser getUser(APIServerProxy proxy, String userID) throws sirrus.api.client.ObjectNotFoundException, sirrus.api.client.TransportException, java.io.IOException
{ IUser user = null; IUserSearch userSearch = null; StringCriterion criterion = null; UserPropertyCriterion userCriteria = null; ISparseData usersInSearch = null;
userSearch = proxy.searchUserObjects(); criterion = new StringCriterion(StringCriterion.EQUALS, userID); userCriteria = new UserPropertyCriterion("Name", criterion); // $NON-NLS-1$ userSearch.putUserPropertyCriterion(userCriteria); usersInSearch = userSearch.search(); user = (IUser) usersInSearch.getByName(userID); return user; }
/** * Supply a single argument as the UserID of the user to be added. This * is then used as userID/first/last values * * @param args String[] */ public static void main(String[] args) {
APIServerProxy myServerProxy = null;
try { String userID = args[0]; String newPassword = args[1]; IUser user = null;
// generate the connection details for the EServer ConnectionDescriptor eserver = new ConnectionDescriptor(ESERVERIP, ESERVERPORT, ConnectionDescriptor.SSL_ANON, ESERVERTIMEOUT);
// Estbalisha connection using the preset parameters myServerProxy = new APIServerProxy(eserver);
// Connect to the Entitlements Server as an appropriate administrator myServerProxy.connect(ADMINUSER, ADMINPW, ADMINGROUP, ADMINROLE);
// Use the static method in this class to search for the user user = getUser(myServerProxy,userID);
// Make the modification to the password user.setPassword(newPassword);
// Save the modfied user in the Entitlements database. user.save();
System.out.println("User " // $NON-NLS-1$ + user.getName() + " updated."); // $NON-NLS-1$
} catch (Exception e) { e.printStackTrace(); } finally { try { myServerProxy.disconnect(); } catch (Exception ignore) { ignore.printStackTrace(); } } } }
|