cancel
Showing results for 
Search instead for 
Did you mean: 

How to delete a user via UME

cand1
Advisor
Advisor
0 Kudos

Hi everybody,

I've created a user with the following lines:

String testUserId = "User0815";

IUserMaint user = userFactory.newUser(testUserId);

user.setFirstName("firstname");

user.setLastName("lastname");

user.setEmail("first.last@test.de");

user.commit();

IUserAccount userAccount = userAccountFactory.newUserAccount(testUserId, user.getUniqueID());

userAccount.setPassword("secret");

userAccount.setPasswordChangeRequired(false);

userAccount.save();

userAccount.commit();

This works fine, but afterwards I want to the delete the user and the according account with

IUser userToDelete = userFactory.getUserByLogonID(testDUserId);

userFactory.deleteUser(userToDelete.getUniqueID());

The second call to

IUserMaint user = userFactory.newUser(testUserId);

gives me a com.sap.security.api.UserAlreadyExistsException, i.e. it seems the user was not deleted. So my question is, what's the right way to delete an user?

Best Regards,

Daniel

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

What is your data source? Check whether the userid actually present there? Were any exceptions raised? Put a print in the catch statement and see if there is any error.

The code you have given seems to be correct, except that I did it as below and it worked. Try this way.

IUser user=uf.getUserByUniqueName(strUserID);

String strUniqueUserID=user.getUniqueID();

uf.deleteUser(strUniqueUserID);

Good luck

Bhanu

cand1
Advisor
Advisor
0 Kudos

Hi Bhanu,

IUser userToDelete = userFactory.getUserByUniqueName(testDUserId);

was the key.

BTW: The difference between getUserByUniqueName() and getUserByLogonID() is not clear to me, but never mind, it works.

Thanks,

Daniel

Former Member
0 Kudos

To view the difference in EP6:

User Admin -> Roles -> do a search on the userid -> edit

you will see the unique id differs quite a bit from the user id. Same for roles etc...

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

What is your data source? Check whether the userid actually present there? Were any exceptions raised? Put a print in the catch statement and see if there is any error.

The code you have given seems to be correct, except that I did it as below and it worked. Try this way.

IUser user=uf.getUserByUniqueName(strUserID);

String strUniqueUserID=user.getUniqueID();

uf.deleteUser(strUniqueUserID);

Good luck

Bhanu

Former Member
0 Kudos

Based on the API this looks like the correct method.

But you could try calling this method afterwards on the IUserAccountFactory and see if it helps

invalidateCacheEntry

public void invalidateCacheEntry(java.lang.String uniqueid)

throws UMExceptionremoves the user account object which has the specified uniqueid from the factory's cache Note: Use this method carefully, because calling it too often may cause performance problems