Search in sources :

Example 1 with ShiroPrincipal

use of org.graylog2.shared.security.ShiroPrincipal in project graylog2-server by Graylog2.

the class RestResource method getSubject.

protected Subject getSubject() {
    if (securityContext == null) {
        LOG.error("Cannot retrieve current subject, SecurityContext isn't set.");
        return null;
    }
    final Principal p = securityContext.getUserPrincipal();
    if (!(p instanceof ShiroPrincipal)) {
        final String msg = "Unknown SecurityContext class " + securityContext + ", cannot continue.";
        LOG.error(msg);
        throw new IllegalStateException(msg);
    }
    final ShiroPrincipal principal = (ShiroPrincipal) p;
    return principal.getSubject();
}
Also used : ShiroPrincipal(org.graylog2.shared.security.ShiroPrincipal) ShiroPrincipal(org.graylog2.shared.security.ShiroPrincipal) Principal(java.security.Principal)

Example 2 with ShiroPrincipal

use of org.graylog2.shared.security.ShiroPrincipal in project graylog2-server by Graylog2.

the class RestTools method getUserNameFromRequest.

@Nullable
public static String getUserNameFromRequest(ContainerRequestContext requestContext) {
    final SecurityContext securityContext = requestContext.getSecurityContext();
    if (!(securityContext instanceof ShiroSecurityContext)) {
        return null;
    }
    final ShiroSecurityContext shiroSecurityContext = (ShiroSecurityContext) securityContext;
    final Principal userPrincipal = shiroSecurityContext.getUserPrincipal();
    if (!(userPrincipal instanceof ShiroPrincipal)) {
        return null;
    }
    final ShiroPrincipal shiroPrincipal = (ShiroPrincipal) userPrincipal;
    return shiroPrincipal.getName();
}
Also used : SecurityContext(javax.ws.rs.core.SecurityContext) ShiroSecurityContext(org.graylog2.shared.security.ShiroSecurityContext) ShiroPrincipal(org.graylog2.shared.security.ShiroPrincipal) ShiroPrincipal(org.graylog2.shared.security.ShiroPrincipal) Principal(java.security.Principal) ShiroSecurityContext(org.graylog2.shared.security.ShiroSecurityContext) Nullable(javax.annotation.Nullable)

Aggregations

Principal (java.security.Principal)2 ShiroPrincipal (org.graylog2.shared.security.ShiroPrincipal)2 Nullable (javax.annotation.Nullable)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 ShiroSecurityContext (org.graylog2.shared.security.ShiroSecurityContext)1