use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class ResourceUtil method getActionReportResult.
public static ActionReportResult getActionReportResult(RestActionReporter ar, String message, HttpHeaders requestHeaders, UriInfo uriInfo) {
if (isBrowser(requestHeaders)) {
message = getHtml(message, uriInfo, false);
}
ActionReport.ExitCode status = ar.getActionExitCode();
ActionReportResult result = new ActionReportResult(ar);
if (status != ActionReport.ExitCode.SUCCESS && status != ActionReport.ExitCode.WARNING) {
result.setErrorMessage(message);
result.setIsError(true);
}
ar.setActionExitCode(status);
ar.setMessage(message);
return result;
}
use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class CollectionLeafResource method buildActionReportResult.
protected ActionReportResult buildActionReportResult() {
RestActionReporter ar = new RestActionReporter();
final String typeKey = upperCaseFirstLetter((decode(getName())));
ar.setActionDescription(typeKey);
ar.getExtraProperties().put("leafList", getEntity());
OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
Map<String, MethodMetaData> mmd = getMethodMetaData();
optionsResult.putMethodMetaData("GET", mmd.get("GET"));
optionsResult.putMethodMetaData("POST", mmd.get("POST"));
ResourceUtil.addMethodMetaData(ar, mmd);
return new ActionReportResult(ar, optionsResult);
}
use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class LeafResource method buildActionReportResult.
protected ActionReportResult buildActionReportResult() {
RestActionReporter ar = new RestActionReporter();
final String typeKey = (decode(getName()));
ar.setActionDescription(typeKey);
ar.getExtraProperties().put("entityLeaf", getEntity());
OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
Map<String, MethodMetaData> mmd = getMethodMetaData();
optionsResult.putMethodMetaData("GET", mmd.get("GET"));
optionsResult.putMethodMetaData("POST", mmd.get("POST"));
ResourceUtil.addMethodMetaData(ar, mmd);
ActionReportResult r = new ActionReportResult(ar, optionsResult);
r.setLeafContent(entity);
return r;
}
use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class SessionsResource method create.
/**
* Get a new session with GlassFish Rest service
* If a request lands here when authentication has been turned on => it has been authenticated.
* @return a new session with GlassFish Rest service
*/
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.APPLICATION_FORM_URLENCODED })
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response create(HashMap<String, String> data) {
if (data == null) {
data = new HashMap<String, String>();
}
final RestConfig restConfig = ResourceUtil.getRestConfig(locatorBridge.getRemoteLocator());
Response.ResponseBuilder responseBuilder = Response.status(UNAUTHORIZED);
RestActionReporter ar = new RestActionReporter();
Request grizzlyRequest = request.get();
// If the call flow reached here, the request has been authenticated by logic in RestAdapater
// probably with an admin username and password. The remoteHostName value
// in the data object is the actual remote host of the end-user who is
// using the console (or, conceivably, some other client). We need to
// authenticate here once again with that supplied remoteHostName to
// make sure we enforce remote access rules correctly.
String hostName = data.get("remoteHostName");
boolean isAuthorized = false;
boolean responseErrorStatusSet = false;
Subject subject = null;
try {
// subject = ResourceUtil.authenticateViaAdminRealm(Globals.getDefaultHabitat(), grizzlyRequest, hostName);
subject = ResourceUtil.authenticateViaAdminRealm(locatorBridge.getRemoteLocator(), grizzlyRequest, hostName);
isAuthorized = ResourceUtil.isAuthorized(locatorBridge.getRemoteLocator(), subject, "domain/rest-sessions/rest-session", "create");
} catch (RemoteAdminAccessException e) {
responseBuilder.status(FORBIDDEN);
responseErrorStatusSet = true;
} catch (Exception e) {
ar.setMessage("Error while authenticating " + e);
}
if (isAuthorized) {
responseBuilder.status(OK);
// Check to see if the username has been set (anonymous user case)
String username = (String) grizzlyRequest.getAttribute("restUser");
if (username != null) {
ar.getExtraProperties().put("username", username);
}
ar.getExtraProperties().put("token", sessionManager.createSession(grizzlyRequest.getRemoteAddr(), subject, chooseTimeout(restConfig)));
} else {
if (!responseErrorStatusSet) {
responseBuilder.status(UNAUTHORIZED);
}
}
return responseBuilder.entity(new ActionReportResult(ar)).build();
}
use of org.glassfish.admin.rest.results.ActionReportResult in project Payara by payara.
the class TemplateExecCommand method executeCommandLegacyFormat.
protected Response executeCommandLegacyFormat(ParameterMap data) {
RestActionReporter actionReport = ResourceUtil.runCommand(commandName, data, getSubject());
final ActionReport.ExitCode exitCode = actionReport.getActionExitCode();
final int status = (exitCode == ActionReport.ExitCode.FAILURE) ? HttpURLConnection.HTTP_INTERNAL_ERROR : HttpURLConnection.HTTP_OK;
ActionReportResult option = (ActionReportResult) optionsLegacyFormat();
ActionReportResult results = new ActionReportResult(commandName, actionReport, option.getMetaData());
results.getActionReport().getExtraProperties().putAll(option.getActionReport().getExtraProperties());
results.setCommandDisplayName(commandDisplayName);
if (exitCode == ActionReport.ExitCode.FAILURE) {
results.setErrorMessage(actionReport.getCombinedMessage());
}
return Response.status(status).entity(results).build();
}
Aggregations