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() 

Source Link

Usage

From source file:at.pollux.thymeleaf.shiro.dialect.test.TestIniRealm.java

License:Apache License

@Override
protected void add(SimpleAccount account) {
    String username = (String) account.getPrincipals().getPrimaryPrincipal();

    // Let's add some additional principals for testing
    SimplePrincipalCollection principalCollection = new SimplePrincipalCollection();
    principalCollection.addAll(account.getPrincipals());
    principalCollection.add(counter.getAndIncrement(), "integerRealm");
    TestObjPrincipal objPrinc = new TestObjPrincipal(username.toUpperCase() + " " + username.toUpperCase());
    principalCollection.add(objPrinc, "objRealm");
    account.setPrincipals(principalCollection);

    super.add(account);
}

From source file:cn.itganhuo.app.web.shiro.ShiroDbRealm.java

License:Apache License

/**
 * ?/*www . j  a v a 2  s  .c o  m*/
 * <ol>
 * <li>???shiro?</li>
 * <li>?????????</li>
 * </ol>
 *
 * @param user_id ?
 * @version 0.0.2-SNAPSHOT
 * @author -?
 */
public void clearUserCache(String user_id) {
    log.debug("Began to clear the user cache.");

    SimplePrincipalCollection spc = new SimplePrincipalCollection();
    spc.add(user_id, getName());
    super.clearCachedAuthorizationInfo(spc);
}

From source file:com.freedomotic.persistence.UserConverter.java

License:Open Source License

/**
 *
 * @param reader//w  w w.  j  a va 2 s  .  c  o  m
 * @param uc
 * @return
 */
@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext uc) {
    SimplePrincipalCollection pc = new SimplePrincipalCollection();
    User user = null;
    reader.moveDown(); //principals
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        String realm = reader.getAttribute("realm");
        pc.add(reader.getValue(), realm);
        // reader.getAttribute("primary"); // ???
        reader.moveUp();
    }
    reader.moveUp(); //end principals
    reader.moveDown(); // credentials
    user = new User(pc, reader.getValue(), Freedomotic.INJECTOR.getInstance(Auth.class));
    reader.moveUp();
    reader.moveDown(); //roles
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        user.addRole(reader.getAttribute("name"));
        reader.moveUp();
    }
    reader.moveUp();
    reader.moveDown(); //properties
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        user.setProperty(reader.getAttribute("name"), reader.getAttribute("value"));
        reader.moveUp();
    }
    reader.moveUp();
    return user;
}

From source file:com.tensorwrench.shiro.realm.MongoUserPasswordRealmAuthorizationTest.java

License:Apache License

@Test
@MongoData("/principals.json")
public void getsUserRoles() {
    SimplePrincipalCollection principals = new SimplePrincipalCollection();
    principals.add("sample-principal-user", "fooRealm");
    AuthorizationInfo info = realm.doGetAuthorizationInfo(principals);
    assertEqualsNoOrder(info.getRoles().toArray(), new String[] { "role:user" });
}

From source file:com.tensorwrench.shiro.realm.MongoUserPasswordRealmAuthorizationTest.java

License:Apache License

@Test
@MongoData("/principals.json")
public void getsAdminRoles() {
    SimplePrincipalCollection principals = new SimplePrincipalCollection();
    principals.add("sample-principal-admin", "fooRealm");
    AuthorizationInfo info = realm.doGetAuthorizationInfo(principals);
    assertEqualsNoOrder(info.getRoles().toArray(), new String[] { "role:user", "role:admin" });
}

From source file:ddf.security.common.SecurityTokenHolderTest.java

License:Open Source License

@Test
public void testRetrieveSecurityTokens() {
    // given/*from w w  w . j  ava2  s .  c o m*/
    SecurityTokenHolder securityTokenHolder = new SecurityTokenHolder();
    PrincipalCollection principalCollection = new SimplePrincipalCollection();

    // when
    securityTokenHolder.setPrincipals(principalCollection);

    // then
    assertThat(securityTokenHolder.getPrincipals(), is(principalCollection));
}

From source file:ddf.security.common.SecurityTokenHolderTest.java

License:Open Source License

@Test
public void testSettingMultipleSecurityTokens() {
    // given// w w  w.j  av a2 s . c  om
    SecurityTokenHolder securityTokenHolder = new SecurityTokenHolder();
    PrincipalCollection securityTokenOne = new SimplePrincipalCollection();
    PrincipalCollection securityTokenTwo = new SimplePrincipalCollection();

    // when
    securityTokenHolder.setPrincipals(securityTokenOne);
    securityTokenHolder.setPrincipals(securityTokenTwo);

    // then
    assertThat(securityTokenHolder.getPrincipals(), is(securityTokenTwo));
}

From source file:ddf.security.common.SecurityTokenHolderTest.java

License:Open Source License

@Test
public void testRemoveSecurityToken() {
    // given//from  w ww  .java  2  s.c o  m
    SecurityTokenHolder securityTokenHolder = new SecurityTokenHolder();
    PrincipalCollection securityToken = new SimplePrincipalCollection();
    securityTokenHolder.setPrincipals(securityToken);

    // when
    securityTokenHolder.remove();

    // then
    assertNull(securityTokenHolder.getPrincipals());
}

From source file:ddf.security.impl.SubjectImplTest.java

License:Open Source License

private PrincipalCollection createTestCollection() {
    SimplePrincipalCollection collection = new SimplePrincipalCollection();
    collection.add(TEST_SUBJECT_NAME, TEST_REALM_NAME);
    return collection;
}

From source file:ddf.security.realm.sts.AbstractStsRealm.java

License:Open Source License

/**
 * Perform authentication based on the supplied token.
 *///from   w ww .  j a v  a2s. co  m
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) {
    String method = "doGetAuthenticationInfo(    AuthenticationToken token )";
    LOGGER.entry(method);

    Object credential;

    if (token instanceof SAMLAuthenticationToken) {
        credential = token.getCredentials();
    } else if (token instanceof BaseAuthenticationToken) {
        credential = ((BaseAuthenticationToken) token).getCredentialsAsXMLString();
    } else {
        credential = token.getCredentials().toString();
    }
    if (credential == null) {
        String msg = "Unable to authenticate credential.  A NULL credential was provided in the supplied authentication token. This may be due to an error with the SSO server that created the token.";
        LOGGER.error(msg);
        throw new AuthenticationException(msg);
    } else {
        //removed the credentials from the log message for now, I don't think we should be dumping user/pass into log
        LOGGER.debug("Received credentials.");
    }

    if (!settingsConfigured) {
        configureStsClient();
        settingsConfigured = true;
    } else {
        setClaimsOnStsClient(createClaimsElement());
    }

    SecurityToken securityToken;
    if (token instanceof SAMLAuthenticationToken && credential instanceof SecurityToken) {
        securityToken = renewSecurityToken((SecurityToken) credential);
    } else {
        securityToken = requestSecurityToken(credential);
    }

    LOGGER.debug("Creating token authentication information with SAML.");
    SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();
    SimplePrincipalCollection principals = new SimplePrincipalCollection();
    SecurityAssertion assertion = new SecurityAssertionImpl(securityToken);
    principals.add(assertion.getPrincipal(), NAME);
    principals.add(assertion, NAME);
    simpleAuthenticationInfo.setPrincipals(principals);
    simpleAuthenticationInfo.setCredentials(credential);

    LOGGER.exit(method);
    return simpleAuthenticationInfo;
}