cancel
Showing results for 
Search instead for 
Did you mean: 

Locking users in UME api

Former Member
0 Kudos
336

Hi All,

I am trying to lock and unlock the users using UME api's.

This is the code which I had used.

**********************************************************************

com.sap.security.api.IUser user = UMFactory.getUserFactory().getUserByLogonID("test");

String userId = user.getUniqueName();

IUserAccountFactory uaf = UMFactory.getUserAccountFactory();

IUserAccount ua = uaf.getUserAccountByLogonId(userId);

IUserAccount uma = uaf.getMutableUserAccount(ua.getUniqueID());

IUserFactory uf = UMFactory.getUserFactory();

uma.setLocked(true,0);

uma.save();

uma.commit();

uf.invalidateCacheEntryByLogonId(userId);

************************************************************************

When I checked the status of this user "test" in user administration, the status is shown as locked. But when i tried to login with the user "test", I could login successfully.

Couldnt know how this happens. Any points to what is going wrong.

Thanks in advance.

Regards,

Yoga

PS: Useful answers will be rewarded.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi,

you need to use the mutable user account.create one button and on the action of the button put the following code.

try

{

IWDClientUser wdUser = WDClientUser.getCurrentUser();

IUser user = wdUser.getSAPUser();

IUserAccount[] acct = user.getUserAccounts();

String userId = acct[0].getLogonUid();

IUserAccountFactory accountFactory = UMFactory.getUserAccountFactory();

IUserAccount account = accountFactory.getUserAccountByLogonId("cindranil");

IUserAccount mutableAccount = accountFactory.getMutableUserAccount(account.getUniqueID());

mutableAccount.setLocked(false,IUserAccount.LOCKED_BY_ADMIN);

mutableAccount.save();

mutableAccount.commit();

}

catch(Exception e)

{

wdComponentAPI.getMessageManager().reportSuccess("Error");

}

regards

Indranil

reward points if useful

Former Member
0 Kudos

Hi Indranil

I am not using Webdynpro..I am writing a abstract portal component.

The code which you have posted and mine is one and the same.

I used mutable user account only.Still the same problem exists.

Regards,

Yoga

Former Member
0 Kudos

Hi,

Check this:

Regards,

Praveen Gudapati

0 Kudos

Hi,

Sorry that was my post with my other account, which is only for company use.

So if any points, assign here plz.

Regards,

Praveen Gudapati

Former Member
0 Kudos

Hi Praveen,

I checked your post earlier. As mentioned there, I cleared the UM cache for the particular user account. When I execute the code, the user account is getting locked. So the code as such works fine I guess. The issue is even after locking the account, I was able to login successfully with the same user account.

Regards,

Yoga

0 Kudos

Hi,

In your setLock method, try to set IUserAccount.LOCKED_BY_ADMIN

Regards,

Praveen Gudapati

Former Member
0 Kudos

Hi Praveen,

Thanks for your answer. It worked!

It doesnt work if we specify the lock reason parameter as IUserAccount.LOCKED_AUTO or IUserAccount.LOCKED_NO.

Regards,

Yoga

Answers (0)