use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SitesResourceProvider method updateInstance.
@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String id, UpdateRequest request) {
JsonValue content = request.getContent();
try {
validWriteOperation(content, id);
} catch (BadRequestException e) {
return e.asPromise();
}
ResourceResponse site;
SSOToken token;
try {
token = getSsoToken(context);
site = getSite(token, id);
} catch (SMSException | SSOException | ConfigurationException e) {
debug.error("Could not read site {}", id, e);
return new InternalServerErrorException("Could not read site").asPromise();
} catch (NotFoundException e) {
return e.asPromise();
}
try {
if (!site.getRevision().equals(request.getRevision())) {
return new PreconditionFailedException("Revision did not match").asPromise();
}
SiteConfiguration.setSitePrimaryURL(token, id, content.get("url").asString());
SiteConfiguration.setSiteSecondaryURLs(token, id, content.get("secondaryURLs").asSet());
return newResultPromise(getSite(token, id));
} catch (SSOException | SMSException | ConfigurationException e) {
debug.error("Could not update site {}", id, e);
return new InternalServerErrorException("Could not update site").asPromise();
} catch (NotFoundException e) {
return new InternalServerErrorException("Could not read site after just updating it", e).asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class SmsCollectionProvider method createInstance.
/**
* Creates a new child instance of config. The parent config referenced by the request path is found, and
* new config is created using the provided name property.
* {@inheritDoc}
*/
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {
JsonValue content = request.getContent();
final String realm = realmFor(context);
try {
Map<String, Set<String>> attrs = converter.fromJson(realm, content);
ServiceConfigManager scm = getServiceConfigManager(context);
ServiceConfig config = parentSubConfigFor(context, scm);
String name = content.get("_id").asString();
if (name == null) {
name = request.getNewResourceId();
} else if (request.getNewResourceId() != null && !name.equals(request.getNewResourceId())) {
return new BadRequestException("name and URI's resource ID do not match").asPromise();
}
if (name == null) {
return new BadRequestException("Invalid name").asPromise();
}
config.addSubConfig(name, lastSchemaNodeName(), 0, attrs);
final ServiceConfig created = checkedInstanceSubConfig(context, name, config);
return awaitCreation(context, name).then(new Function<Void, ResourceResponse, ResourceException>() {
@Override
public ResourceResponse apply(Void aVoid) {
JsonValue result = getJsonValue(realm, created);
return newResourceResponse(created.getName(), String.valueOf(result.hashCode()), result);
}
});
} catch (ServiceAlreadyExistsException e) {
debug.warning("::SmsCollectionProvider:: ServiceAlreadyExistsException on create", e);
return new ConflictException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::SmsCollectionProvider:: SMSException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::SmsCollectionProvider:: SSOException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (ResourceException e) {
return e.asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class AuthenticationChainsFilter method transformRequestBody.
private JsonValue transformRequestBody(JsonValue body) throws InternalServerErrorException {
if (body.isDefined("authChainConfiguration")) {
try {
List<AuthConfigurationEntry> entries = new ArrayList<>();
for (JsonValue entry : body.get("authChainConfiguration")) {
String module = entry.get("module").asString();
String criteria = entry.get("criteria").asString();
String options = getOptions(entry);
entries.add(new AuthConfigurationEntry(module, criteria, options));
}
body.put("authChainConfiguration", AMAuthConfigUtils.authConfigurationEntryToXMLString(entries));
} catch (AMConfigurationException e) {
throw new InternalServerErrorException("Failed to parse authChainConfiguration", e);
}
}
return body;
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class AuthenticationModuleCollectionHandler method handleQuery.
/**
* Returns the list of configured authentication module instances for the current realm.
*
* {@inheritDoc}
*/
@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
String searchForId;
try {
searchForId = request.getQueryFilter().accept(new AuthenticationModuleQueryFilterVisitor(), null);
} catch (UnsupportedOperationException e) {
return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
}
if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
return new NotSupportedException("Query paging not currently supported").asPromise();
}
try {
SSOToken ssoToken = context.asContext(SSOTokenContext.class).getCallerSSOToken();
String realm = context.asContext(RealmContext.class).getResolvedRealm();
AMAuthenticationManager mgr = new AMAuthenticationManager(ssoToken, realm);
Set<AMAuthenticationInstance> moduleInstances = mgr.getAuthenticationInstances();
List<ResourceResponse> resourceResponses = new ArrayList<>();
for (AMAuthenticationInstance instance : moduleInstances) {
String name = instance.getName();
if (searchForId == null || searchForId.equalsIgnoreCase(name)) {
try {
ServiceSchemaManager schemaManager = getSchemaManager(instance.getType());
String type = schemaManager.getResourceName();
String typeDescription = getI18NValue(schemaManager, instance.getType(), debug);
JsonValue result = json(object(field(ResourceResponse.FIELD_CONTENT_ID, name), field("typeDescription", typeDescription), field("type", type)));
resourceResponses.add(newResourceResponse(name, String.valueOf(result.hashCode()), result));
} catch (AMConfigurationException ex) {
debug.error("AuthenticationModuleCollectionHandler.handleQuery(): Invalid auth module " + "instance configuration: {}", name);
if (debug.messageEnabled()) {
debug.message("AuthenticationModuleCollectionHandler.handleQuery(): Configuration exception: {}", name, ex);
}
}
}
}
return QueryResponsePresentation.perform(handler, request, resourceResponses);
} catch (AMConfigurationException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: AMConfigurationException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SSOException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: SSOException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
} catch (SMSException e) {
debug.warning("::AuthenticationModuleCollectionHandler:: SMSException on create", e);
return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
}
}
use of org.forgerock.json.resource.InternalServerErrorException in project OpenAM by OpenRock.
the class ClientResourceManager method getIdentity.
private AMIdentity getIdentity(String uName, String realm) throws InternalServerErrorException {
AMIdentity theID = null;
AMIdentityRepository amIdRepo = null;
amIdRepo = new AMIdentityRepository(realm, getAdminToken());
IdSearchControl idsc = new IdSearchControl();
idsc.setRecursive(true);
idsc.setAllReturnAttributes(true);
// search for the identity
Set<AMIdentity> results = Collections.EMPTY_SET;
try {
idsc.setMaxResults(0);
IdSearchResults searchResults = amIdRepo.searchIdentities(IdType.AGENTONLY, uName, idsc);
if (searchResults != null) {
results = searchResults.getSearchResults();
}
if (results == null || results.size() != 1) {
throw new InternalServerErrorException("Too many results or not enough");
}
theID = results.iterator().next();
} catch (IdRepoException e) {
throw new InternalServerErrorException("Unable to get search results", e);
} catch (SSOException e) {
throw new InternalServerErrorException("Unable to get search results", e);
}
return theID;
}
Aggregations