Search in sources :

Example 86 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project graylog2-server by Graylog2.

the class UserContext method runAs.

/**
 * Build a temporary Shiro Subject and run the callable within that context
 * @param username  The username of the subject
 * @param runnable  The runnable to be executed
 */
public static void runAs(String username, Runnable runnable) {
    final Subject subject = new Subject.Builder().principals(new SimplePrincipalCollection(username, "runAs-context")).authenticated(true).sessionCreationEnabled(false).buildSubject();
    subject.execute(runnable);
}
Also used : SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Subject(org.apache.shiro.subject.Subject)

Example 87 with SimplePrincipalCollection

use of org.apache.shiro.subject.SimplePrincipalCollection in project graylog2-server by Graylog2.

the class RootAccountRealm method doGetAuthenticationInfo.

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    final AuthenticationInfo authenticationInfo = super.doGetAuthenticationInfo(token);
    // After successful authentication, exchange the principals to unique admin userId
    if (authenticationInfo instanceof SimpleAccount) {
        SimpleAccount account = (SimpleAccount) authenticationInfo;
        account.setPrincipals(new SimplePrincipalCollection(UserImpl.LocalAdminUser.LOCAL_ADMIN_ID, NAME));
        return account;
    }
    return null;
}
Also used : SimpleAccount(org.apache.shiro.authc.SimpleAccount) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) AuthenticationInfo(org.apache.shiro.authc.AuthenticationInfo)

Aggregations

SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)87 Test (org.junit.Test)38 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)34 SimpleAuthenticationInfo (org.apache.shiro.authc.SimpleAuthenticationInfo)12 Element (org.w3c.dom.Element)12 SecurityAssertion (ddf.security.assertion.SecurityAssertion)11 AuthorizationInfo (org.apache.shiro.authz.AuthorizationInfo)11 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)11 SecurityAssertionSaml (ddf.security.assertion.saml.impl.SecurityAssertionSaml)10 Principal (java.security.Principal)10 SAMLAuthenticationToken (org.codice.ddf.security.handler.SAMLAuthenticationToken)10 ArrayList (java.util.ArrayList)9 Subject (org.apache.shiro.subject.Subject)9 AuthenticationInfo (org.apache.shiro.authc.AuthenticationInfo)8 Subject (ddf.security.Subject)7 AuthenticationException (org.apache.shiro.authc.AuthenticationException)7 Realm (org.apache.shiro.realm.Realm)7 SimpleSession (org.apache.shiro.session.mgt.SimpleSession)7 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)6 Assertion (org.opensaml.saml.saml2.core.Assertion)6