Search in sources :

Example 31 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project molgenis by molgenis.

the class MolgenisPasswordEncoderTest method encode.

@Test
public void encode() {
    String password = "password";
    String encodedPassword = "encoded-password";
    BCryptPasswordEncoder bCryptPasswordEncoder = mock(BCryptPasswordEncoder.class);
    when(bCryptPasswordEncoder.encode(password)).thenReturn(encodedPassword);
    assertEquals(new MolgenisPasswordEncoder(bCryptPasswordEncoder).encode(password), encodedPassword);
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Test(org.testng.annotations.Test)

Example 32 with BCryptPasswordEncoder

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

the class UserController method modifyUser.

/**
 * 修改用户密码
 */
@RequestMapping(value = "/modifyUser", method = RequestMethod.POST)
@PrePermissions(value = Functional.UPD)
public R<Boolean> modifyUser(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.core.utils.R) User(com.github.liuweijw.business.admin.domain.User) AuthUser(com.github.liuweijw.core.beans.system.AuthUser) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PrePermissions(com.github.liuweijw.business.commons.web.aop.PrePermissions) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project SoftUni by kostovhg.

the class UserController method registerProcess.

@PostMapping("/register")
public String registerProcess(UserBindingModel userBindingModel) {
    if (!userBindingModel.getPassword().equals(userBindingModel.getConfirmPassword())) {
        return "redirect:/register";
    }
    BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    User user = new User(userBindingModel.getEmail(), userBindingModel.getFullName(), bCryptPasswordEncoder.encode(userBindingModel.getPassword()));
    Role userRole = this.roleRepository.findByName("ROLE_USER");
    user.addRole(userRole);
    this.userRepository.saveAndFlush(user);
    return "redirect:/login";
}
Also used : Role(softuni.todolist.entity.Role) User(softuni.todolist.entity.User) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 34 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project mots by motech-implementations.

the class SecurityConfiguration method authenticator.

/**
 * Initializes AuthenticationProvider bean with userDetailsService and BCryptPasswordEncoder.
 *
 * @return initialized AuthenticationProvider
 */
@Bean
public AuthenticationProvider authenticator() {
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
    provider.setUserDetailsService(userDetailsService);
    provider.setPasswordEncoder(new BCryptPasswordEncoder());
    return provider;
}
Also used : DaoAuthenticationProvider(org.springframework.security.authentication.dao.DaoAuthenticationProvider) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Bean(org.springframework.context.annotation.Bean)

Example 35 with BCryptPasswordEncoder

use of org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder in project mots by motech-implementations.

the class UserService method saveUser.

/**
 * Save User with new encoded password (if it's not blank).
 *
 * @param user User to be created.
 * @return saved User
 */
@PreAuthorize(RoleNames.HAS_MANAGE_USERS_OR_MANAGE_INCHARGE_USERS_ROLE)
public User saveUser(User user, boolean encodeNewPassword) {
    if (encodeNewPassword) {
        String newPasswordEncoded = new BCryptPasswordEncoder().encode(user.getPassword());
        user.setPassword(newPasswordEncoded);
    }
    return validateAndSave(user);
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

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