use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeOAuth2ClientStep method perform.
@Override
public void perform() throws UpgradeException {
for (Map.Entry<String, Map<AgentType, Map<String, Set<String>>>> entry : upgradableConfigs.entrySet()) {
String realm = entry.getKey();
try {
ServiceConfigManager scm = new ServiceConfigManager(IdConstants.AGENT_SERVICE, getAdminToken());
for (Map.Entry<AgentType, Map<String, Set<String>>> changes : entry.getValue().entrySet()) {
AgentType type = changes.getKey();
ServiceConfig sc = scm.getOrganizationConfig(realm, type.instanceName);
for (Map.Entry<String, Set<String>> subConfig : changes.getValue().entrySet()) {
UpgradeProgress.reportStart("upgrade.oauth2.start", subConfig.getKey());
ServiceConfig oauth2Config = sc.getSubConfig(subConfig.getKey());
Map<String, Set<String>> attrs = oauth2Config.getAttributesWithoutDefaults();
for (String attrName : subConfig.getValue()) {
if (CHANGED_PROPERTIES.contains(attrName)) {
Set<String> values = attrs.get(attrName);
// If single string scopes are included in the Scope(s) or Default Scope(s), then apend a pipe.
if (VersionUtils.isCurrentVersionLessThan(AM_13, true) && (SCOPES.equals(attrName) || DEFAULT_SCOPES.equals(attrName))) {
addScopesWithPipe(attrs, attrName, values);
}
String value = CollectionHelper.getMapAttr(attrs, attrName);
if (value != null) {
if (!pattern.matcher(value).matches()) {
if (values != null) {
attrs.put(attrName, convertValues(values));
}
}
}
} else if (IDTOKEN_SIGNED_RESPONSE_ALG.equals(attrName)) {
String value = CollectionHelper.getMapAttr(attrs, attrName);
if (ALGORITHM_NAMES.containsKey(value)) {
attrs.put(attrName, Collections.singleton(ALGORITHM_NAMES.get(value)));
}
} else if (ADDED_LIFETIME_PROPERTIES.contains(attrName)) {
attrs.put(attrName, Collections.singleton("0"));
}
}
oauth2Config.setAttributes(attrs);
UpgradeProgress.reportEnd("upgrade.success");
}
}
} catch (Exception ex) {
UpgradeProgress.reportEnd("upgrade.failed");
DEBUG.error("An error occurred while trying to upgrade an OAuth2 client", ex);
throw new UpgradeException("Unable to upgrade OAuth2 client");
}
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeOAuth2ProviderStep method persistDefaultsForProviders.
private void persistDefaultsForProviders() throws UpgradeException {
try {
for (Map.Entry<String, Map<String, Set<String>>> entry : attributesToUpdate.entrySet()) {
final String realm = entry.getKey();
UpgradeProgress.reportStart("upgrade.oauth2.provider.start", realm);
final ServiceConfig serviceConfig = scm.getOrganizationConfig(realm, null);
Map<String, Set<String>> attributes = entry.getValue();
if (attributes == null) {
attributes = serviceConfig.getAttributesWithoutDefaults();
}
renameAlgorithms(attributes);
sortScopes(attributes);
serviceConfig.setAttributes(attributes);
UpgradeProgress.reportEnd("upgrade.success");
}
} catch (Exception e) {
UpgradeProgress.reportEnd("upgrade.failed");
DEBUG.error("An error occurred while trying to upgrade an OAuth2 Provider", e);
throw new UpgradeException("Unable to upgrade OAuth2 Providers.", e);
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeServiceUtils method getServiceDefinitions.
/**
* Loads a DOM {@code Document} for each defined service.
* @param token The admin token.
* @return A map of service name to the service DOM models.
* @throws UpgradeException When the service XML cannot be loaded.
*/
static Map<String, Document> getServiceDefinitions(SSOToken token) throws UpgradeException {
List<String> serviceNames = new ArrayList<>();
serviceNames.addAll(UpgradeUtils.getPropertyValues(SetupConstants.PROPERTY_FILENAME, SetupConstants.SERVICE_NAMES));
Map<String, Document> newServiceDefinitions = new HashMap<>();
String basedir = SystemProperties.get(SystemProperties.CONFIG_PATH);
ServicesDefaultValues.setServiceConfigValues(getUpgradeHttpServletRequest(basedir, token));
for (String serviceFileName : serviceNames) {
boolean tagswap = true;
if (serviceFileName.startsWith("*")) {
serviceFileName = serviceFileName.substring(1);
tagswap = false;
}
String strXML;
try {
strXML = IOUtils.readStream(UpgradeServiceUtils.class.getClassLoader().getResourceAsStream(serviceFileName));
} catch (IOException ioe) {
DEBUG.error("unable to load services file: " + serviceFileName, ioe);
throw new UpgradeException(ioe);
}
if (tagswap) {
strXML = ServicesDefaultValues.tagSwap(strXML, true);
}
Document serviceSchema = fetchDocumentSchema(strXML, token);
newServiceDefinitions.put(UpgradeUtils.getServiceName(serviceSchema), serviceSchema);
}
return newServiceDefinitions;
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeServiceUtils method setUserAndPassword.
private static void setUserAndPassword(IHttpServletRequest requestFromFile, String basedir) throws UpgradeException {
try {
BootstrapData bootStrap = new BootstrapData(basedir);
Map<String, String> data = bootStrap.getDataAsMap(0);
requestFromFile.addParameter(SetupConstants.CONFIG_VAR_DS_MGR_DN, data.get(BootstrapData.DS_MGR));
requestFromFile.addParameter(SetupConstants.CONFIG_VAR_DS_MGR_PWD, JCECrypt.decode(data.get(BootstrapData.DS_PWD)));
} catch (IOException ioe) {
DEBUG.error("Unable to load directory user/password from bootstrap file", ioe);
throw new UpgradeException("Unable to load bootstrap file: " + ioe.getMessage());
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeServiceUtils method getUpgradeHttpServletRequest.
private static IHttpServletRequest getUpgradeHttpServletRequest(String basedir, SSOToken token) throws UpgradeException {
// need to reinitialize the tag swap property map with original install params
IHttpServletRequest requestFromFile = new UpgradeHttpServletRequest(basedir);
try {
Properties foo = ServerConfiguration.getServerInstance(token, WebtopNaming.getLocalServer());
requestFromFile.addParameter(SetupConstants.CONFIG_VAR_ENCRYPTION_KEY, foo.getProperty(Constants.ENC_PWD_PROPERTY));
String dbOption = (String) requestFromFile.getParameterMap().get(SetupConstants.CONFIG_VAR_DATA_STORE);
boolean embedded = dbOption.equals(SetupConstants.SMS_EMBED_DATASTORE);
if (!embedded) {
setUserAndPassword(requestFromFile, basedir);
}
} catch (Exception ex) {
DEBUG.error("Unable to initialise services defaults", ex);
throw new UpgradeException("Unable to initialise services defaults: " + ex.getMessage());
}
return requestFromFile;
}
Aggregations