Example usage for org.apache.shiro.crypto.hash HashRequest.Builder HashRequest.Builder

List of usage examples for org.apache.shiro.crypto.hash HashRequest.Builder HashRequest.Builder

Introduction

In this page you can find the example usage for org.apache.shiro.crypto.hash HashRequest.Builder HashRequest.Builder.

Prototype

HashRequest.Builder

Source Link

Usage

From source file:org.apache.hadoop.gateway.shirorealm.KnoxPamRealm.java

License:Apache License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    UnixUser user = null;//from   w  ww  .j a v a 2  s.co  m
    try {
        user = (new PAM(this.getService())).authenticate(upToken.getUsername(),
                new String(upToken.getPassword()));
    } catch (PAMException e) {
        handleAuthFailure(token, e.getMessage(), e);
    }
    HashRequest.Builder builder = new HashRequest.Builder();
    Hash credentialsHash = hashService
            .computeHash(builder.setSource(token.getCredentials()).setAlgorithmName(HASHING_ALGORITHM).build());
    /* Coverity Scan CID 1361684 */
    if (credentialsHash == null) {
        handleAuthFailure(token, "Failed to compute hash", null);
    }
    return new SimpleAuthenticationInfo(new UnixUserPrincipal(user), credentialsHash.toHex(),
            credentialsHash.getSalt(), getName());
}