Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ-1401565] Validate if the server has already started before call R…
Browse files Browse the repository at this point in the history
…EST handlers.
  • Loading branch information
rubenvp8510 authored and spinder committed Sep 6, 2017
1 parent 50669ee commit 81f532b
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.StreamingOutput;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.auth.Subject;
import org.rhq.enterprise.server.auth.SessionManager;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.core.StartupLocal;

/**
* Interceptor to set the 'caller' variable of the AbstractRestBean from the princpial
Expand All @@ -51,12 +55,17 @@
*/
public class SetCallerInterceptor {

protected Log log = LogFactory.getLog(getClass().getName());

@Resource
private EJBContext ejbContext;

@EJB
private SubjectManagerLocal subjectManager;

@EJB
private StartupLocal startupBean;

private SessionManager sessionManager = SessionManager.getInstance();

/**
Expand All @@ -72,6 +81,14 @@ public Object setCaller(InvocationContext ctx) throws Exception {

Subject caller=null;
java.security.Principal p = ejbContext.getCallerPrincipal();
if (!startupBean.isInitialized()) {
String notInitMessage = "Tried to call REST endpoint but the server has not finished to startup";
log.warn(notInitMessage);
Response.ResponseBuilder builder;
builder = Response.status(Response.Status.SERVICE_UNAVAILABLE).entity(notInitMessage);
return builder.build();
}

if (p!=null) {
caller = subjectManager.getSubjectByName(p.getName());
}
Expand Down

0 comments on commit 81f532b

Please sign in to comment.