cancel
Showing results for 
Search instead for 
Did you mean: 

UME API Unlock users - reason field

Former Member
0 Kudos

Hi Experts,

I have created a web dynpro application that takes a username as input and is supposed to unlock that user. In addition i have to maintain the unlock reason field as well. The reason field is visible when the user is unlocked or locked manually from the UME.

String userId  = wdContext.currentContextElement().getUniquename(); 
	String lv_reason = wdContext.currentContextElement().getReason();
	IUserAccountFactory accountFactory = UMFactory.getUserAccountFactory();
	IUserAccount account = accountFactory.getUserAccountByLogonId(userId);
	IUserAccount mutableAccount = accountFactory.getMutableUserAccount(account.getUniqueID());
	mutableAccount.setAttribute("com.sap.security.core.usermanagement","lockreason",new String []{lv_reason});
	
	
	mutableAccount.setLocked(false,IUserAccount.LOCKED_BY_ADMIN);
	mutableAccount.save();
	mutableAccount.commit();

So the above unlocks the user just fine but the lock reason stays unchanged.

I have obtained this (com.sap.security.core.usermanagement","lockreason" ) from the IUserAccount.getAttributes.

Any help is appreciated.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Attribute names are unlocktext, locktext from namespace com.sap.security.core.usermanagement

Former Member
0 Kudos

Thanks for that.

This is what I have now:

IUserFactory userFactory = UMFactory.getUserFactory();
IUser userAccount = userFactory.getUserByLogonID(userId);
IUserMaint user = userFactory.getMutableUser(userAccount.getUniqueID());
	
user.setAttribute("com.sap.security.core.usermanagement","unlocktext", new String[]{lv_reason});

user.save();
user.commit();

It still isn't setting the "Reason for Last Account Unlock:", which is under Accoutn Information in UME.

Former Member
0 Kudos

Nevermind my last post. I got it to work.

So the final code to unlock and set an unlock reason is:

	String userId  = wdContext.currentContextElement().getUniquename(); 
	String lv_reason = wdContext.currentContextElement().getReason();
	
	
	IUserAccountFactory accountFactory = UMFactory.getUserAccountFactory();
	IUserAccount account = accountFactory.getUserAccountByLogonId(userId);
	IUserAccount mutableAccount = accountFactory.getMutableUserAccount(account.getUniqueID());
	
	
	mutableAccount.setLocked(false,IUserAccount.LOCKED_BY_ADMIN);
	mutableAccount.setAttribute("com.sap.security.core.usermanagement","unlocktext", new String[]{lv_reason});

	mutableAccount.save();
	mutableAccount.commit();

Thanks Maksim and Abdulbasit.

Answers (1)

Answers (1)

abdulbasit
Active Contributor
0 Kudos

Can you try to set attribute with :

(Leave unlock part the same)


IUserFactory userFactory = UMFactory.getUserFactory();
IUserMaint user = userFactory.getMutableUser(account.getUniqueID());
user.setAttribute(null, attribute, new String[]{value});
user.save();
user.commit();

Former Member
0 Kudos

Thanks for you answer,

However this didn't help as there isn't a setAttribute in IUserMaint.

abdulbasit
Active Contributor
0 Kudos

I copied it from my working code. I use this code to update user attributes. I haven't tried for unlock reason attribute but I'm sure it works for updating other attributes.