Package br.net.woodstock.rockframework.security.util

Source Code of br.net.woodstock.rockframework.security.util.DigesterPasswordEncoder

/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.security.util;

import java.io.Serializable;

import br.net.woodstock.rockframework.core.RockFrameworkVersion;
import br.net.woodstock.rockframework.core.util.Assert;
import br.net.woodstock.rockframework.security.EncodingType;
import br.net.woodstock.rockframework.security.digest.DigestType;
import br.net.woodstock.rockframework.security.digest.Digester;
import br.net.woodstock.rockframework.security.digest.impl.AsStringDigester;
import br.net.woodstock.rockframework.security.digest.impl.Base64Digester;
import br.net.woodstock.rockframework.security.digest.impl.BasicDigester;
import br.net.woodstock.rockframework.security.digest.impl.HexDigester;

public class DigesterPasswordEncoder implements PasswordEncoder, Serializable {

  private static final long  serialVersionUID  = RockFrameworkVersion.VERSION;

  private AsStringDigester  digester;

  public DigesterPasswordEncoder(final DigestType type) {
    super();
    Assert.notNull(type, "type");
    Digester basic = new BasicDigester(type);
    Digester base64 = new Base64Digester(basic);
    this.digester = new AsStringDigester(base64);
  }

  public DigesterPasswordEncoder(final DigestType digestType, final EncodingType encodingType) {
    super();
    Assert.notNull(digestType, "digestType");
    Assert.notNull(encodingType, "encodingType");
    Digester basic = new BasicDigester(digestType);
    Digester encoded = null;
    if (encodingType == EncodingType.HEX) {
      encoded = new HexDigester(basic);
    } else {
      encoded = new Base64Digester(basic);
    }
    this.digester = new AsStringDigester(encoded);
  }

  @Override
  public String encode(final String password) {
    return this.digester.digestAsString(password);
  }
}
TOP

Related Classes of br.net.woodstock.rockframework.security.util.DigesterPasswordEncoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.