Example usage for org.apache.shiro.authc SimpleAuthenticationInfo getCredentials

List of usage examples for org.apache.shiro.authc SimpleAuthenticationInfo getCredentials

Introduction

In this page you can find the example usage for org.apache.shiro.authc SimpleAuthenticationInfo getCredentials.

Prototype

public Object getCredentials() 

Source Link

Usage

From source file:me.buom.shiro.realm.jdbc.HmacJdbcRealm.java

License:Apache License

protected void beforeAssertCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    SimpleAuthenticationInfo authInfo = (SimpleAuthenticationInfo) info;

    Object oldCredentials = authInfo.getCredentials();
    Object stringToSign = hmacBuilder.buildStringToSign((HmacToken) token);
    authInfo.setCredentials(stringToSign);

    if (log.isDebugEnabled()) {
        log.debug("oldCredentials: {}", oldCredentials);
        log.debug("credentials: {}", authInfo.getCredentials());
        log.debug("credentialsSalt: {}", authInfo.getCredentialsSalt().toHex());
    }/*w w w .j ava2  s .c  o m*/
}

From source file:org.eclipse.kapua.service.authentication.shiro.credential.BCryptCredentialsMatcher.java

License:Open Source License

@Override
public boolean doCredentialsMatch(AuthenticationToken authenticationToken,
        AuthenticationInfo authenticationInfo) {
    ////from   w  ww.j  a  v  a  2  s .com
    // Token data
    UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
    String tokenUsername = token.getUsername();
    String tokenPassword = new String(token.getPassword());

    //
    // Info data
    SimpleAuthenticationInfo info = (SimpleAuthenticationInfo) authenticationInfo;
    String infoUsername = (String) info.getPrincipals().getPrimaryPrincipal();
    String infoPassword = (String) info.getCredentials();

    //
    // Match token with info
    boolean credentialMatch = false;
    if (tokenUsername.equals(infoUsername)) {
        if (BCrypt.checkpw(tokenPassword, infoPassword)) {
            credentialMatch = true;

            // FIXME: if true cache token password for authentication performance improvement
        }
    }

    return credentialMatch;
}

From source file:zi.helper.ZShiroJdbcRealm.java

License:Apache License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    //identify account to log to
    UsernamePasswordToken userPassToken = (UsernamePasswordToken) token;
    String username = userPassToken.getUsername();

    if (username == null) {
        log.debug("Username is null.");
        return null;
    }//ww w .  j av a  2  s.  c  om

    // read password hash and salt from db
    User UserDB = MUser.ReadByName(username);

    if (UserDB.get("password") == null) {
        log.debug("No account found for user [" + username + "]");
        return null;
    }
    log.info(userPassToken.getCredentials() + " :::=> token" + getName());
    // return salted credentials
    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(UserDB.get("name"), UserDB.get("password"),
            new SimpleByteSource("OTransmedia.2.0"), getName());

    log.info(info.getCredentials() + " ::: => salt");
    return info;
}