Example usage for org.springframework.security.crypto.password StandardPasswordEncoder matches

List of usage examples for org.springframework.security.crypto.password StandardPasswordEncoder matches

Introduction

In this page you can find the example usage for org.springframework.security.crypto.password StandardPasswordEncoder matches.

Prototype

public boolean matches(CharSequence rawPassword, String encodedPassword) 

Source Link

Usage

From source file:ro.allevo.fintpws.security.CustomPasswordEncoder.java

@Override
public boolean isPasswordValid(String encryptedPassword, String rawPassword, Object salt) {
    StandardPasswordEncoder encoder = new StandardPasswordEncoder();
    return encoder.matches(rawPassword, encryptedPassword);
}

From source file:com.poscoict.license.security.UserService.java

public UserDetails loadUserByUsername(String userId) throws UsernameNotFoundException {
    logger.info("LoginCheck - ID: " + userId);
    boolean changePassword = false;

    StandardPasswordEncoder encoder = new StandardPasswordEncoder();

    UserInfo userInfo = getUserDao.get(userId.trim());
    logger.info("LoginCheck - ID: " + userInfo);
    String userPassword = userInfo.getUSER_PASSWORD();
    String userRole = userInfo.getUSER_TYPE();
    String userName = userInfo.getUSER_NAME();

    logger.info("LoginCheck - getUSER_PASSWORD: ");

    logger.info("LoginCheck - getUSER_PASSWORD: " + userInfo.getUSER_PASSWORD());
    logger.info("LoginCheck - getUSER_NAME: " + userInfo.getUSER_NAME());

    Collection<SimpleGrantedAuthority> roles = new ArrayList<SimpleGrantedAuthority>();
    roles.add(new SimpleGrantedAuthority(Consts.rolePrefix + userRole));

    if (encoder.matches(userId, userPassword))
        changePassword = true;/*from   www  . ja v a2  s  .  c  o m*/

    UserDetails user = new CustomUserDetails(userId, userPassword, userName, changePassword, roles);
    return user;
}

From source file:com.poscoict.license.service.BoardService.java

public String changePassword(String oriPass, String newPass, HttpSession session) throws Exception {
    StandardPasswordEncoder encoder = new StandardPasswordEncoder();
    PrivateKey privateKey = (PrivateKey) session.getAttribute("__rsaPrivateKey__");

    CustomUserDetails userDetails = (CustomUserDetails) session.getAttribute("userDetails");
    String userNo = userDetails.getUserNo();
    String userPassword = userDetails.getPassword();
    logger.info("changePassword: " + userNo);

    String result = "";

    if (encoder.matches(decryptRsa(privateKey, oriPass), userPassword)) {
        result = "success";

        String newPassword = encoder.encode(decryptRsa(privateKey, newPass));
        userDao.modifyPassword(userNo, newPassword);

        session.removeAttribute("__rsaPrivateKey__");
        session.removeAttribute("changePassword");
        userDetails.setPassword(newPassword);
        userDetails.setChangePassword(false);
        session.setAttribute("userDetails", userDetails);

        logger.info("changePassword-success " + userNo);
    } else {/*w w  w.j  a v  a  2  s. c o  m*/
        result = "fail";
        logger.info("changePassword-fail " + userNo);
    }

    return result;
}