use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeResourceTypeStep method saveResourceType.
/**
* Persist the given resource type.
* @param resourceType The resource type to save.
* @throws UpgradeException If the resource type failed to persist.
*/
private void saveResourceType(ResourceType resourceType, String realm) throws UpgradeException {
try {
UpgradeProgress.reportStart(AUDIT_CREATE_RESOURCE_TYPE_START, resourceType.getName());
resourceTypeService.saveResourceType(getAdminSubject(), realm, resourceType);
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException ee) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw new UpgradeException("Failed to create resource type " + resourceType.getName(), ee);
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeResourceTypeStep method upgradePrivilege.
/**
* Add the resource type UUID to the privilege and persist it.
* @param privilegeManager The PrivilegeManager for the realm in which the privilege resides.
* @param privilege The privilege to upgrade.
* @param resourceTypeUUID The resource type associated with the privilege.
* @throws UpgradeException If the privilege failed to persist.
*/
private void upgradePrivilege(PrivilegeManager privilegeManager, Privilege privilege, String resourceTypeUUID) throws UpgradeException {
try {
UpgradeProgress.reportStart(AUDIT_MODIFIED_POLICY_UUID_START, privilege.getName());
if (privilege != null) {
privilege.setResourceTypeUuid(resourceTypeUUID);
privilegeManager.modify(privilege);
}
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException ee) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw new UpgradeException("Failed to add resource type uuid to privilege " + privilege.getName(), ee);
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class OldPolicyConditionMigrationUpgradeStep method perform.
/**
* Does the persisting of the upgraded policies.
*
* @throws UpgradeException If there is a problem saving the policies.
*/
@Override
public void perform() throws UpgradeException {
for (Map.Entry<String, Set<Privilege>> entry : privilegesToUpgrade.entrySet()) {
String realm = entry.getKey();
//ensure reading apps cleanly
ApplicationManager.clearCache(realm);
PrivilegeManager privilegeManager = getPrivilegeManager(realm);
for (Privilege privilege : entry.getValue()) {
privilege.getEntitlement().clearCache();
try {
addResourceType(privilege, realm);
privilegeManager.modify(privilege.getName(), privilege);
} catch (EntitlementException e) {
DEBUG.error("Failed to modify privilege!", e);
throw new UpgradeException("Failed to modify privilege!", e);
}
}
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class OldPolicyConditionMigrationUpgradeStep method initialize.
/**
* Checks what policies could be automatically upgraded and performs the upgrade without saving so that the
* migrated policy can be validated to ensure the upgrade went well.
*
* @throws UpgradeException If a problem occurred checking the policies.
*/
@Override
public void initialize() throws UpgradeException {
if (!isCurrentVersionLessThan(1200, true)) {
return;
}
try {
DEBUG.message("Initializing OldPolicyConditionMigrationStep");
for (String realm : getRealmNames()) {
if (!realm.startsWith("/")) {
realm = "/" + realm;
}
PrivilegeManager privilegeManager = getPrivilegeManager(realm);
List<Privilege> privileges;
try {
privileges = privilegeManager.findAllPolicies();
} catch (EntitlementException e) {
continue;
}
for (Privilege privilege : privileges) {
if (conditionUpgrader.isPolicyUpgradable(privilege)) {
try {
MigrationReport report = conditionUpgrader.dryRunPolicyUpgrade(privilege);
addReport(realm, report);
addUpgradablePolicy(realm, privilege);
} catch (Exception e) {
addUnupgradablePolicy(realm, privilege);
}
}
}
}
} catch (UpgradeException e) {
DEBUG.error("Error while trying to detect changes in entitlements", e);
throw e;
} catch (Exception ex) {
DEBUG.error("Error while trying to detect changes in entitlements", ex);
throw new UpgradeException(ex);
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeResourceTypeStepTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
privilegedAction = mock(PrivilegedAction.class);
resourceTypeService = mock(ResourceTypeService.class);
connectionFactory = mock(ConnectionFactory.class);
configManager = mock(ServiceConfigManager.class);
upgradeResourceTypeStep = new UpgradeResourceTypeStep(configManager, resourceTypeService, privilegedAction, connectionFactory, Collections.<String>emptySet()) {
@Override
protected Document getEntitlementXML() throws UpgradeException {
return document;
}
@Override
protected Set<String> getRealmNamesFromParent() throws UpgradeException {
return realms;
}
@Override
protected Set<String> policiesEligibleForUpgrade(String appName, String realm) throws UpgradeException {
return policies;
}
};
when(document.getElementsByTagName(anyString())).thenReturn(new NodeList() {
@Override
public Node item(int i) {
return null;
}
@Override
public int getLength() {
return 0;
}
});
// Mock global and application type service configuration
ServiceConfig globalConfig = mock(ServiceConfig.class);
when(configManager.getGlobalConfig(anyString())).thenReturn(globalConfig);
ServiceConfig appTypesConfig = mock(ServiceConfig.class);
when(globalConfig.getSubConfig(anyString())).thenReturn(appTypesConfig);
// Mock organisation and application service configuration
ServiceConfig orgConfig = mock(ServiceConfig.class);
when(configManager.getOrganizationConfig(anyString(), anyString())).thenReturn(orgConfig);
ServiceConfig appsConfig = mock(ServiceConfig.class);
when(orgConfig.getSubConfig(anyString())).thenReturn(appsConfig);
// Mock application names
when(appsConfig.getSubConfigNames()).thenReturn(Collections.singleton("MyApplication"));
// Mock application data
ServiceConfig appConfig = mock(ServiceConfig.class);
when(appsConfig.getSubConfig("MyApplication")).thenReturn(appConfig);
when(appConfig.getAttributes()).thenReturn(appData);
// Mock application type on application and application type data
ServiceConfig appTypeConfig = mock(ServiceConfig.class);
when(appTypesConfig.getSubConfig("MyApplicationType")).thenReturn(appTypeConfig);
when(appTypeConfig.getAttributes()).thenReturn(appTypeData);
setupDataStructures();
}
Aggregations