use of org.forgerock.openam.utils.JsonObject in project OpenAM by OpenRock.
the class SoapSTSPublishServiceRequestHandler method handleRead.
public Promise<ResourceResponse, ResourceException> handleRead(Context context, ReadRequest request) {
try {
if (EMPTY_STRING.equals(request.getResourcePath())) {
List<SoapSTSInstanceConfig> publishedInstances = publisher.getPublishedInstances();
JsonObject jsonObject = JsonValueBuilder.jsonValue();
for (SoapSTSInstanceConfig instanceConfig : publishedInstances) {
jsonObject.put(instanceConfig.getDeploymentSubPath(), mapStringToJson(instanceConfig.toJson().toString()));
}
/*
Note that the revision etag is not set, as this is not a resource which should really be cached.
If caching becomes necessary, a string composed of the hash codes of each of the SoapSTSInstanceConfig
instances could be used (or a hash of that string).
*/
return newResultPromise(newResourceResponse(PUBLISHED_INSTANCES, EMPTY_STRING, jsonObject.build()));
} else {
final String realm = getRealmFromResourceName(request.getResourcePath());
if (!realmValidator.isRealm(realm)) {
logger.warn("Read of soap STS instance state for instance " + request.getResourcePath() + " in realm " + realm + " rejected because realm does not exist");
return new NotFoundException("The specified realm does not exist.").asPromise();
}
SoapSTSInstanceConfig instanceConfig = publisher.getPublishedInstance(request.getResourcePath(), realm);
return newResultPromise(newResourceResponse(instanceConfig.getDeploymentSubPath(), getInstanceConfigEtag(instanceConfig), JsonValueBuilder.jsonValue().put(instanceConfig.getDeploymentSubPath(), mapStringToJson(instanceConfig.toJson().toString())).build()));
}
} catch (STSPublishException e) {
String message = "Exception caught obtaining soap sts instance corresponding to id: " + request.getResourcePath() + "; Exception: " + e;
logger.error(message, e);
return e.asPromise();
}
}
use of org.forgerock.openam.utils.JsonObject in project OpenAM by OpenRock.
the class AbstractRestAuthCallbackHandler method createJsonField.
/**
* Creates a JSON field for a callback.
*
* @param name The name of the field.
* @param values The array value of the field.
* @return The JSON field object.
*/
final JsonValue createJsonField(String name, Object[] values) {
JsonArray jsonArray = JsonValueBuilder.jsonValue().put("name", name == null ? "" : name).array("value");
if (values != null) {
for (Object value : values) {
jsonArray.add(value);
}
}
JsonObject jsonObject = jsonArray.build();
return jsonObject.build();
}
use of org.forgerock.openam.utils.JsonObject in project OpenAM by OpenRock.
the class RestAuthenticationHandler method createJsonCallbackResponse.
private JsonValue createJsonCallbackResponse(String authId, LoginConfiguration loginConfiguration, LoginProcess loginProcess, JsonValue jsonCallbacks) throws SignatureException, RestAuthException {
PagePropertiesCallback pagePropertiesCallback = loginProcess.getPagePropertiesCallback();
JsonObject jsonResponseObject = JsonValueBuilder.jsonValue();
if (authId == null) {
authId = authIdHelper.createAuthId(loginConfiguration, loginProcess.getAuthContext());
}
jsonResponseObject.put(AUTH_ID, authId);
AuditRequestContext.putProperty(AUTH_ID, authId);
if (pagePropertiesCallback != null) {
jsonResponseObject.put("template", pagePropertiesCallback.getTemplateName());
String moduleName = pagePropertiesCallback.getModuleName();
String state = pagePropertiesCallback.getPageState();
jsonResponseObject.put("stage", moduleName + state);
jsonResponseObject.put("header", pagePropertiesCallback.getHeader());
}
jsonResponseObject.put("callbacks", jsonCallbacks.getObject());
return jsonResponseObject.build();
}
use of org.forgerock.openam.utils.JsonObject in project OpenAM by OpenRock.
the class RestAuthenticationHandler method processAuthentication.
/**
* Using the given LoginProcess will process the authentication by getting the required callbacks and either
* completing and submitting them or sending the requirements back to the client as JSON. If the authentication
* process has completed it will then check the completion status and will either return an error or the SSO Token
* Id to the client.
*
* @param request The HttpServletRequest.
* @param response The HttpServletResponse.
* @param postBody The post body of the request.
* @param loginProcess The LoginProcess used to track the login.
* @param loginConfiguration The LoginConfiguration used to configure the login process.
* @return A ResponseBuilder which contains the contents of the response to return to the client.
* @throws AuthLoginException If there is a problem submitting the callbacks.
* @throws SignatureException If there is a problem creating the JWT to use in the response to the client.
*/
private JsonValue processAuthentication(HttpServletRequest request, HttpServletResponse response, JsonValue postBody, String authId, LoginProcess loginProcess, LoginConfiguration loginConfiguration) throws AuthLoginException, SignatureException, RestAuthException {
switch(loginProcess.getLoginStage()) {
case REQUIREMENTS_WAITING:
{
Callback[] callbacks = loginProcess.getCallbacks();
JsonValue jsonCallbacks;
try {
if (callbacks.length == 1 && callbacks[0] instanceof RedirectCallback && postBody != null) {
jsonCallbacks = null;
} else {
jsonCallbacks = handleCallbacks(request, response, postBody, callbacks);
}
} catch (RestAuthResponseException e) {
// Include the authId in the JSON response.
if (authId == null) {
authId = authIdHelper.createAuthId(loginConfiguration, loginProcess.getAuthContext());
}
e.getJsonResponse().put(AUTH_ID, authId);
AuditRequestContext.putProperty(AUTH_ID, authId);
throw e;
}
if (jsonCallbacks != null && jsonCallbacks.size() > 0) {
JsonValue jsonValue = createJsonCallbackResponse(authId, loginConfiguration, loginProcess, jsonCallbacks);
return jsonValue;
} else {
loginProcess = loginProcess.next(callbacks);
return processAuthentication(request, response, null, authId, loginProcess, loginConfiguration);
}
}
case COMPLETE:
{
loginProcess.cleanup();
if (loginProcess.isSuccessful()) {
// send token to client
JsonObject jsonResponseObject = JsonValueBuilder.jsonValue();
SSOToken ssoToken = loginProcess.getSSOToken();
if (ssoToken != null) {
String tokenId = ssoToken.getTokenID().toString();
jsonResponseObject.put(TOKEN_ID, tokenId);
AuditRequestContext.putProperty(TOKEN_ID, tokenId);
} else {
jsonResponseObject.put("message", "Authentication Successful");
}
String gotoUrl = urlValidator.getRedirectUrl(loginProcess.getOrgDN(), urlValidator.getValueFromJson(postBody, RedirectUrlValidator.GOTO), loginProcess.getSuccessURL());
jsonResponseObject.put("successUrl", gotoUrl);
return jsonResponseObject.build();
} else {
// send Error to client
AuthenticationContext authContext = loginProcess.getAuthContext();
String errorCode = authContext.getErrorCode();
String errorMessage = authContext.getErrorMessage();
throw new RestAuthErrorCodeException(errorCode, errorMessage);
}
}
}
// This should never happen
throw new RestAuthException(ResourceException.INTERNAL_ERROR, "Unknown Authentication State!");
}
use of org.forgerock.openam.utils.JsonObject in project OpenAM by OpenRock.
the class RecordReport method infoReport.
/**
* Create the infoReport
*
* @param record
* @return
*/
public JsonValue infoReport(Record record) {
JsonObject report = JsonValueBuilder.jsonValue();
report.put(GLOBAL_INFO_LABEL, globalInformationReport(record).asMap());
report.put(RECORD_LABEL, RecordProperties.toJson(record.getRecordProperties()).asMap());
report.put(JVM_LABEL, getJVMInformation().asMap());
report.put(SYSTEM_PROPERTIES_LABEL, getSystemProperties().asMap());
return report.build();
}
Aggregations