Search in sources :

Example 46 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project spring-security by spring-projects.

the class DaoAuthenticationProviderTests method testGettersSetters.

@Test
public void testGettersSetters() {
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
    provider.setPasswordEncoder(new BCryptPasswordEncoder());
    assertThat(provider.getPasswordEncoder().getClass()).isEqualTo(BCryptPasswordEncoder.class);
    provider.setUserCache(new SpringCacheBasedUserCache(mock(Cache.class)));
    assertThat(provider.getUserCache().getClass()).isEqualTo(SpringCacheBasedUserCache.class);
    assertThat(provider.isForcePrincipalAsString()).isFalse();
    provider.setForcePrincipalAsString(true);
    assertThat(provider.isForcePrincipalAsString()).isTrue();
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) SpringCacheBasedUserCache(org.springframework.security.core.userdetails.cache.SpringCacheBasedUserCache) Test(org.junit.jupiter.api.Test)

Example 47 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project OsmAnd-tools by osmandapp.

the class WebSecurityConfiguration method passwordEncoder.

@Bean
public PasswordEncoder passwordEncoder() {
    DelegatingPasswordEncoder delegatingPasswordEncoder = (DelegatingPasswordEncoder) PasswordEncoderFactories.createDelegatingPasswordEncoder();
    delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(new BCryptPasswordEncoder());
    return delegatingPasswordEncoder;
}
Also used : DelegatingPasswordEncoder(org.springframework.security.crypto.password.DelegatingPasswordEncoder) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Bean(org.springframework.context.annotation.Bean)

Example 48 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project fw-cloud-framework by liuweijw.

the class UserController method modify.

/**
 * 修改用户密码
 */
@RequestMapping(value = "/modify", method = RequestMethod.POST)
@PrePermissions(value = Functional.UPD)
public R<Boolean> modify(HttpServletRequest request, @RequestBody UserForm userForm) {
    if (null == userForm.getUsername())
        return new R<Boolean>().failure("用户名不存在");
    if (null == userForm.getPassword())
        return new R<Boolean>().failure("请输入旧密码");
    if (null == userForm.getNewpassword())
        return new R<Boolean>().failure("请输入新密码");
    User user = this.userService.findUserByUsername(userForm.getUsername().trim(), false);
    if (null == user)
        return new R<Boolean>().failure("用户名不存在");
    if (!new BCryptPasswordEncoder().matches(userForm.getPassword().trim(), user.getPassword()))
        return new R<Boolean>().failure("旧密码输入错误!");
    user.setPassword(new BCryptPasswordEncoder().encode(userForm.getNewpassword().trim()));
    boolean r = this.userService.updateUser(user);
    return new R<Boolean>().data(r);
}
Also used : R(com.github.liuweijw.commons.base.R) User(com.github.liuweijw.business.admin.domain.User) AuthUser(com.github.liuweijw.system.api.model.AuthUser) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PrePermissions(com.github.liuweijw.business.commons.web.aop.PrePermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)48 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)18 Test (org.junit.jupiter.api.Test)7 KeystorePasswordHolder (won.owner.model.KeystorePasswordHolder)7 User (won.owner.model.User)7 SCryptPasswordEncoder (org.springframework.security.crypto.scrypt.SCryptPasswordEncoder)6 DelegatingPasswordEncoder (org.springframework.security.crypto.password.DelegatingPasswordEncoder)5 NoOpPasswordEncoder (org.springframework.security.crypto.password.NoOpPasswordEncoder)5 Pbkdf2PasswordEncoder (org.springframework.security.crypto.password.Pbkdf2PasswordEncoder)5 StandardPasswordEncoder (org.springframework.security.crypto.password.StandardPasswordEncoder)5 User (com.github.liuweijw.business.admin.domain.User)4 HashMap (java.util.HashMap)4 Transactional (org.springframework.transaction.annotation.Transactional)4 KeystoreHolder (won.owner.model.KeystoreHolder)4 ExpensiveSecureRandomString (won.protocol.util.ExpensiveSecureRandomString)4 PrePermissions (com.github.liuweijw.business.commons.web.aop.PrePermissions)3 Date (java.util.Date)3 lombok.val (lombok.val)3 Bean (org.springframework.context.annotation.Bean)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3