use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class ScriptConfigurationDataStore method getAll.
@Override
public Set<ScriptConfiguration> getAll() throws ScriptException {
final Set<ScriptConfiguration> scriptConfigurations = new LinkedHashSet<>();
try {
ServiceConfig config = getSubOrgConfig();
Set<String> uuids = config.getSubConfigNames();
for (String uuid : uuids) {
scriptConfigurations.add(scriptConfigurationFromMap(uuid, config.getSubConfig(uuid).getAttributesForRead()));
}
config = getSubGlobalConfig();
uuids = config.getSubConfigNames();
for (String uuid : uuids) {
scriptConfigurations.add(scriptConfigurationFromMap(uuid, config.getSubConfig(uuid).getAttributesForRead()));
}
} catch (SSOException | SMSException e) {
throw createAndLogError(logger, RETRIEVE_ALL_FAILED, e, realm);
}
return scriptConfigurations;
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class ScriptConfigurationDataStore method get.
@Override
public ScriptConfiguration get(String uuid) throws ScriptException {
try {
ServiceConfig config = getSubOrgConfig();
if (config.getSubConfigNames().contains(uuid)) {
return scriptConfigurationFromMap(uuid, config.getSubConfig(uuid).getAttributesForRead());
}
config = getSubGlobalConfig();
if (config.getSubConfigNames().contains(uuid)) {
return scriptConfigurationFromMap(uuid, config.getSubConfig(uuid).getAttributesForRead());
}
} catch (SSOException | SMSException e) {
throw createAndLogError(logger, RETRIEVE_FAILED, e, uuid, realm);
}
throw createAndLogError(logger, SCRIPT_UUID_NOT_FOUND, uuid, realm);
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class ScriptConfigurationDataStoreTest method shouldFailIfAttemptingToDeleteDefaultScript.
@Test
public void shouldFailIfAttemptingToDeleteDefaultScript() throws Exception {
// given
String uuid = "1234567890";
ServiceConfig defaultScriptSubConfig = mock(ServiceConfig.class);
given(subGlobalConfig.getSubConfig(uuid)).willReturn(defaultScriptSubConfig);
given(defaultScriptSubConfig.exists()).willReturn(true);
// when
try {
dataStore.delete(uuid);
fail("shouldFailIfAttemptingToDeleteDefaultScript");
} catch (ScriptException e) {
// then
assertEquals(e.getScriptErrorCode(), RETRIEVE_FAILED);
}
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class MigrateValidGotoSetting method initialize.
@Override
public void initialize() throws UpgradeException {
try {
final PolicyManager pm = new PolicyManager(getAdminToken(), HIDDEN_REALM);
if (pm.getPolicyNames(DELEGATION_POLICY_NAME).isEmpty()) {
if (DEBUG.messageEnabled()) {
DEBUG.message("Unable to find the delegation policy in the hidden realm, looking for existing goto" + " domain values.");
}
//The delegation policy is not defined yet in the configuration, we need to migrate the goto domains.
final ServiceConfigManager scm = new ServiceConfigManager(ISAuthConstants.AUTH_SERVICE_NAME, getAdminToken());
for (final String realm : getRealmNames()) {
if (DEBUG.messageEnabled()) {
DEBUG.message("Looking for valid goto URLs in realm " + realm);
}
final ServiceConfig organizationConfig = scm.getOrganizationConfig(realm, null);
final Map<String, Set<String>> attrs = organizationConfig.getAttributesWithoutDefaults();
final Set<String> validDomains = attrs.get(LEGACY_GOTO_DOMAINS_SETTING);
if (validDomains != null && !validDomains.isEmpty()) {
changes.put(realm, validDomains);
}
}
if (DEBUG.messageEnabled()) {
DEBUG.message("Found the following existing goto URL domains in realms: " + changes);
}
} else {
delegationPolicyFound = true;
}
} catch (final NameNotFoundException nnfe) {
throw new UpgradeException("Unable to find hidden realm", nnfe);
} catch (final PolicyException pe) {
throw new UpgradeException("Unexpected error occurred while retrieving policies from the hidden realm", pe);
} catch (final SMSException smse) {
throw new UpgradeException("An error occurred while checking for old valid goto domains", smse);
} catch (final SSOException ssoe) {
throw new UpgradeException("An error occurred while checking for old valid goto domains", ssoe);
}
}
use of com.sun.identity.sm.ServiceConfig in project OpenAM by OpenRock.
the class MigrateValidGotoSetting method perform.
@Override
public void perform() throws UpgradeException {
try {
if (!changes.isEmpty()) {
final ServiceConfigManager validationService = new ServiceConfigManager(VALIDATION_SERVICE, getAdminToken());
final ServiceConfigManager authService = new ServiceConfigManager(ISAuthConstants.AUTH_SERVICE_NAME, getAdminToken());
for (final Map.Entry<String, Set<String>> entry : changes.entrySet()) {
final String realm = entry.getKey();
if (DEBUG.messageEnabled()) {
DEBUG.message("Starting to migrate goto domains for realm: " + realm);
}
UpgradeProgress.reportStart("upgrade.goto.migrate.start", realm);
validationService.createOrganizationConfig(realm, getAttrMap(GOTO_RESOURCES, entry.getValue()));
//The settings now are migrated, we should now clear up the legacy settings
if (DEBUG.messageEnabled()) {
DEBUG.message("Removing old goto domains from iPlanetAMAuthService");
}
final ServiceConfig organizationConfig = authService.getOrganizationConfig(realm, null);
organizationConfig.setAttributes(getAttrMap(LEGACY_GOTO_DOMAINS_SETTING, Collections.EMPTY_SET));
UpgradeProgress.reportEnd("upgrade.success");
}
}
if (DEBUG.messageEnabled()) {
DEBUG.message("Attempting to create the delegation policy in the hidden realm");
}
UpgradeProgress.reportStart("upgrade.goto.policy.start");
final PolicyManager pm = new PolicyManager(getAdminToken(), HIDDEN_REALM);
String policy = AMSetupServlet.readFile(DELEGATION_POLICY_FILE);
policy = ServicesDefaultValues.tagSwap(policy, true);
//Adding the delegation privileges to allow agent accounts to read the new validationService.
PolicyUtils.createPolicies(pm, new ByteArrayInputStream(policy.getBytes()));
if (DEBUG.messageEnabled()) {
DEBUG.message("Delegation policy successfully created under the hidden realm");
}
UpgradeProgress.reportEnd("upgrade.success");
} catch (final IOException ioe) {
UpgradeProgress.reportEnd("upgrade.failed");
throw new UpgradeException("An IO error occurred while reading the delegation policy", ioe);
} catch (final PolicyException pe) {
UpgradeProgress.reportEnd("upgrade.failed");
throw new UpgradeException("An unexpected error occurred while importing the delegation policy", pe);
} catch (final SMSException smse) {
UpgradeProgress.reportEnd("upgrade.failed");
throw new UpgradeException("An error occurred while migrating the valid goto domain setting", smse);
} catch (final SSOException ssoe) {
UpgradeProgress.reportEnd("upgrade.failed");
throw new UpgradeException("An error occurred while migrating the valid goto domain setting", ssoe);
}
}
Aggregations