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);
}
}
};
}
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));
}
}
}
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);
}
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;
}
Aggregations