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