com.google.api.services.admin.directory.model.User

Here are the examples of the java api class com.google.api.services.admin.directory.model.User taken from open source projects.

1. GoogleDirectoryTest#testCreateUser()

Project: account-provisioning-for-google-apps
File: GoogleDirectoryTest.java
/**
   * Test method for
   * {@link apps.provisioning.server.apis.GoogleDirectory#createUser(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}
   * .
   *
   * @throws Exception
   * @throws IOException
   */
@Test
public final void testCreateUser() throws IOException, Exception {
    String firstname = "Carlos";
    String lastname = "Alvares";
    String password = "12345678";
    User user = googleDirectory.createUser(NOT_EXISTING_USERNAME, firstname, lastname, password);
    if (user == null) {
        fail("User hasn't been created.");
    } else {
        googleDirectory.remove(NOT_EXISTING_USERNAME);
    }
}

2. GoogleDirectory#createUser()

Project: account-provisioning-for-google-apps
File: GoogleDirectory.java
/**
   * Creates a user in Google Apps Diretory.
   *
   * @param username Username without domain.
   * @param firstname First name
   * @param lastname Last name
   * @param password Password with 8 characters or longer.
   * @return The created user.
   * @throws IOException
   * @throws Exception When values are null, empty, shorter or longer than allowed.
   */
public User createUser(String username, String firstname, String lastname, String password) throws IOException, Exception {
    if (username == null || firstname == null || lastname == null || password == null) {
        throw new Exception("Null values are not allowed.");
    }
    if (username.isEmpty() || firstname.isEmpty() || lastname.isEmpty() || password.isEmpty()) {
        throw new Exception("All the parameters must be filled.");
    }
    if (username.length() > UsernameManager.MAX_USERNAME_LENGTH || firstname.length() > UsernameManager.MAX_NAME_LENGTH || lastname.length() > UsernameManager.MAX_NAME_LENGTH || password.length() > UsernameManager.MAX_PASSWORD_LENGTH) {
        throw new Exception("One of the fields exceds the maximum length. 60 (firstname,lastname), 64 (username)," + " 100 (password)");
    }
    if (password.length() < UsernameManager.MIN_PASSWORD_LENGTH) {
        throw new Exception("Password must have at least 8 characters.");
    }
    User user = new User();
    UserName name = new UserName();
    name.setGivenName(firstname);
    name.setFamilyName(lastname);
    user.setName(name);
    user.setPrimaryEmail(getEmail(username));
    user.setPassword(password);
    return directory.users().insert(user).execute();
}