All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.vt.middleware.password.SourceRule Maven / Gradle / Ivy

The newest version!
/*
  $Id: SourceRule.java 2704 2013-04-24 21:30:32Z dfisher $

  Copyright (C) 2003-2013 Virginia Tech.
  All rights reserved.

  SEE LICENSE FOR MORE INFORMATION

  Author:  Middleware Services
  Email:   [email protected]
  Version: $Revision: 2704 $
  Updated: $Date: 2013-04-24 17:30:32 -0400 (Wed, 24 Apr 2013) $
*/
package edu.vt.middleware.password;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Rule for determining if a password matches a password from a different
 * source. Useful for when separate systems cannot have matching passwords. If
 * no sources have been set or an empty source has been set, then passwords will
 * meet this rule.
 *
 * @author  Middleware Services
 * @version  $Revision: 2704 $ $Date: 2013-04-24 17:30:32 -0400 (Wed, 24 Apr 2013) $
 */
public class SourceRule extends AbstractDigester implements Rule
{

  /** Error code for regex validation failures. */
  public static final String ERROR_CODE = "SOURCE_VIOLATION";


  /** {@inheritDoc} */
  @Override
  public RuleResult validate(final PasswordData passwordData)
  {
    final RuleResult result = new RuleResult(true);
    if (passwordData.getPasswordSources().isEmpty()) {
      return result;
    }

    final String cleartext = passwordData.getPassword().getText();
    for (String source : passwordData.getPasswordSources().keySet()) {
      if (matches(cleartext, passwordData.getPasswordSources().get(source))) {
        result.setValid(false);
        result.getDetails().add(
          new RuleResultDetail(
            ERROR_CODE,
            createRuleResultDetailParameters(source)));
      }
    }
    return result;
  }


  /**
   * Creates the parameter data for the rule result detail.
   *
   * @param  source  matching source
   *
   * @return  map of parameter name to value
   */
  protected Map createRuleResultDetailParameters(final String source)
  {
    final Map m = new LinkedHashMap();
    m.put("source", source);
    return m;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy