use of org.apache.shiro.authc.credential.DefaultPasswordService in project ART-TIME by Artezio.
the class SettingsServiceTest method testUpdateAdminPassword.
@Test
public void testUpdateAdminPassword() {
Setting passwordSetting = new Setting(Setting.Name.ADMIN_PASSWORD, "old_password");
entityManager.persist(passwordSetting);
Settings settings = settingsService.getSettings();
DefaultPasswordService defaultPasswordService = new DefaultPasswordService();
Settings actual = settingsService.update(settings, "new_password");
assertNotNull(actual.getAdminPassword());
assertNotEquals("new_password", actual.getAdminPassword());
assertTrue(defaultPasswordService.passwordsMatch("new_password", actual.getAdminPassword()));
}
use of org.apache.shiro.authc.credential.DefaultPasswordService in project pac4j by pac4j.
the class ShiroEncoderBuilder method tryCreatePasswordEncoder.
public void tryCreatePasswordEncoder(final Map<String, PasswordEncoder> encoders) {
for (int i = 0; i <= MAX_NUM_ENCODERS; i++) {
final String exists = getProperty(SHIRO_ENCODER, i);
final boolean hasProperty = containsProperty(SHIRO_ENCODER_GENERATE_PUBLIC_SALT, i) || containsProperty(SHIRO_ENCODER_HASH_ALGORITHM_NAME, i) || containsProperty(SHIRO_ENCODER_HASH_ITERATIONS, i) || containsProperty(SHIRO_ENCODER_PRIVATE_SALT, i);
if (isNotBlank(exists) || hasProperty) {
final DefaultPasswordService passwordService = new DefaultPasswordService();
if (hasProperty) {
final DefaultHashService hashService = new DefaultHashService();
if (containsProperty(SHIRO_ENCODER_GENERATE_PUBLIC_SALT, i)) {
hashService.setGeneratePublicSalt(getPropertyAsBoolean(SHIRO_ENCODER_GENERATE_PUBLIC_SALT, i));
}
if (containsProperty(SHIRO_ENCODER_HASH_ALGORITHM_NAME, i)) {
hashService.setHashAlgorithmName(getProperty(SHIRO_ENCODER_HASH_ALGORITHM_NAME, i));
}
if (containsProperty(SHIRO_ENCODER_HASH_ITERATIONS, i)) {
hashService.setHashIterations(getPropertyAsInteger(SHIRO_ENCODER_HASH_ITERATIONS, i));
}
if (containsProperty(SHIRO_ENCODER_PRIVATE_SALT, i)) {
hashService.setPrivateSalt(ByteSource.Util.bytes(getProperty(SHIRO_ENCODER_PRIVATE_SALT, i)));
}
passwordService.setHashService(hashService);
}
encoders.put(concat(SHIRO_ENCODER, i), new ShiroPasswordEncoder(passwordService));
}
}
}
use of org.apache.shiro.authc.credential.DefaultPasswordService in project ART-TIME by Artezio.
the class SettingsService method update.
@FacesMessage(onCompleteMessageKey = "message.settingsAreSaved")
public Settings update(Settings settings, String password) {
PasswordService passwordService = new DefaultPasswordService();
String encryptedPassword = passwordService.encryptPassword(password);
settings.setAdminPassword(encryptedPassword);
return update(settings);
}
Aggregations