use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class UpgradeUtils method deleteService.
public static void deleteService(String serviceName, SSOToken adminToken) throws UpgradeException {
String classMethod = "UpgradeUtils:deleteService : ";
try {
ServiceManager sm = new ServiceManager(adminToken);
ServiceConfigManager scm = new ServiceConfigManager(serviceName, adminToken);
if (scm.getGlobalConfig(null) != null) {
scm.removeGlobalConfiguration(null);
}
ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName, adminToken);
Set<String> versions = sm.getServiceVersions(serviceName);
if (ssm.getPolicySchema() == null) {
if (debug.messageEnabled()) {
debug.message("Service has policy schema; matching policy schema will be removed");
}
deletePolicyRule(serviceName, adminToken);
}
for (String version : versions) {
sm.removeService(serviceName, version);
}
} catch (SSOException ssoe) {
debug.error(classMethod + ssoe.getMessage());
throw new UpgradeException(ssoe);
} catch (SMSException smse) {
debug.error(classMethod + smse.getMessage());
throw new UpgradeException(smse);
} catch (AMException ame) {
debug.error(classMethod + ame.getMessage());
throw new UpgradeException(ame);
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class UpgradeUtils method removeSubConfigAttributeDefaultValues.
/**
* Removes attributes default values from service subconfiguration.
*
* @param serviceName name of the service
* @param sunServiceID set of service identifiers
* @param realm the realm name
* @param subConfigName the service sub-configuration name.
* @param attributeName name of the attribute
* @param defaultValues a set of values to be removed
*/
public static void removeSubConfigAttributeDefaultValues(String serviceName, Set sunServiceID, String realm, String subConfigName, String attributeName, Set defaultValues) {
String classMethod = "UpgradeUtils:removeSubConfigAttributeDefaultValues : ";
try {
ServiceConfigManager scm = getServiceConfigManager(serviceName);
ServiceConfig sc = scm.getOrganizationConfig(realm, null);
ServiceConfig subConfig = sc.getSubConfig(subConfigName);
String serviceID = getSunServiceID(subConfig);
if (debug.messageEnabled()) {
debug.message(classMethod + "sunServiceID :" + sunServiceID);
debug.message(classMethod + "serviceID :" + serviceID);
debug.message(classMethod + "subConfigName :" + subConfigName);
debug.message(classMethod + "Attribute Name :" + attributeName);
debug.message(classMethod + "Default Values :" + defaultValues);
}
if (sunServiceID.contains(serviceID)) {
Set valSet = getExistingValues(subConfig, attributeName, defaultValues);
if (debug.messageEnabled()) {
debug.message(classMethod + "Values to be removed" + valSet);
}
subConfig.removeAttributeValues(attributeName, valSet);
}
} catch (SSOException ssoe) {
debug.error(classMethod + "Invalid SSOToken : ", ssoe);
} catch (SMSException sme) {
debug.error(classMethod + "Error remove default values : ", sme);
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class UpgradeUtils method addAttributeToSubConfiguration.
/**
* Adds attributes to service sub configuration.
*
* @param serviceName the service name
* @param subConfigName the sub configuration name
* @param attrValues Map of attributes key is the attribute name and
* value a set of attribute values.
* @throws UpgradeException on error.
*/
public static void addAttributeToSubConfiguration(String serviceName, String subConfigName, Map attrValues) throws UpgradeException {
String classMethod = "UpgradeUtils:addAttributeToSubConfiguration : ";
try {
ServiceConfigManager scm = getServiceConfigManager(serviceName);
ServiceConfig sc = scm.getGlobalConfig(null);
StringTokenizer st = new StringTokenizer(subConfigName, "/");
int tokenCount = st.countTokens();
for (int i = 1; i <= tokenCount; i++) {
String scn = st.nextToken();
sc = sc.getSubConfig(scn);
}
for (Iterator i = attrValues.keySet().iterator(); i.hasNext(); ) {
String attrName = (String) i.next();
sc.addAttribute(attrName, (Set) attrValues.get(attrName));
}
} catch (SMSException sme) {
throw new UpgradeException("Unable to add attribute to subconfig");
} catch (SSOException ssoe) {
throw new UpgradeException("invalid SSOToken");
} catch (Exception e) {
debug.error(classMethod + "Error adding attribute to subconfig:", e);
}
if (debug.messageEnabled()) {
debug.message(classMethod + "Added attributes " + attrValues + " to subconfig " + subConfigName + " in service " + serviceName);
}
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class UpgradeUtils method getOrgSubConfigs.
/**
* Return sub configurations in a service.
*
* @param serviceName the service name.
* @param serviceVersion the version of the service
* @param realm the realm to retreive the sub configs from.
* @return a set containing the org sub configurations.
*/
static Set getOrgSubConfigs(String serviceName, String serviceVersion, String realm) {
String classMethod = "UpgradeUtils:getOrgSubConfigs : ";
Set subConfigs;
try {
ServiceConfigManager scm = new ServiceConfigManager(ssoToken, serviceName, serviceVersion);
ServiceConfig orgConfig = scm.getOrganizationConfig(realm, null);
subConfigs = orgConfig.getSubConfigNames();
if (debug.messageEnabled()) {
debug.message(classMethod + "Org subConfigs : " + subConfigs);
}
} catch (Exception e) {
if (debug.messageEnabled()) {
debug.message(classMethod + "No organization subconfigs", e);
}
subConfigs = Collections.EMPTY_SET;
}
return subConfigs;
}
use of com.sun.identity.sm.ServiceConfigManager in project OpenAM by OpenRock.
the class RemoveNetscapeLDAPStep method initialize.
@Override
public void initialize() throws UpgradeException {
try {
if (VersionUtils.isCurrentVersionLessThan(AM_13, true)) {
for (String realm : getRealmNames()) {
ServiceConfigManager scm = new ServiceConfigManager(IdConstants.REPO_SERVICE, getAdminToken());
ServiceConfig sc = scm.getOrganizationConfig(realm, null);
if (sc != null) {
Set<String> subConfigNames = sc.getSubConfigNames("*", NETSCAPE_LDAP_V3);
if (!subConfigNames.isEmpty()) {
Set<String> names = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
names.addAll(subConfigNames);
subSchemaIds.put(realm, names);
}
}
}
ServiceSchemaManager ssm = new ServiceSchemaManager(IdConstants.REPO_SERVICE, getAdminToken());
ServiceSchema orgSchema = ssm.getOrganizationSchema();
if (orgSchema.getSubSchemaNames().contains(NETSCAPE_LDAP_V3)) {
removeSubSchema = true;
}
}
} catch (Exception ex) {
DEBUG.error("Unable to identify old datastore configurations", ex);
throw new UpgradeException("An error occured while trying to identify old datastore configurations");
}
}
Aggregations