Search in sources :

Example 1 with DefaultPasswordService

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()));
}
Also used : DefaultPasswordService(org.apache.shiro.authc.credential.DefaultPasswordService) Setting(com.artezio.arttime.config.Setting) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test)

Example 2 with DefaultPasswordService

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));
        }
    }
}
Also used : DefaultPasswordService(org.apache.shiro.authc.credential.DefaultPasswordService) DefaultHashService(org.apache.shiro.crypto.hash.DefaultHashService) ShiroPasswordEncoder(org.pac4j.core.credentials.password.ShiroPasswordEncoder)

Example 3 with DefaultPasswordService

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);
}
Also used : DefaultPasswordService(org.apache.shiro.authc.credential.DefaultPasswordService) PasswordService(org.apache.shiro.authc.credential.PasswordService) DefaultPasswordService(org.apache.shiro.authc.credential.DefaultPasswordService) FacesMessage(com.artezio.arttime.web.interceptors.FacesMessage)

Aggregations

DefaultPasswordService (org.apache.shiro.authc.credential.DefaultPasswordService)3 Setting (com.artezio.arttime.config.Setting)1 Settings (com.artezio.arttime.config.Settings)1 FacesMessage (com.artezio.arttime.web.interceptors.FacesMessage)1 PasswordService (org.apache.shiro.authc.credential.PasswordService)1 DefaultHashService (org.apache.shiro.crypto.hash.DefaultHashService)1 Test (org.junit.Test)1 ShiroPasswordEncoder (org.pac4j.core.credentials.password.ShiroPasswordEncoder)1