Search in sources :

Example 6 with PasswordValidator

use of org.motechproject.security.validator.PasswordValidator in project motech by motech.

the class PasswordValidatorManager method getValidator.

/**
 * Retrieves a validator by the name it was registered with. The service property with the kye org.motechproject.security.validator_name
 * is treated as the name of the validator.
 * @param name the name of the validator
 * @return the validator, or null if it is missing
 */
public PasswordValidator getValidator(String name) {
    try {
        Collection<ServiceReference<PasswordValidator>> refs = bundleContext.getServiceReferences(PasswordValidator.class, null);
        for (ServiceReference<PasswordValidator> ref : refs) {
            PasswordValidator validator = bundleContext.getService(ref);
            if (StringUtils.equalsIgnoreCase(name, validator.getName())) {
                return validator;
            }
        }
        LOGGER.warn("Validator with name {} not found", name);
        return null;
    } catch (InvalidSyntaxException e) {
        throw new IllegalStateException("Unable to create a service filter expression", e);
    }
}
Also used : PasswordValidator(org.motechproject.security.validator.PasswordValidator) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

PasswordValidator (org.motechproject.security.validator.PasswordValidator)6 Test (org.junit.Test)3 MotechSettings (org.motechproject.config.domain.MotechSettings)1 PasswordValidatorException (org.motechproject.security.exception.PasswordValidatorException)1 MinLengthValidatorDecorator (org.motechproject.security.validator.impl.MinLengthValidatorDecorator)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1