This solution will generate random password using SUN java access manager password generator plugin and the password will be saved to corresponding user attribute
import com.iplanet.am.sdk.AMException; import com.iplanet.am.sdk.AMStoreConnection; import com.iplanet.am.sdk.AMUser; import com.iplanet.am.util.AMPasswordUtil; import com.iplanet.services.cdm.G11NSettings; import com.iplanet.sso.SSOException; import com.iplanet.sso.SSOToken; import com.iplanet.sso.SSOTokenManager; import com.sun.identity.authentication.internal.AuthPrincipal; import com.sun.identity.password.plugins.PasswordGenerator; import com.sun.identity.password.ui.model.PWResetException; import com.sun.identity.sm.OrganizationConfigManager; import com.sun.identity.sm.SMSException; import java.text.DateFormat; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import javax.servlet.http.HttpServletRequest; public class GeneratePassword { public void generatePassword(HttpServletRequest request, User userInput) throws AMException,PWResetException,InstantiationException,IllegalAccessException, ClassNotFoundException,SMSException, SSOException, Exception { try { SSOTokenManager manager = null; SSOToken ssoToken = null; String adminDN = "uid=amadmin,ou=People,dc=red,dc=iplanet,dc=com"; String adminPwd = "password"; manager = SSOTokenManager.getInstance(); ssoToken = manager.createSSOToken(new AuthPrincipal(adminDN), adminPwd); String userDN = ssoToken.getPrincipal().getName(); AMStoreConnection amsc = new AMStoreConnection(ssoToken); AMUser user = amsc.getUser(userDN); String rootDN = user.getOrganizationDN(); String customerName = userInput.getCustomerName(); String userId = userInput.getUserId(); String dn = "o=" + customerName + "," + rootDN; String userDn = "uid=" + userId + ",ou=People," + dn; AMUser amuser1 = amsc.getUser(userDn); OrganizationConfigManager mgr = new OrganizationConfigManager(token, dn); Map attributeValues = mgr.getServiceAttributes(PW_RESET_SERVICE); Set set = (Set) attributeValues.get(PW_RESET_OPTION); String plugin = ((set != null) && !set.isEmpty()) ? (String) set.iterator().next() : ""; log.info("plugin....." + plugin); Object obj = null; Class c = Class.forName(plugin); obj = c.newInstance(); if ((obj != null) && (obj instanceof PasswordGenerator)) { PasswordGenerator pwd = (PasswordGenerator) obj; password = pwd.generatePassword(amuser1); } HashMap userAttributeMap = new HashMap(); storeUserAttributes("userPassword", password, userAttributeMap); amuser1.setAttributes(userAttributeMap); amuser1.store(); } catch (AMException ex) { ex.printStackTrace(); } catch (PWResetException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (SMSException ex) { ex.printStackTrace(); } catch (SSOException ex) { ex.printStackTrace(); } } }