While working with the SAP User Management Engine (UME), there might be a need to reset or change the password of an SAP Portal user through Java code.
The following code snippet demonstrates how to reset or change password using SAP UME API.

import com.sap.security.api.IUserAccount;
import com.sap.security.api.IUserAccountFactory;
import com.sap.security.api.UMException;
import com.sap.security.api.UMFactory;

...
...

public boolean resetPassword(String loginId, String newPassword)
{
	// Get the instance of factory
	IUserAccountFactory accntFactory = UMFactory.getUserAccountFactory();
	try
	{
		// Fetch the user account object by using the login ID of the user
		IUserAccount accnt = accntFactory.getUserAccountByLogonId(loginId);
		
		// Get a mutable object of user account which can be modified
		IUserAccount mAccnt = accntFactory.getMutableUserAccount(accnt.getUniqueID());

		// Set the new password in the mutable user account object
		mAccnt.setPassword(newPassword);
			
		// Save and commit the mutable user account object
		mAccnt.save();
		mAccnt.commit();
	}
	catch (UMException ex)
	{
		// Handle the exception			
	}
}

...
...
Change password using SAP UME API
        

Comments, Questions or Suggestions: