Search in sources :

Example 21 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter 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;
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) OptionsResult(org.glassfish.admin.rest.results.OptionsResult)

Example 22 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter 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();
}
Also used : Response(javax.ws.rs.core.Response) RestConfig(org.glassfish.admin.restconnector.RestConfig) ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) Request(org.glassfish.grizzly.http.server.Request) Subject(javax.security.auth.Subject) RemoteAdminAccessException(org.glassfish.internal.api.RemoteAdminAccessException) RemoteAdminAccessException(org.glassfish.internal.api.RemoteAdminAccessException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 23 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class StatusGenerator method listOfCommands.

public void listOfCommands() {
    CommandRunner cr = serviceLocator.getService(CommandRunner.class);
    RestActionReporter ar = new RestActionReporter();
    ParameterMap parameters = new ParameterMap();
    cr.getCommandInvocation("list-commands", ar, getSubject()).parameters(parameters).execute();
    List<ActionReport.MessagePart> children = ar.getTopMessagePart().getChildren();
    for (ActionReport.MessagePart part : children) {
        allCommands.add(part.getMessage());
    }
    ar = new RestActionReporter();
    parameters = new ParameterMap();
    parameters.add("DEFAULT", "_");
    cr.getCommandInvocation("list-commands", ar, getSubject()).parameters(parameters).execute();
    children = ar.getTopMessagePart().getChildren();
    for (ActionReport.MessagePart part : children) {
        allCommands.add(part.getMessage());
    }
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 24 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter 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();
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReport(org.glassfish.api.ActionReport)

Example 25 with RestActionReporter

use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.

the class TemplateExecCommand method optionsLegacyFormat.

@OPTIONS
@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ActionReportResult optionsLegacyFormat() {
    RestActionReporter ar = new RestActionReporter();
    ar.setExtraProperties(new Properties());
    ar.setActionDescription(commandDisplayName);
    OptionsResult optionsResult = new OptionsResult(resourceName);
    Map<String, MethodMetaData> mmd = new HashMap<String, MethodMetaData>();
    MethodMetaData methodMetaData = ResourceUtil.getMethodMetaData(commandName, getCommandParams(), locatorBridge.getRemoteLocator());
    optionsResult.putMethodMetaData(commandMethod, methodMetaData);
    mmd.put(commandMethod, methodMetaData);
    ResourceUtil.addMethodMetaData(ar, mmd);
    ActionReportResult ret = new ActionReportResult(ar, null, optionsResult);
    ret.setCommandDisplayName(commandDisplayName);
    return ret;
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) HashMap(java.util.HashMap) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Properties(java.util.Properties) OptionsResult(org.glassfish.admin.rest.results.OptionsResult) Produces(javax.ws.rs.Produces) OPTIONS(javax.ws.rs.OPTIONS)

Aggregations

RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)44 ActionReportResult (org.glassfish.admin.rest.results.ActionReportResult)23 OptionsResult (org.glassfish.admin.rest.results.OptionsResult)13 ActionReport (org.glassfish.api.ActionReport)12 Produces (javax.ws.rs.Produces)9 WebApplicationException (javax.ws.rs.WebApplicationException)8 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 GET (javax.ws.rs.GET)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Consumes (javax.ws.rs.Consumes)5 MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)5 MessagePart (org.glassfish.api.ActionReport.MessagePart)5 ParameterMap (org.glassfish.api.admin.ParameterMap)5 CommandRunner (org.glassfish.api.admin.CommandRunner)4 Test (org.testng.annotations.Test)4 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)3 List (java.util.List)3 MultiException (org.glassfish.hk2.api.MultiException)3