Example usage for org.apache.shiro.authc.credential Sha256CredentialsMatcher doCredentialsMatch

List of usage examples for org.apache.shiro.authc.credential Sha256CredentialsMatcher doCredentialsMatch

Introduction

In this page you can find the example usage for org.apache.shiro.authc.credential Sha256CredentialsMatcher doCredentialsMatch.

Prototype

@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) 

Source Link

Document

This implementation first hashes the token 's credentials, potentially using a salt if the info argument is a org.apache.shiro.authc.SaltedAuthenticationInfo SaltedAuthenticationInfo .

Usage

From source file:com.wira.ews.server.security.authentication.Authenticator.java

License:Apache License

@SuppressWarnings("deprecation")
private UserDto authenticate(String username, String password) {

    Sha256CredentialsMatcher matcher = new Sha256CredentialsMatcher();
    EwsUser user = userDao.findUserByUsername(username);

    if (password == null || user == null || user.getPassword() == null) {
        return null;
    }//from  w  ww.  j  av a  2 s .c  o m

    AuthenticationToken token = new UsernamePasswordToken(username, password);
    UsernamePasswordToken authcToken = new UsernamePasswordToken(username, password);
    boolean isMatch = false;
    try {
        log.debug("credentials to use: " + username + " : " + password);
        isMatch = matcher.doCredentialsMatch(token, realm.getAuthenticationInfo(authcToken));
    } catch (IncorrectCredentialsException e) {
        return null;
    }

    if (!isMatch) {
        return null;
    }

    return user.toDto();
}