ConfigObjectService.java revision 7523c7f44ed55a9882212a3925629e54c1295dae
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyrighted [year] [name of copyright owner]".
*
* Copyright © 2011 ForgeRock AS. All rights reserved.
*/
// Deprecated
/**
* Provides access to OSGi configuration
*
* @author aegloff
*/
name = "org.forgerock.openidm.config",
immediate = true,
)
@Properties({
})
public class ConfigObjectService extends ObjectSetJsonResource {
private ComponentContext context;
private ConfigCrypto configCrypto;
/**
* Gets an object from the object set by identifier.
* <p/>
* The object may contain metadata properties, including object identifier {@code _id},
* and object version {@code _rev} to enable optimistic concurrency supported by OpenIDM.
*
* @param fullId the identifier of the object to retrieve from the object set.
* @return the requested object.
* @throws NotFoundException if the specified object could not be found.
* @throws ForbiddenException if access to the object is forbidden.
* @throws BadRequestException if the passed identifier is invalid
*/
try {
// List all configurations
if (null != rawConfigs) {
if (properties != null) {
}
// If there is an alias for factory config is available, make a nicer ID then the internal PID
} else {
}
}
}
} else {
}
JsonValue value = enhancedConfig.getConfiguration(props, context.getBundleContext(), fullId, false);
}
} catch (ObjectSetException ex) {
throw ex;
throw new InternalServerErrorException("Failure to load configuration for " + fullId + ": " + ex.getMessage(), ex);
}
return result;
}
/**
* Creates a new object in the object set.
* <p/>
* This method sets the {@code _id} property to the assigned identifier for the object,
* and the {@code _rev} property to the revised object version (For optimistic concurrency)
*
* @param fullId the client-generated identifier to use, or {@code null} if server-generated identifier is requested.
* @param obj the contents of the object to create in the object set.
* @throws NotFoundException if the specified id could not be resolved.
* @throws ForbiddenException if access to the object or object set is forbidden.
* @throws PreconditionFailedException if an object with the same ID already exists.
* @throws BadRequestException if the passed identifier is invalid
*/
throw new BadRequestException("The passed identifier to create is null");
}
try {
if (parsedId.isFactoryConfig()) {
throw new BadRequestException("router config can not be factory config");
}
} else {
}
throw new PreconditionFailedException("Can not create a new configuration with ID "
+ parsedId + ", configuration for this ID already exists.");
}
Dictionary dict = configCrypto.encrypt(parsedId.getPidOrFactoryPid(), parsedId.instanceAlias, null, new JsonValue(obj));
if (parsedId.isFactoryConfig()) {
dict.put(JSONConfigInstaller.SERVICE_FACTORY_PID_ALIAS, parsedId.instanceAlias); // The alias for the PID as understood by fileinstall
}
} catch (ObjectSetException ex) {
throw ex;
} catch (WaitForMetaData ex) {
logger.info("No meta-data provider available yet to create and encrypt configuration for {}, retry later.", fullId, ex);
throw new InternalServerErrorException("No meta-data provider available yet to create and encrypt configuration for "
throw new InternalServerErrorException("Failure to create configuration for " + fullId + ": " + ex.getMessage(), ex);
}
}
/**
* Updates the specified object in the object set.
* <p/>
* This implementation requires MVCC and hence enforces that clients state what revision they expect
* to be updating
* <p/>
* If successful, this method updates metadata properties within the passed object,
* including: a new {@code _rev} value for the revised object's version
*
* @param fullId the identifier of the object to be put, or {@code null} to request a generated identifier.
* @param rev the version of the object to update; or {@code null} if not provided.
* @param obj the contents of the object to put in the object set.
* @throws ConflictException if version is required but is {@code null}.
* @throws ForbiddenException if access to the object is forbidden.
* @throws NotFoundException if the specified object could not be found.
* @throws PreconditionFailedException if version did not match the existing object in the set.
* @throws BadRequestException if the passed identifier is invalid
*/
throw new BadRequestException("The passed identifier to update is null");
}
try {
if (existingConfig == null) {
throw new NotFoundException("No existing configuration found for " + fullId + ", can not update the configuration.");
}
existingConfig = configCrypto.encrypt(parsedId.getPidOrFactoryPid(), parsedId.instanceAlias, existingConfig, new JsonValue(obj));
} catch (ObjectSetException ex) {
throw ex;
throw new InternalServerErrorException("Failure to update configuration for " + fullId + ": " + ex.getMessage(), ex);
}
}
/**
* Deletes the specified object from the object set.
*
* @param fullId the identifier of the object to be deleted.
* @param rev the version of the object to delete or {@code null} if not provided.
* @throws NotFoundException if the specified object could not be found.
* @throws ForbiddenException if access to the object is forbidden.
* @throws ConflictException if version is required but is {@code null}.
* @throws PreconditionFailedException if version did not match the existing object in the set.
*/
throw new BadRequestException("The passed identifier to delete is null");
}
try {
if (existingConfig == null) {
throw new NotFoundException("No existing configuration found for " + fullId + ", can not delete the configuration.");
}
} catch (ObjectSetException ex) {
throw ex;
throw new InternalServerErrorException("Failure to delete configuration for " + fullId + ": " + ex.getMessage(), ex);
}
}
/**
* Locate an existing configuration based on its id, which can be
* a pid or for factory configurations the <factory pid>/<alias>
* pids can be qualified or if they use the default openidm prefix unqualified
*
* @param fullId the id
* @return the configuration if found, null if not
* @throws IOException
* @throws InvalidSyntaxException
*/
Configuration findExistingConfiguration(String fullId) throws IOException, InvalidSyntaxException, BadRequestException {
if (parsedId.isFactoryConfig()) {
filter = "(&(" + ConfigurationAdmin.SERVICE_FACTORYPID + "=" + factoryPid + ")(" + JSONConfigInstaller.SERVICE_FACTORY_PID_ALIAS + "=" + parsedId.instanceAlias + "))";
} else {
}
return configurations[0];
} else {
return null;
}
}
}
/**
* TODO: Description.
*
* @param context TODO.
*/
}
}
class ParsedId {
public String factoryPid;
public String instanceAlias;
throw new BadRequestException("The passed identifier to has more then one '/'");
}
case 2: {
// Do blank check StringUtils.isBlank()
}
}
case 1: {
throw new BadRequestException("The passed Factory identifier has no pid");
} else {
if (null == instanceAlias) {
} else {
}
}
}
}
if (null != factoryPid) {
} else {
}
}
/**
* @return is this ID represents a managed factory configuration, or false if it is a managed service configuraiton
*/
public boolean isFactoryConfig() {
return (instanceAlias != null);
}
/*
* Make the PID fully qualified with the default context for OpenIDM
*/
}
/**
* Get the qualified pid of the managed service or managed factory depending on the configuration represented
* Some APIs do not distinguish beween single managed service PID and managed factory PID
*
* @return the qualified pid if this ID represents a managed service configuration, or the managed factory PID
* if it represents a managed factory configuration
*/
public String getPidOrFactoryPid() {
if (isFactoryConfig()) {
return qualifyPid(factoryPid);
} else {
return qualifyPid(pid);
}
}
if (isFactoryConfig()) {
} else {
return pid;
}
}
}