use of org.forgerock.json.resource.NotFoundException 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.NotFoundException 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.NotFoundException 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.NotFoundException in project OpenAM by OpenRock.
the class UserDevicesResource method deleteInstance.
/**
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId, DeleteRequest request) {
final String userName = contextHelper.getUserId(context);
try {
List<JsonValue> devices = userDevicesDao.getDeviceProfiles(userName, getRealm(context));
JsonValue toDelete = null;
for (JsonValue device : devices) {
if (resourceId.equals(device.get(UUID_KEY).asString())) {
toDelete = device;
break;
}
}
if (toDelete == null) {
return new NotFoundException("User device, " + resourceId + ", not found.").asPromise();
}
devices.remove(toDelete);
userDevicesDao.saveDeviceProfiles(userName, getRealm(context), devices);
return newResultPromise(newResourceResponse(resourceId, toDelete.hashCode() + "", toDelete));
} catch (InternalServerErrorException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.NotFoundException in project OpenAM by OpenRock.
the class SitesResourceProvider method createInstance.
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {
JsonValue content = request.getContent();
String id = request.getNewResourceId();
try {
id = validWriteOperation(content, id);
} catch (BadRequestException e) {
return e.asPromise();
}
String url = content.get(PRIMARY_URL).asString();
try {
SSOToken token = getSsoToken(context);
if (SiteConfiguration.isSiteExist(token, id)) {
return new ConflictException("Site with id already exists: " + id).asPromise();
}
SiteConfiguration.createSite(token, id, url, content.get(SECONDARY_URLS).asSet());
debug.message("Site created: {}", id);
return newResultPromise(getSite(token, id));
} catch (SMSException | SSOException | ConfigurationException e) {
debug.error("Could not create site", e);
return new InternalServerErrorException("Could not create site").asPromise();
} catch (NotFoundException e) {
return new InternalServerErrorException("Could not read site just created").asPromise();
}
}
Aggregations