use of org.glassfish.admin.restconnector.RestConfig in project Payara by payara.
the class BaseProvider method isDebug.
/**
* check for the __debug request header
*/
protected boolean isDebug() {
RestConfig rg = ResourceUtil.getRestConfig(habitat);
if ((rg != null) && (rg.getDebug().equalsIgnoreCase("true"))) {
return true;
}
if (requestHeaders == null) {
return true;
}
List header = requestHeaders.get().getRequestHeader(HEADER_DEBUG);
return (header != null) && ("true".equals(header.get(0)));
}
use of org.glassfish.admin.restconnector.RestConfig in project Payara by payara.
the class GetRestConfig method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
RestConfig restConfig = config.getExtensionByType(RestConfig.class);
if (restConfig == null) {
report.setMessage("debug=false, indentLevel=-1, showHiddenCommands=false, wadlGeneration=false, logOutput=false, logInput=false, showDeprecatedItems=false, sessionTokenTimeout=30");
report.getTopMessagePart().addProperty("debug", "false");
report.getTopMessagePart().addProperty("indentLevel", "-1");
report.getTopMessagePart().addProperty("showHiddenCommands", "false");
report.getTopMessagePart().addProperty("showDeprecatedItems", "false");
report.getTopMessagePart().addProperty("wadlGeneration", "" + "false");
report.getTopMessagePart().addProperty("logOutput", "" + "false");
report.getTopMessagePart().addProperty("logInput", "" + "false");
report.getTopMessagePart().addProperty("sessionTokenTimeout", "30");
} else {
report.setMessage("debug=" + restConfig.getDebug() + ", indentLevel=" + restConfig.getIndentLevel() + ", showHiddenCommands=" + restConfig.getShowHiddenCommands() + ", wadlGeneration=" + restConfig.getWadlGeneration() + ", logOutput=" + restConfig.getLogOutput() + ", logInput=" + restConfig.getLogInput() + ", sessionTokenTimeout=" + restConfig.getSessionTokenTimeout());
report.getTopMessagePart().addProperty("debug", restConfig.getDebug());
report.getTopMessagePart().addProperty("indentLevel", restConfig.getIndentLevel());
report.getTopMessagePart().addProperty("showHiddenCommands", restConfig.getShowHiddenCommands());
report.getTopMessagePart().addProperty("showDeprecatedItems", restConfig.getShowDeprecatedItems());
report.getTopMessagePart().addProperty("wadlGeneration", restConfig.getWadlGeneration());
report.getTopMessagePart().addProperty("logOutput", restConfig.getLogOutput());
report.getTopMessagePart().addProperty("logInput", restConfig.getLogInput());
report.getTopMessagePart().addProperty("sessionTokenTimeout", "" + restConfig.getSessionTokenTimeout());
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return;
}
use of org.glassfish.admin.restconnector.RestConfig 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.restconnector.RestConfig in project Payara by payara.
the class SetRestConfig method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
RestConfig restConfig = config.getExtensionByType(RestConfig.class);
/**
* The schedules does not exist in this Config. We will need to
* add it plus the default schedules.
*/
if (restConfig == null) {
try {
ConfigSupport.apply(new SingleConfigCode<Config>() {
@Override
public Object run(Config parent) throws TransactionFailure {
RestConfig child = parent.createChild(RestConfig.class);
parent.getContainers().add(child);
return child;
}
}, config);
} catch (TransactionFailure e) {
report.setMessage("TransactionFailure failure while creating the REST config");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
restConfig = config.getExtensionByType(RestConfig.class);
if (restConfig == null) {
report.setMessage("Rest Config is NULL...");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
try {
ConfigSupport.apply(new SingleConfigCode<RestConfig>() {
@Override
public Object run(RestConfig param) throws TransactionFailure, PropertyVetoException {
if (debug != null) {
param.setDebug(debug);
}
if (indentLevel != -100) {
param.setIndentLevel("" + indentLevel);
}
if (showHiddenCommands != null) {
param.setShowHiddenCommands(showHiddenCommands);
}
if (showDeprecatedItems != null) {
param.setShowDeprecatedItems(showDeprecatedItems);
}
if (wadlGeneration != null) {
param.setWadlGeneration(wadlGeneration);
}
if (logOutput != null) {
param.setLogOutput(logOutput);
}
if (logInput != null) {
param.setLogInput(logInput);
}
if (sessionTokenTimeout != null) {
param.setSessionTokenTimeout(sessionTokenTimeout);
}
return param;
}
}, restConfig);
} catch (TransactionFailure e) {
report.setMessage("TransactionFailure while changing the REST config");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
return;
}
Aggregations