001
014
015 package com.liferay.portal.security.pwd;
016
017 import com.liferay.portal.exception.PwdEncryptorException;
018 import com.liferay.portal.kernel.util.GetterUtil;
019 import com.liferay.portal.kernel.util.PropsKeys;
020 import com.liferay.portal.kernel.util.StringUtil;
021 import com.liferay.portal.kernel.util.Validator;
022 import com.liferay.portal.util.PropsUtil;
023
024
027 public abstract class BasePasswordEncryptor implements PasswordEncryptor {
028
029 @Override
030 public String encrypt(String plainTextPassword, String encryptedPassword)
031 throws PwdEncryptorException {
032
033 return encrypt(
034 getDefaultPasswordAlgorithmType(), plainTextPassword,
035 encryptedPassword);
036 }
037
038 @Override
039 public String encrypt(
040 String algorithm, String plainTextPassword,
041 String encryptedPassword)
042 throws PwdEncryptorException {
043
044 if (Validator.isNull(plainTextPassword)) {
045 throw new PwdEncryptorException("Unable to encrypt blank password");
046 }
047
048 return doEncrypt(algorithm, plainTextPassword, encryptedPassword);
049 }
050
051 @Override
052 public String getDefaultPasswordAlgorithmType() {
053 return _PASSWORDS_ENCRYPTION_ALGORITHM;
054 }
055
056 protected abstract String doEncrypt(
057 String algorithm, String plainTextPassword,
058 String encryptedPassword)
059 throws PwdEncryptorException;
060
061 private static final String _PASSWORDS_ENCRYPTION_ALGORITHM =
062 StringUtil.toUpperCase(
063 GetterUtil.getString(
064 PropsUtil.get(PropsKeys.PASSWORDS_ENCRYPTION_ALGORITHM)));
065
066 }