Example usage for org.apache.shiro.authc SimpleAccount setCredentials

List of usage examples for org.apache.shiro.authc SimpleAccount setCredentials

Introduction

In this page you can find the example usage for org.apache.shiro.authc SimpleAccount setCredentials.

Prototype

public void setCredentials(Object credentials) 

Source Link

Document

Sets this Account's credentials that verify one or more of the Account's #getPrincipals() principals , such as a password or private key.

Usage

From source file:me.buom.shiro.realm.text.HmacIniRealm.java

License:Apache License

protected void beforeAssertCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    SimpleAccount account = (SimpleAccount) info;
    if (account != null) {
        // only set credentials salt on the first time!!!
        ByteSource credentialsSalt = (ByteSource) account.getCredentialsSalt();
        if (credentialsSalt == null) {
            Object credentials = account.getCredentials();
            credentialsSalt = ByteSource.Util.bytes(credentials);
            account.setCredentialsSalt(credentialsSalt);
            account.setCredentials(null);
        }/*from  w w w .ja v  a2 s  .  c  o  m*/

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

        if (log.isDebugEnabled()) {
            log.debug("oldCredentials: {}", oldCredentials);
            log.debug("curCredentials: {}", account.getCredentials());
            log.debug("credentialsSalt: {}", account.getCredentialsSalt().toHex());
        }
    }
}

From source file:org.i3xx.step.zero.security.impl.shiro.NaMyRealm.java

License:Apache License

protected SimpleAccount getAccount(String username, Object credentials) {

    //TODO: Remove the System.out
    System.out.println("get account user: " + username);
    //Account account = new SimpleAccount(username, "sha256EncodedPasswordFromDatabase", getName());

    if (username == null)
        throw new AccountException("Null usernames are not allowed by this realm.");
    //Account account=_store.getAccounts().get(username);
    //if (account == null) throw new UnknownAccountException("No account found for user [" + username + "]");
    String hash = _hash/*account.getPasswordHash()*/;
    ByteSource salt = new SimpleByteSource(_salt/*account.getSalt()*/);

    SimpleAccount account = new SimpleAccount(username, hash, salt, getName());

    //SimpleAccount account = new SimpleAccount(username, "sha256EncodedPasswordFromDatabase", getName());
    account.addRole("user");
    account.addRole("admin");
    account.addStringPermission("blogEntry:edit");
    account.addStringPermission("printer:print:laserjet");

    //The password or private key
    account.setCredentials(credentials);

    return account;
}