on 03-09-2007 6:07 AM
Hi Everybody,
I have a scenario of chaging the portal user password from web dynpro application.
I tried using :
IUserAccount IUA = UMFactory.getUserAccountFactory().getMutableUserAccount("USER.PRIVATE_DATASOURCE.un:enteg2");
IUA.setPassword("password123");
Where "USER.PRIVATE_DATASOURCE.un:user" is the unique-id of the user.
But I am getting an error as
<b>EXCEPTION : com.sap.security.api.NoSuchUserAccountException: The given id "USER.PRIVATE_DATASOURCE.un:enteg2"is not a unique id of a user account!</b>
This unique-id has been taken from the user profile. Even I tried using the function to get the unique user-id and passing as a parameter to this but still its not working . Same error.
We have used LDAP ADS (Through SSL configuration) to store the user details.
<b>We were able to change the password directly from User Profile area in portal.</b>
Can anyone please guide me is there anyother way to do it.
Thanks.
Nirmal
Hi Nirmal,
Please find some code we use. The changePassword method allows (the user) to change the password, provided the current password is known. The resetPassword generates a new password (without knowing the current password) for a user account with a given email address.
// uid without namespace prefix, e.g. "enteg2" instead of
// e.g. "USER.PRIVATE_DATASOURCE.un:enteg2" or "USER.R3_DATASOURCE.enteg2"
private void changePassword(String uid, String oldPassword, String newPassword)
throws
UMException,
NoSuchUserException,
NoSuchPrincipalException,
InvalidPasswordException {
IUserFactory uf = UMFactory.getUserFactory();
IUser u = uf.getUserByLogonID(uid);
for (Iterator i = u.getUserAccountUniqueIDs(); i.hasNext();) {
IUserAccountFactory uaf = UMFactory.getUserAccountFactory();
IUserAccount ua = uaf.getMutableUserAccount((String) i.next());
ua.setPassword(oldPassword, newPassword);
//ua.setPasswordChangeRequired(false);
ua.commit();
}
}
private void resetPassword(String email)
throws
UMException,
FeatureNotAvailableException,
NoSuchUserException,
NoSuchPrincipalException,
InvalidPasswordException {
IUser[] users = getUsersByEmail(email);
if (users.length == 1) { // only reset password in case email is unique
IUser user = users[0];
String userid = user.getName();
String password = resetPassword(user);
// feedback, e.g. email userid / password
}
}
private IUser[] getUsersByEmail(String email)
throws UMException, FeatureNotAvailableException, NoSuchUserException {
IUserFactory uf = UMFactory.getUserFactory();
IUserSearchFilter usf = uf.getUserSearchFilter();
usf.setEmail(email, ISearchAttribute.EQUALS_OPERATOR, false);
ISearchResult sr = uf.searchUsers(usf);
if (ISearchResult.SEARCH_RESULT_OK != sr.getState()) {
throw new UMException("ISearchResult state is " + sr.getState());
}
IUser[] users = new IUser[sr.size()];
for (int j = 0; sr.hasNext(); j++) {
users[j] = uf.getUser((String) sr.next());
}
return users;
}
private String resetPassword(IUser user)
throws UMException, NoSuchPrincipalException, InvalidPasswordException {
String password = generatePassword();
for (Iterator i = user.getUserAccountUniqueIDs(); i.hasNext();) {
IUserAccountFactory uaf = UMFactory.getUserAccountFactory();
IUserAccount ua = uaf.getMutableUserAccount((String) i.next());
ua.setPassword(password);
ua.setPasswordChangeRequired(false);
ua.commit();
}
return password;
}
private String generatePassword() {
ISecurityPolicy sp = UMFactory.getSecurityPolicy();
return sp.generatePassword();
}
Kind regards,
Sigiswald
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nirmal,
Try getting the IUser object first and then use method "getUserAccounts()" on the same.
for gettting IUser object, you can use WDClientUser and all.
Regards,
Mausam
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.