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);
}
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;
}
Aggregations