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