Search in sources :

Example 6 with StandardPasswordEncoder

use of org.springframework.security.crypto.password.StandardPasswordEncoder in project oc-explorer by devgateway.

the class EditUserPage method getSaveEditPageButton.

@Override
public SaveEditPageButton getSaveEditPageButton() {
    return new SaveEditPageButton("save", new StringResourceModel("save", EditUserPage.this, null)) {

        private static final long serialVersionUID = 5214537995514151323L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            Person saveable = editForm.getModelObject();
            StandardPasswordEncoder encoder = new StandardPasswordEncoder("");
            // encode the password
            if (saveable.getChangePass()) {
                saveable.setPassword(encoder.encode(password.getField().getModelObject()));
            } else {
                if (saveable.getPassword() == null || saveable.getPassword().compareTo("") == 0) {
                    feedbackPanel.error(new StringResourceModel("nullPassword", this, null).getString());
                    target.add(feedbackPanel);
                    return;
                }
            }
            // it again next time
            if (isChangePassPage()) {
                saveable.setChangePassword(false);
            }
            ensureDefaultDashboardIsAlsoAssignedDashboard(saveable);
            jpaRepository.save(saveable);
            if (!SecurityUtil.isCurrentUserAdmin()) {
                setResponsePage(Homepage.class);
            } else {
                setResponsePage(listPageClass);
            }
        }
    };
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) Form(org.apache.wicket.markup.html.form.Form) StringResourceModel(org.apache.wicket.model.StringResourceModel) Person(org.devgateway.toolkit.persistence.dao.Person)

Example 7 with StandardPasswordEncoder

use of org.springframework.security.crypto.password.StandardPasswordEncoder in project pac4j by pac4j.

the class SpringEncoderBuilder method tryCreatePasswordEncoder.

public void tryCreatePasswordEncoder(final Map<String, org.pac4j.core.credentials.password.PasswordEncoder> encoders) {
    for (int i = 0; i <= MAX_NUM_ENCODERS; i++) {
        final String type = getProperty(SPRING_ENCODER_TYPE, i);
        if (isNotBlank(type)) {
            final PasswordEncoder encoder;
            if (SpringEncoderType.NOOP.toString().equalsIgnoreCase(type)) {
                encoder = NoOpPasswordEncoder.getInstance();
            } else if (SpringEncoderType.BCRYPT.toString().equalsIgnoreCase(type)) {
                if (containsProperty(SPRING_ENCODER_BCRYPT_LENGTH, i)) {
                    encoder = new BCryptPasswordEncoder(getPropertyAsInteger(SPRING_ENCODER_BCRYPT_LENGTH, i));
                } else {
                    encoder = new BCryptPasswordEncoder();
                }
            } else if (SpringEncoderType.PBKDF2.toString().equalsIgnoreCase(type)) {
                if (containsProperty(SPRING_ENCODER_PBKDF2_SECRET, i)) {
                    final String secret = getProperty(SPRING_ENCODER_PBKDF2_SECRET, i);
                    if (containsProperty(SPRING_ENCODER_PBKDF2_ITERATIONS, i) && containsProperty(SPRING_ENCODER_PBKDF2_HASH_WIDTH, i)) {
                        encoder = new Pbkdf2PasswordEncoder(secret, getPropertyAsInteger(SPRING_ENCODER_PBKDF2_ITERATIONS, i), getPropertyAsInteger(SPRING_ENCODER_PBKDF2_HASH_WIDTH, i));
                    } else {
                        encoder = new Pbkdf2PasswordEncoder(secret);
                    }
                } else {
                    encoder = new Pbkdf2PasswordEncoder();
                }
            } else if (SpringEncoderType.SCRYPT.toString().equalsIgnoreCase(type)) {
                if (containsProperty(SPRING_ENCODER_SCRYPT_CPU_COST, i) && containsProperty(SPRING_ENCODER_SCRYPT_MEMORY_COST, i) && containsProperty(SPRING_ENCODER_SCRYPT_PARALLELIZATION, i) && containsProperty(SPRING_ENCODER_SCRYPT_KEY_LENGTH, i) && containsProperty(SPRING_ENCODER_SCRYPT_SALT_LENGTH, i)) {
                    encoder = new SCryptPasswordEncoder(getPropertyAsInteger(SPRING_ENCODER_SCRYPT_CPU_COST, i), getPropertyAsInteger(SPRING_ENCODER_SCRYPT_MEMORY_COST, i), getPropertyAsInteger(SPRING_ENCODER_SCRYPT_PARALLELIZATION, i), getPropertyAsInteger(SPRING_ENCODER_SCRYPT_KEY_LENGTH, i), getPropertyAsInteger(SPRING_ENCODER_SCRYPT_SALT_LENGTH, i));
                } else {
                    encoder = new SCryptPasswordEncoder();
                }
            } else if (SpringEncoderType.STANDARD.toString().equalsIgnoreCase(type)) {
                if (containsProperty(SPRING_ENCODER_STANDARD_SECRET, i)) {
                    encoder = new StandardPasswordEncoder(getProperty(SPRING_ENCODER_STANDARD_SECRET, i));
                } else {
                    encoder = new StandardPasswordEncoder();
                }
            } else {
                throw new TechnicalException("Unsupported spring encoder type: " + type);
            }
            encoders.put(concat(SPRING_ENCODER, i), new SpringSecurityPasswordEncoder(encoder));
        }
    }
}
Also used : StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) TechnicalException(org.pac4j.core.exception.TechnicalException) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) SpringSecurityPasswordEncoder(org.pac4j.core.credentials.password.SpringSecurityPasswordEncoder) NoOpPasswordEncoder(org.springframework.security.crypto.password.NoOpPasswordEncoder) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) SpringSecurityPasswordEncoder(org.pac4j.core.credentials.password.SpringSecurityPasswordEncoder) Pbkdf2PasswordEncoder(org.springframework.security.crypto.password.Pbkdf2PasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)

Example 8 with StandardPasswordEncoder

use of org.springframework.security.crypto.password.StandardPasswordEncoder in project oc-explorer by devgateway.

the class WebSecurityConfig method configureGlobal.

@Autowired
public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception {
    // we use standard password encoder for all passwords
    StandardPasswordEncoder spe = new StandardPasswordEncoder();
    auth.userDetailsService(customJPAUserDetailsService).passwordEncoder(spe);
}
Also used : StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 9 with StandardPasswordEncoder

use of org.springframework.security.crypto.password.StandardPasswordEncoder in project tutorials by eugenp.

the class PasswordStorageWebSecurityConfigurer method passwordEncoder.

@Bean
public PasswordEncoder passwordEncoder() {
    // set up the list of supported encoders and their prefixes
    PasswordEncoder defaultEncoder = new StandardPasswordEncoder();
    Map<String, PasswordEncoder> encoders = new HashMap<>();
    encoders.put("bcrypt", new BCryptPasswordEncoder());
    encoders.put("scrypt", new SCryptPasswordEncoder());
    encoders.put("noop", NoOpPasswordEncoder.getInstance());
    DelegatingPasswordEncoder passwordEncoder = new DelegatingPasswordEncoder("bcrypt", encoders);
    passwordEncoder.setDefaultPasswordEncoderForMatches(defaultEncoder);
    return passwordEncoder;
}
Also used : StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) StandardPasswordEncoder(org.springframework.security.crypto.password.StandardPasswordEncoder) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) NoOpPasswordEncoder(org.springframework.security.crypto.password.NoOpPasswordEncoder) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) HashMap(java.util.HashMap) SCryptPasswordEncoder(org.springframework.security.crypto.scrypt.SCryptPasswordEncoder) DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Bean(org.springframework.context.annotation.Bean)

Aggregations

StandardPasswordEncoder (org.springframework.security.crypto.password.StandardPasswordEncoder)9 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)4 SCryptPasswordEncoder (org.springframework.security.crypto.scrypt.SCryptPasswordEncoder)4 NoOpPasswordEncoder (org.springframework.security.crypto.password.NoOpPasswordEncoder)3 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)3 Pbkdf2PasswordEncoder (org.springframework.security.crypto.password.Pbkdf2PasswordEncoder)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 Form (org.apache.wicket.markup.html.form.Form)2 StringResourceModel (org.apache.wicket.model.StringResourceModel)2 DefaultPasswordEncoder (org.apereo.cas.util.crypto.DefaultPasswordEncoder)2 Person (org.devgateway.toolkit.persistence.dao.Person)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SecureRandom (java.security.SecureRandom)1 HashMap (java.util.HashMap)1 UtilityClass (lombok.experimental.UtilityClass)1 lombok.val (lombok.val)1 PasswordEncoderProperties (org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties)1 GlibcCryptPasswordEncoder (org.apereo.cas.util.crypto.GlibcCryptPasswordEncoder)1 SpringSecurityPasswordEncoder (org.pac4j.core.credentials.password.SpringSecurityPasswordEncoder)1 TechnicalException (org.pac4j.core.exception.TechnicalException)1