Search in sources :

Example 1 with TenantDomainMismatchException

use of org.alfresco.repo.tenant.TenantDomainMismatchException in project acs-community-packaging by Alfresco.

the class CreateUserWizard method validateUsername.

/**
 * Validate Username field data is acceptable
 */
public void validateUsername(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    int minUsernameLength = Application.getClientConfig(context).getMinUsernameLength();
    String name = ((String) value).trim();
    if (name.length() < minUsernameLength || name.length() > 256) {
        String err = MessageFormat.format(Application.getMessage(context, LoginBean.MSG_USERNAME_LENGTH), new Object[] { minUsernameLength, 256 });
        throw new ValidatorException(new FacesMessage(err));
    }
    if (name.indexOf('"') != -1 || name.indexOf('\\') != -1) {
        String err = MessageFormat.format(Application.getMessage(context, LoginBean.MSG_USER_ERR), new Object[] { "\", \\" });
        throw new ValidatorException(new FacesMessage(err));
    }
    try {
        name = PersonServiceImpl.updateUsernameForTenancy(name, getTenantService());
    } catch (TenantDomainMismatchException e) {
        String err = MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), ERROR_DOMAIN_MISMATCH), e.getTenantA(), e.getTenantB());
        throw new ValidatorException(new FacesMessage(err));
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) TenantDomainMismatchException(org.alfresco.repo.tenant.TenantDomainMismatchException) FacesMessage(javax.faces.application.FacesMessage)

Example 2 with TenantDomainMismatchException

use of org.alfresco.repo.tenant.TenantDomainMismatchException in project alfresco-repository by Alfresco.

the class People method createPerson.

/**
 * Create a Person with an optionally generated user name
 *
 * @param userName userName or null for a generated user name
 * @param firstName firstName
 * @param lastName lastName
 * @param emailAddress emailAddress
 * @param password if not null creates a new authenticator with the given password.
 * @param setAccountEnabled
 *            set to 'true' to create enabled user account, or 'false' to
 *            create disabled user account for created person.
 * @param notifyByEmail
 *            set to 'true' to have the new user emailed to let them know
 *            their account details. Only applies if a username and
 *            password were supplied.
 * @return the person node (type cm:person) created or null if the person
 *         could not be created
 */
public ScriptNode createPerson(String userName, String firstName, String lastName, String emailAddress, String password, boolean setAccountEnabled, boolean notifyByEmail) {
    ParameterCheck.mandatory("firstName", firstName);
    ParameterCheck.mandatory("emailAddress", emailAddress);
    ScriptNode person = null;
    // generate user name if not supplied
    if (userName == null) {
        for (int i = 0; i < numRetries; i++) {
            userName = usernameGenerator.generateUserName(firstName, lastName, emailAddress, i);
            // create person if user name does not already exist
            if (!personService.personExists(userName)) {
                break;
            }
        }
    }
    if (userName != null) {
        try {
            userName = PersonServiceImpl.updateUsernameForTenancy(userName, tenantService);
        } catch (TenantDomainMismatchException re) {
            throw new AuthenticationException("User must belong to same domain as admin: " + re.getTenantA());
        }
        person = createPerson(userName, firstName, lastName, emailAddress);
        if (person != null && password != null) {
            // create account for person with the userName and password
            authenticationService.createAuthentication(userName, password.toCharArray());
            authenticationService.setAuthenticationEnabled(userName, setAccountEnabled);
            person.save();
            if (notifyByEmail) {
                personService.notifyPerson(userName, password);
            }
        }
    }
    return person;
}
Also used : TenantDomainMismatchException(org.alfresco.repo.tenant.TenantDomainMismatchException) AuthenticationException(org.alfresco.repo.security.authentication.AuthenticationException)

Aggregations

TenantDomainMismatchException (org.alfresco.repo.tenant.TenantDomainMismatchException)2 FacesMessage (javax.faces.application.FacesMessage)1 ValidatorException (javax.faces.validator.ValidatorException)1 AuthenticationException (org.alfresco.repo.security.authentication.AuthenticationException)1