Java Code Examples for com.google.api.services.admin.directory.model.User#setName()
The following examples show how to use
com.google.api.services.admin.directory.model.User#setName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GoogleDirectory.java From account-provisioning-for-google-apps with Apache License 2.0 | 5 votes |
/** * 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(); }
Example 2
Source File: GoogleProvisioningConnector.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Buld Google user object to provision * * @param provisioningEntity * @return */ protected User updateGoogleUser(ProvisioningEntity provisioningEntity) { User updateUser = new User(); updateUser.setPrimaryEmail(provisioningEntity.getIdentifier().getIdentifier()); UserName username = new UserName(); String defaultFamilyNameKey = "google_prov_familyname"; String defaultGivenNameKey = "google_prov_givenname"; String familyNameClaimKey = "google_prov_familyname_claim_dropdown"; String givenNameClaimKey = "google_prov_givenname_claim_dropdown"; Map<String, String> requiredAttributes = getSingleValuedClaims(provisioningEntity .getAttributes()); if (MapUtils.isEmpty(requiredAttributes)) { return null; } // Set given name String givenNameClaim = this.configHolder.getValue(givenNameClaimKey); String givenNameValue = requiredAttributes.get(givenNameClaim); if (StringUtils.isBlank(givenNameValue)) { String defaultGivenNameValue = this.configHolder.getValue(defaultGivenNameKey); if (StringUtils.isNotBlank(defaultGivenNameValue)) { givenNameValue = defaultGivenNameValue; } } if (log.isDebugEnabled()) { log.debug("New Google user given name : " + givenNameValue); } username.setGivenName(givenNameValue); // Set family name String familyNameClaim = this.configHolder.getValue(familyNameClaimKey); String familyNameValue = requiredAttributes.get(familyNameClaim); if (StringUtils.isBlank(familyNameValue)) { String defaultFamilyNameValue = this.configHolder.getValue(defaultFamilyNameKey); if (StringUtils.isNotBlank(defaultFamilyNameValue)) { familyNameValue = defaultFamilyNameValue; } } if (log.isDebugEnabled()) { log.debug("New Google user family name : " + familyNameValue); } username.setFamilyName(familyNameValue); updateUser.setName(username); updateUser.setPassword(generatePassword()); return updateUser; }