on 01-03-2012 4:13 PM
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
Attribute names are unlocktext, locktext from namespace com.sap.security.core.usermanagement
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.