use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class UserDevicesDao method getIdentity.
/**
* Gets the {@code AMIdentity} for the authenticated user.
*
* @param userName The user's name.
* @param realm The user's realm.
* @return An {@code AMIdentity}.
* @throws InternalServerErrorException If there is a problem getting the user's identity.
*/
private AMIdentity getIdentity(String userName, String realm) throws InternalServerErrorException {
final AMIdentity amIdentity;
final AMIdentityRepository amIdRepo = AuthD.getAuth().getAMIdentityRepository(realm);
final IdSearchControl idsc = new IdSearchControl();
idsc.setAllReturnAttributes(true);
Set<AMIdentity> results = Collections.emptySet();
try {
idsc.setMaxResults(NO_LIMIT);
IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.USER, userName, idsc);
if (searchResults != null) {
results = searchResults.getSearchResults();
}
if (results.isEmpty()) {
throw new IdRepoException("getIdentity : User " + userName + " is not found");
} else if (results.size() > 1) {
throw new IdRepoException("getIdentity : More than one user found for the userName " + userName);
}
amIdentity = results.iterator().next();
} catch (IdRepoException | SSOException e) {
throw new InternalServerErrorException(e.getMessage(), e);
}
return amIdentity;
}
use of org.forgerock.json.resource.InternalServerErrorException 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.InternalServerErrorException 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();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SitesResourceProvider method queryCollection.
@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
if (!"true".equals(request.getQueryFilter().toString())) {
return new BadRequestException("Query only supports 'true' filter").asPromise();
}
try {
SSOToken token = getSsoToken(context);
Set<String> siteNames = SiteConfiguration.getSites(token);
for (String siteName : siteNames) {
handler.handleResource(getSite(token, siteName));
}
return newResultPromise(newQueryResponse());
} catch (SSOException | SMSException | ConfigurationException e) {
debug.error("Could not read sites", e);
return new InternalServerErrorException("Could not read sites").asPromise();
} catch (NotFoundException e) {
debug.error("Could not read site", e);
return new InternalServerErrorException("Could not read site we've just got name for").asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException 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