
You have imported the required interfaces and gotten the required factories.
More information: User Management Functions for Users .
This procedure describes how to create a user programmatically in the user store. Use this procedure if you cannot use the existing user administration tools to create a user and need to customize your tools to create users programmatically.
The following example creates a user and user account with the name demo_user. It also sets the last name and password for this user.
public static void createUser(String userName, String lastName,
String securePassword) {
/*
* TODO: By whatever means you set these variables you must check that
* userName and securePassword comply with the security policy settings
* or be prepared to catch the exception when they do not comply.
*/
try {
IUserMaint mutableUser = userFactory.newUser(userName);
/*
* Set the LastName attribute of the user. Note: The user attribute
* last name is mandatory for AS ABAP data source.
*/
mutableUser.setLastName(lastName);
// Create a new user account with userName.
IUserAccount userAccount = userAccountFactory.newUserAccount(userName);
// Get the initial password of the user account.
userAccount.setPassword(securePassword);
// Write the changes to the user store in a single
// transaction.
userFactory.commitUser(mutableUser, userAccount);
} catch (UserAlreadyExistsException uaee) {
// TODO: Handle UserAlreadyExistsException.
} catch (UserAccountAlreadyExistsException uaaee) {
// TODO: Handle UserAccountAlreadyExistsException.
} catch (UMException umex) {
// TODO: Handle UMException.
} catch (UMRuntimeException umrex) {
// TODO: Handle UMRuntimeException.
}
}