use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class IdentityResourceV1 method createInstance.
/**
* Creates an a resource using a privileged token
* @param admin Token that has administrative privileges
* @param details resource details that needs to be created
* @return A successful promise if the create was successful
*/
private Promise<ActionResponse, ResourceException> createInstance(SSOToken admin, final JsonValue details, final String realm) {
JsonValue jVal = details;
IdentityDetails identity = jsonValueToIdentityDetails(objectType, jVal, realm);
final String resourceId = identity.getName();
return attemptResourceCreation(realm, admin, identity, resourceId).thenAsync(new AsyncFunction<IdentityDetails, ActionResponse, ResourceException>() {
@Override
public Promise<ActionResponse, ResourceException> apply(IdentityDetails dtls) {
if (dtls != null) {
debug.message("IdentityResource.createInstance :: Anonymous CREATE in realm={} for resourceId={}", realm, resourceId);
return newResultPromise(newActionResponse(identityDetailsToJsonValue(dtls)));
} else {
return new NotFoundException(resourceId + " not found").asPromise();
}
}
});
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class IdentityResourceV2 method createInstance.
/**
* Creates an a resource using a privileged token
* @param admin Token that has administrative privileges
* @param details resource details that needs to be created
* @return A successful promise containing the identity details if the create was successful
*/
private Promise<ActionResponse, ResourceException> createInstance(SSOToken admin, JsonValue details, final String realm) {
JsonValue jVal = details;
IdentityDetails identity = jsonValueToIdentityDetails(objectType, jVal, realm);
final String resourceId = identity.getName();
return attemptResourceCreation(realm, admin, identity, resourceId).thenAsync(new AsyncFunction<IdentityDetails, ActionResponse, ResourceException>() {
@Override
public Promise<ActionResponse, ResourceException> apply(IdentityDetails dtls) {
if (dtls != null) {
debug.message("IdentityResource.createInstance :: Anonymous CREATE in realm={} " + "for resourceId={}", realm, resourceId);
return newResultPromise(newActionResponse(identityDetailsToJsonValue(dtls)));
} else {
return new NotFoundException(resourceId + " not found").asPromise();
}
}
});
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ServerInfoResource method getAllServerInfo.
/**
* Retrieves all server info set on the server.
*
* @param context
* Current Server Context.
* @param realm
* realm in whose security context we use.
*/
private Promise<ResourceResponse, ResourceException> getAllServerInfo(Context context, String realm) {
JsonValue result = new JsonValue(new LinkedHashMap<String, Object>(1));
Set<String> cookieDomains;
ResourceResponse resource;
//added for the XUI to be able to understand its locale to request the appropriate translations to cache
ISLocaleContext localeContext = new ISLocaleContext();
HttpContext httpContext = context.asContext(HttpContext.class);
//we have nothing else to go on at this point other than their request
localeContext.setLocale(httpContext);
SelfServiceInfo selfServiceInfo = configHandler.getConfig(realm, SelfServiceInfoBuilder.class);
RestSecurity restSecurity = restSecurityProvider.get(realm);
Set<String> protectedUserAttributes = new HashSet<>();
protectedUserAttributes.addAll(selfServiceInfo.getProtectedUserAttributes());
protectedUserAttributes.addAll(restSecurity.getProtectedUserAttributes());
try {
cookieDomains = AuthClientUtils.getCookieDomains();
result.put("domains", cookieDomains);
result.put("protectedUserAttributes", protectedUserAttributes);
result.put("cookieName", SystemProperties.get(Constants.AM_COOKIE_NAME, "iPlanetDirectoryPro"));
result.put("secureCookie", CookieUtils.isCookieSecure());
result.put("forgotPassword", String.valueOf(selfServiceInfo.isForgottenPasswordEnabled()));
result.put("forgotUsername", String.valueOf(selfServiceInfo.isForgottenUsernameEnabled()));
result.put("kbaEnabled", String.valueOf(selfServiceInfo.isKbaEnabled()));
result.put("selfRegistration", String.valueOf(selfServiceInfo.isUserRegistrationEnabled()));
result.put("lang", getJsLocale(localeContext.getLocale()));
result.put("successfulUserRegistrationDestination", "default");
result.put("socialImplementations", getSocialAuthnImplementations(realm));
result.put("referralsEnabled", Boolean.FALSE.toString());
result.put("zeroPageLogin", AuthUtils.getZeroPageLoginConfig(realm));
result.put("realm", realm);
result.put("xuiUserSessionValidationEnabled", SystemProperties.getAsBoolean(Constants.XUI_USER_SESSION_VALIDATION_ENABLED, true));
if (debug.messageEnabled()) {
debug.message("ServerInfoResource.getAllServerInfo ::" + " Added resource to response: " + ALL_SERVER_INFO);
}
resource = newResourceResponse(ALL_SERVER_INFO, Integer.toString(result.asMap().hashCode()), result);
return newResultPromise(resource);
} catch (Exception e) {
debug.error("ServerInfoResource.getAllServerInfo : Cannot retrieve all server info domains.", e);
return new NotFoundException(e.getMessage()).asPromise();
}
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class ServerInfoResource method getCookieDomains.
/**
* Retrieves the cookie domains set on the server.
*/
private Promise<ResourceResponse, ResourceException> getCookieDomains() {
JsonValue result = new JsonValue(new LinkedHashMap<String, Object>(1));
Set<String> cookieDomains;
ResourceResponse resource;
int rev;
try {
cookieDomains = AuthClientUtils.getCookieDomains();
rev = cookieDomains.hashCode();
result.put("domains", cookieDomains);
resource = newResourceResponse(COOKIE_DOMAINS, Integer.toString(rev), result);
if (debug.messageEnabled()) {
debug.message("ServerInfoResource.getCookieDomains ::" + " Added resource to response: " + COOKIE_DOMAINS);
}
return newResultPromise(resource);
} catch (Exception e) {
debug.error("ServerInfoResource.getCookieDomains : Cannot retrieve cookie domains.", e);
return new NotFoundException(e.getMessage()).asPromise();
}
}
use of org.forgerock.json.resource.ResourceException in project OpenAM by OpenRock.
the class SmsCollectionProvider method updateInstance.
/**
* Updates a child instance of config. The parent config referenced by the request path is found, and
* the config is updated using the resourceId.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId, UpdateRequest request) {
JsonValue content = request.getContent();
String realm = realmFor(context);
try {
Map<String, Set<String>> attrs = converter.fromJson(realm, content);
ServiceConfigManager scm = getServiceConfigManager(context);
ServiceConfig config = parentSubConfigFor(context, scm);
ServiceConfig node = checkedInstanceSubConfig(context, resourceId, config);
node.setAttributes(attrs);
JsonValue result = getJsonValue(realm, node);
return newResultPromise(newResourceResponse(resourceId, String.valueOf(result.hashCode()), result));
} catch (ServiceNotFoundException e) {
debug.warning("::SmsCollectionProvider:: ServiceNotFoundException on update", e);
return new NotFoundException("Unable to update SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on update", e);
return new InternalServerErrorException("Unable to update SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on update", e);
return new InternalServerErrorException("Unable to update SMS config: " + e.getMessage()).asPromise();
} catch (ResourceException e) {
return e.asPromise();
}
}
Aggregations