Example usage for org.apache.shiro.subject SimplePrincipalCollection SimplePrincipalCollection

List of usage examples for org.apache.shiro.subject SimplePrincipalCollection SimplePrincipalCollection

Introduction

In this page you can find the example usage for org.apache.shiro.subject SimplePrincipalCollection SimplePrincipalCollection.

Prototype

public SimplePrincipalCollection(PrincipalCollection principals) 

Source Link

Usage

From source file:edu.wisc.nexus.auth.rut.RemoteUserAuthenticationInfo.java

License:Apache License

@Override
public void merge(AuthenticationInfo info) {
    if (info == null || info.getPrincipals() == null || info.getPrincipals().isEmpty()) {
        return;//ww  w .  java 2s. co  m
    }

    if (this.principals == null) {
        this.principals = info.getPrincipals();
    } else {
        if (!(this.principals instanceof MutablePrincipalCollection)) {
            this.principals = new SimplePrincipalCollection(this.principals);
        }
        ((MutablePrincipalCollection) this.principals).addAll(info.getPrincipals());
    }

    Object thisCredentials = getCredentials();
    Object otherCredentials = info.getCredentials();

    if (otherCredentials == null) {
        return;
    }

    if (thisCredentials == null) {
        this.credentials = otherCredentials;
        return;
    }

    if (!(thisCredentials instanceof Collection)) {
        Set<Object> newSet = new HashSet<Object>();
        newSet.add(thisCredentials);
        this.credentials = newSet;
    }

    // At this point, the credentials should be a collection
    Collection<Object> credentialCollection = (Collection<Object>) getCredentials();
    if (otherCredentials instanceof Collection) {
        credentialCollection.addAll((Collection<?>) otherCredentials);
    } else {
        credentialCollection.add(otherCredentials);
    }
}

From source file:org.apache.usergrid.security.shiro.UsergridAuthenticationInfo.java

License:Apache License

/**
 * Constructor that takes in an account's identifying principal(s) and its corresponding credentials that verify
 * the principals./*from  w ww. ja v  a 2 s.  co m*/
 *
 * @param principals  a Realm's account's identifying principal(s)
 * @param credentials the accounts corresponding principals that verify the principals.
 */
public UsergridAuthenticationInfo(PrincipalCollection principals, Object credentials) {
    this.principals = new SimplePrincipalCollection(principals);
    this.credentials = credentials;
}

From source file:org.apache.usergrid.security.shiro.UsergridAuthenticationInfo.java

License:Apache License

/**
 * Constructor that takes in an account's identifying principal(s), hashed credentials used to verify the
 * principals, and the salt used when hashing the credentials.
 *
 * @param principals        a Realm's account's identifying principal(s)
 * @param hashedCredentials the hashed credentials that verify the principals.
 * @param credentialsSalt   the salt used when hashing the hashedCredentials.
 * @see org.apache.shiro.authc.credential.HashedCredentialsMatcher HashedCredentialsMatcher
 * @since 1.1//w w  w . j a  va  2s.  c  om
 */
public UsergridAuthenticationInfo(PrincipalCollection principals, Object hashedCredentials,
        ByteSource credentialsSalt) {
    this.principals = new SimplePrincipalCollection(principals);
    this.credentials = hashedCredentials;
    this.credentialsSalt = credentialsSalt;
}

From source file:org.apache.usergrid.security.shiro.UsergridAuthenticationInfo.java

License:Apache License

/**
 * Takes the specified <code>info</code> argument and adds its principals and credentials into this instance.
 *
 * @param info the <code>AuthenticationInfo</code> to add into this instance.
 *///from  ww w.  ja  v a  2 s.  co m
@SuppressWarnings("unchecked")
public void merge(AuthenticationInfo info) {
    if (info == null || info.getPrincipals() == null || info.getPrincipals().isEmpty()) {
        return;
    }

    if (this.principals == null) {
        this.principals = info.getPrincipals();
    } else {
        if (!(this.principals instanceof MutablePrincipalCollection)) {
            this.principals = new SimplePrincipalCollection(this.principals);
        }
        ((MutablePrincipalCollection) this.principals).addAll(info.getPrincipals());
    }

    //only mess with a salt value if we don't have one yet.  It doesn't make sense
    //to merge salt values from different realms because a salt is used only within
    //the realm's credential matching process.  But if the current instance's salt
    //is null, then it can't hurt to pull in a non-null value if one exists.
    //
    //since 1.1:
    if (this.credentialsSalt == null && info instanceof SaltedAuthenticationInfo) {
        this.credentialsSalt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
    }

    Object thisCredentials = getCredentials();
    Object otherCredentials = info.getCredentials();

    if (otherCredentials == null) {
        return;
    }

    if (thisCredentials == null) {
        this.credentials = otherCredentials;
        return;
    }

    if (!(thisCredentials instanceof Collection)) {
        Set newSet = new HashSet();
        newSet.add(thisCredentials);
        setCredentials(newSet);
    }

    // At this point, the credentials should be a collection
    Collection credentialCollection = (Collection) getCredentials();
    if (otherCredentials instanceof Collection) {
        credentialCollection.addAll((Collection) otherCredentials);
    } else {
        credentialCollection.add(otherCredentials);
    }
}