Example usage for org.apache.commons.lang StringUtils isAlphanumeric

List of usage examples for org.apache.commons.lang StringUtils isAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isAlphanumeric.

Prototype

public static boolean isAlphanumeric(String str) 

Source Link

Document

Checks if the String contains only unicode letters or digits.

Usage

From source file:org.medici.bia.service.user.UserServiceImpl.java

/**
 * {@inheritDoc}//from w w w .j  a  v a  2  s .  co m
 */
@Override
public Integer ratePassword(String password) {
    if ((password == null) || password.equals(""))
        return 0;

    if (password.length() < 8)
        return 1;

    if (StringUtils.isAlpha(password))
        return 2;

    if (StringUtils.isAlphanumeric(password))
        return 3;

    if (StringUtils.isAsciiPrintable(password))
        return 4;

    return 0;
}

From source file:org.mifos.application.servicefacade.LoginServiceFacadeWebTier.java

@Override
public void validatePassword(String password, Errors errors) {
    if (password.length() < PasswordRules.getMinPasswordLength()) {
        errors.reject(PersonnelConstants.ERROR_PASSWORD_LENGTH,
                new Integer[] { PasswordRules.getMinPasswordLength() },
                "Password should have the minimum length of " + PasswordRules.getMinPasswordLength()
                        + " characters.");
    }//from  w ww  .  j  av a 2  s.  com

    if (PasswordRules.isMustContainDigit() && !password.matches(".*\\d.*")) {
        errors.reject(PersonnelConstants.ERROR_PASSWORD_DIGIT);
    }

    if (PasswordRules.isMustContainSpecial() && StringUtils.isAlphanumeric(password)) {
        errors.reject(PersonnelConstants.ERROR_PASSWORD_SPECIAL);
    }

    if (PasswordRules.isMustContainBothCaseLetters() && !password.matches(".*[a-z]*[A-Z].*")) { //contains at least one upper and lower case letter?
        errors.reject(PersonnelConstants.ERROR_PASSWORD_BOTH_CASE);
    }
}

From source file:org.mifos.security.login.struts.actionforms.LoginActionForm.java

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    String method = request.getParameter(Methods.method.toString());
    if (method.equals(Methods.login.toString()) || method.equals(Methods.updatePassword.toString())) {
        errors.add(super.validate(mapping, request));
        if (method.equals(Methods.updatePassword.toString())) {
            if (newPassword.equals(oldPassword)) {
                errors.add(LoginConstants.SAME_OLD_AND_NEW_PASSWORD,
                        new ActionMessage(LoginConstants.SAME_OLD_AND_NEW_PASSWORD));
            }/*from  w  ww . j av a 2s .co  m*/
            if (newPassword.length() < PasswordRules.getMinPasswordLength()) {
                errors.add(PersonnelConstants.ERROR_PASSWORD_LENGTH,
                        new ActionMessage(PersonnelConstants.ERROR_PASSWORD_LENGTH,
                                new Integer[] { PasswordRules.getMinPasswordLength() }));
            }

            if (PasswordRules.isMustContainDigit() && !newPassword.matches(".*\\d.*")) {
                errors.add(PersonnelConstants.ERROR_PASSWORD_DIGIT,
                        new ActionMessage(PersonnelConstants.ERROR_PASSWORD_DIGIT));
            }

            if (PasswordRules.isMustContainSpecial() && StringUtils.isAlphanumeric(newPassword)) {
                errors.add(PersonnelConstants.ERROR_PASSWORD_SPECIAL,
                        new ActionMessage(PersonnelConstants.ERROR_PASSWORD_SPECIAL));
            }

            if (PasswordRules.isMustContainBothCaseLetters() && !newPassword.matches(".*[a-z]*[A-Z].*")) { //contains at least one upper and lower case letter?
                errors.add(PersonnelConstants.ERROR_PASSWORD_BOTH_CASE,
                        new ActionMessage(PersonnelConstants.ERROR_PASSWORD_BOTH_CASE));
            }
        }
    }
    if (!method.equals(Methods.validate.toString())) {
        request.setAttribute(LoginConstants.METHODCALLED, method);
    }
    return errors;
}

From source file:org.onebusaway.enterprise.webapp.actions.m.ColorStylesheetAction.java

public void setColors(String c) {
    if (c == null) {
        return;// www  . ja  v a 2  s .  co  m
    }

    String[] colors = c.split(",");
    for (String color : colors) {
        if (StringUtils.isAlphanumeric(color)) {
            _colors.add(color);
        }
    }
}

From source file:org.silverpeas.admin.domain.AbstractDomainService.java

/**
 * Check domain's name validity (no white spaces, only alphanumeric characters, no duplicate in
 * database)/* w ww  .  j  a  v a  2 s  .  c om*/
 * @param domainName the new domain name
 * @throws DomainConflictException if domain name is not valid
 * @throws AdminException if a technical problem occurs during checks
 */
protected void checkDomainName(String domainName) throws DomainConflictException, AdminException {

    // Check 1 - Detects white spaces in domain name
    if (StringUtils.contains(domainName, ' ')) {
        throw new WhiteSpacesDetectedException(domainName);
    }

    // Check 2 - Detects non-alphanumerics characters
    if (!StringUtils.isAlphanumeric(domainName)) {
        throw new NonAlphaNumericDetectedException(domainName);
    }

    // Check 3 - Check domain name availability in database
    Admin adminService = AdminReference.getAdminService();
    Domain[] tabDomain = adminService.getAllDomains();
    for (Domain domain : tabDomain) {
        if (domain.getName().equalsIgnoreCase(domainName)) {
            throw new NameAlreadyExistsInDatabaseException(domainName);
        }
    }
}

From source file:org.sonar.plugins.gosu.codenarc.apt.AptParser.java

private static String getRuleName(String line) {
    if (StringUtils.isBlank(line)) {
        return null;
    }/* ww  w  . j av  a  2 s.c om*/
    String result = null;
    if (line.startsWith("* {")) {
        result = StringUtils.substringBetween(line, "* {", "} Rule").trim();
    } else {
        result = line.substring(2).trim();
    }
    if (result.endsWith("Rule")) {
        result = result.substring(0, result.length() - 4);
    }
    if (StringUtils.isAllLowerCase(result) || !StringUtils.isAlphanumeric(result)
            || "References".equals(result)) {
        // false positive
        return null;
    }
    return result;
}

From source file:org.sonar.updatecenter.common.PluginKeyUtils.java

public static boolean isValid(String pluginKey) {
    return StringUtils.isNotBlank(pluginKey) && StringUtils.isAlphanumeric(pluginKey);
}

From source file:org.structr.common.StructrAndSpatialPredicate.java

private boolean isStructrEntity(final T container) {

    if (container.hasProperty(idName)) {

        final Object idObject = container.getProperty(idName);
        if (idObject instanceof String) {

            final String id = (String) idObject;

            if (id.length() == 32 && StringUtils.isAlphanumeric(id)) {

                // id is a Structr uuid
                if (container.hasProperty(typeName)) {

                    final Object typeObject = container.getProperty(typeName);
                    if (typeObject instanceof String) {

                        final String type = (String) typeObject;

                        // return true if type is an existing node entity
                        if (configuration.getNodeEntities().containsKey(type)) {
                            return true;
                        }//from  w  w w.j  a  v  a2 s .c  om

                        // return true if type is an existing relationship entity
                        if (configuration.getRelationshipEntities().containsKey(type)) {
                            return true;
                        }
                    }
                }
            }
        }
    }

    return false;
}

From source file:org.telscenter.sail.webapp.domain.impl.Projectcode.java

/**
 * Checks if this projectcode is legal syntactically
 * //ww  w.j  a  va 2 s  .co m
 * @return <code>true</code> iff provided projectcode is legal
 */
public boolean isLegalProjectcode() {
    if (StringUtils.contains(projectcode, SEPARATOR)) {
        String runcode = getRuncode();
        String periodname = getRunPeriod();
        if (!StringUtils.isEmpty(runcode) && !StringUtils.isEmpty(periodname)
                && StringUtils.isAlphanumeric(runcode) && StringUtils.isAlphanumeric(periodname)) {
            return true;
        }
    }
    return false;
}

From source file:org.telscenter.sail.webapp.presentation.validators.UserAccountFormValidator.java

/**
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 *///from www.  ja v a2  s.  c  o m
public void validate(Object userAccountFormIn, Errors errors) {
    UserAccountForm userAccountForm = (UserAccountForm) userAccountFormIn;
    MutableUserDetails userDetails = userAccountForm.getUserDetails();

    if (userAccountForm.isNewAccount()) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.password",
                "error.password-not-specified");

        if (errors.getFieldErrorCount("userDetails.password") > 0) {
            return;
        }

        if (userDetails.getPassword().length() > MAX_PASSWORD_LENGTH) {
            errors.rejectValue("userDetails.password", "error.password-too-long");
            return;
        }

        if (!StringUtils.isAlphanumeric(userDetails.getPassword())) {
            errors.rejectValue("userDetails.password", "error.password-illegal-characters");
            return;
        }

        if (userDetails.getSignupdate() == null) {
            errors.rejectValue("userDetails.signupdate", "error.signupdate-not-specified");
            return;
        }
    } else {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.username",
                "error.username-not-specified");

        if (!StringUtils.isAlphanumeric(userDetails.getUsername())) {
            errors.rejectValue("userDetails.username", "error.illegal-characters");
        }
    }

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.firstname", "error.firstname-not-specified");

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userDetails.lastname", "error.lastname-not-specified");

    if (!StringUtils.isAlphanumeric(userDetails.getFirstname())
            || !StringUtils.isAsciiPrintable(userDetails.getFirstname())) {
        errors.rejectValue("userDetails.firstname", "error.firstname-illegal-characters");
        return;
    }

    if (!StringUtils.isAlphanumeric(userDetails.getLastname())
            || !StringUtils.isAsciiPrintable(userDetails.getLastname())) {
        errors.rejectValue("userDetails.lastname", "error.lastname-illegal-characters");
        return;
    }

    if (errors.hasErrors())
        userDetails.setPassword("");
}