Creating Users

Prerequisites

You have imported the required interfaces and gotten the required factories.

More information: User Management Functions for Users .

Context

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.

Procedure

  1. Use the IUserMaint interface to create a new and modifiable user object.
  2. Set any required attributes.
  3. Use the IUserAccountFactory to create the user account object.
  4. Use the setPassword() method to create a password for the user account.
  5. Commit your changes.

Example

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.
	}

}