cancel
Showing results for 
Search instead for 
Did you mean: 

Change Password and Unlock User using UME API

Former Member
0 Kudos

Hi,

I am trying to Unlock the user who got locked by entering wrong password at the time of login to the SAP EP portal and then changing the user password.

Below is the code which I am testing for the same

String userId="test1";

IUserAccount iuacc = UMFactory.getUserAccountFactory().getUserAccountByLogonId(userId);

IUserAccount iUserAccount = UMFactory.getUserAccountFactory().getMutableUserAccount(iuacc.getUniqueID());

iUserAccount.setLocked(false,0);

iUserAccount.commit();

iUserAccount.save();

iUserAccount.setPassword("testing3");

iUserAccount.commit();

iUserAccount.save();

The above code is working fine without any errors or exception. But after runnning the code when i login in to SAP EP portal

i could see the user is still locked and password is not changed.

Could someone help me in fixing this problem. I am using SAP EP 6.0 SPS-02 UME APIs

Accepted Solutions (0)

Answers (2)

Answers (2)

Saravanan_SD
Advisor
Advisor
0 Kudos

Hi Prashanth,

Try like this. It is working fine.


IUserAccountFactory userAccountFactory =UMFactory.getUserAccountFactory();
IUserAccount userAccount = null;
	
userAccount = userAccountFactory.getUserAccountByLogonId("testuser");
	
//get an account object which can be modified

 IUserAccount mUserAccount = null;
	
mUserAccount =	userAccountFactory.getMutableUserAccount(userAccount.getUniqueID());
	
//to unlock account

mUserAccount.setLocked(false,IUserAccount.LOCKED_NO);
mUserAccount.setPassword("password");
//		then you must call comit;
mUserAccount.commit();

Regards,

Saravanan

Former Member
0 Kudos

Here is some simple code to reset the password. You can use it as a baseline for unlocking the user as well. There is minimal error handling and the assumption is that you wish to set the password for all the user accounts. It also assumes that you have correctly gotten the IUser or IUserMaint object. (this code takes an IUserMaint but could easily take an IUser object)


    public boolean setNewUserPassword(IUserMaint userMaint, String password) {
    	boolean passwordSet = false;
		IUserAccountFactory factory = UMFactory.getUserAccountFactory();
		IUserAccount[] accounts = null;
		IUserAccount userAccount = null;
		IUserAccount mutableAccount = null;
		try {
			accounts = userMaint.getUserAccounts();
			for(int j = 0; j < accounts.length; j++) {
				userAccount = accounts[j];
				mutableAccount = factory.getMutableUserAccount(userAccount.getUniqueID());
				mutableAccount.setPassword(password);
				mutableAccount.commit();
				passwordSet = true;
			}
		}
		catch(UMException ume) {
			ume.printStackTrace();
		}
    	
    	return passwordSet;
    }

Hope this helps.

Craig