use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeResourceTypeStep method createResourceType.
/**
* Create the resource type for the given application if a suitable resource type does not already exist.
* @param state The state object that contains the various parameters for creating the resource type.
* @param realm The realm in which the application and resource type resides.
* @return The resource type if it could be created or {@code null} if it could not.
* @throws UpgradeException If the application types could not be read.
*/
private ResourceType createResourceType(ResourceTypeState state, String realm) throws UpgradeException {
final Set<QueryFilter<SmsAttribute>> actionFilters = transformSet(state.actions, new Function<String, QueryFilter<SmsAttribute>, NeverThrowsException>() {
@Override
public QueryFilter<SmsAttribute> apply(String value) {
return QueryFilter.equalTo(ResourceTypeSmsAttributes.ACTIONS, value);
}
});
final Set<QueryFilter<SmsAttribute>> patternFilters = transformSet(state.patterns, new Function<String, QueryFilter<SmsAttribute>, NeverThrowsException>() {
@Override
public QueryFilter<SmsAttribute> apply(String value) {
return QueryFilter.equalTo(ResourceTypeSmsAttributes.PATTERNS, value);
}
});
final Set<ResourceType> resourceTypes;
try {
resourceTypes = resourceTypeService.getResourceTypes(QueryFilter.and(QueryFilter.and(actionFilters), QueryFilter.and(patternFilters)), getAdminSubject(), realm);
} catch (EntitlementException e) {
throw new UpgradeException("Failed to retrieve resource type for " + state.appName, e);
}
if (!resourceTypes.isEmpty()) {
// Some matching resource types have been found, return the first one.
return resourceTypes.iterator().next();
}
ResourceType resourceType = ResourceType.builder().setName(state.appName + RESOURCES_TYPE_NAME_SUFFIX).addActions(getActions(state.actions)).addPatterns(state.patterns).setDescription(RESOURCE_TYPE_DESCRIPTION + state.appName).generateUUID().build();
saveResourceType(resourceType, realm);
state.resourceTypeName = resourceType.getName();
return resourceType;
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeResourceTypeStep method getApplicationTypeData.
private Map<String, Set<String>> getApplicationTypeData(String appTypeName) throws UpgradeException {
try {
ServiceConfig config = configManager.getGlobalConfig(null).getSubConfig("applicationTypes");
if (config == null) {
throw new UpgradeException("Expected sub config applicationTypes under service " + EntitlementUtils.SERVICE_NAME);
}
config = config.getSubConfig(appTypeName);
if (config == null) {
throw new UpgradeException("Expected to find application type " + appTypeName);
}
@SuppressWarnings("unchecked") Map<String, Set<String>> attributes = config.getAttributes();
return attributes;
} catch (SSOException | SMSException e) {
throw new UpgradeException("Failed to retrieve application type data for " + appTypeName, e);
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class UpgradeResourceTypeStep method upgradeApplication.
/**
* Add the resource type UUID to the application and persist it.
* @param ec The EntitlementConfiguration for the realm in which the application resides.
* @param appName Name of the application.
* @param resourceTypeUUID The resource type associated with the application.
* @throws UpgradeException If the application failed to persist.
*/
private void upgradeApplication(EntitlementConfiguration ec, String appName, String resourceTypeUUID) throws UpgradeException {
try {
UpgradeProgress.reportStart(AUDIT_MODIFIED_APP_UUID_START, appName);
final Application application = ec.getApplication(appName);
application.addAllResourceTypeUuids(Collections.singleton(resourceTypeUUID));
ec.storeApplication(application);
UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
} catch (EntitlementException ee) {
UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
throw new UpgradeException("Failed to add resource type uuid to application " + appName, ee);
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class OldPolicyConditionMigrationUpgradeStep method addResourceType.
private void addResourceType(Privilege privilege, String realm) throws UpgradeException, EntitlementException {
Application application = privilege.getEntitlement().getApplication(getAdminSubject(), realm);
Set<String> resourceTypeUuids = application.getResourceTypeUuids();
if (CollectionUtils.isNotEmpty(resourceTypeUuids)) {
// UpgradeResourceTypeStep only creates one Resource Type for each application, so there should
// only be one resource type associated with the application at this stage
privilege.setResourceTypeUuid(application.getResourceTypeUuids().iterator().next());
} else {
DEBUG.error("Failed to modify privilege {} in realm {}! Associated application has no Resource Types.", privilege.getName(), realm);
throw new UpgradeException("Failed to modify privilege!");
}
}
use of org.forgerock.openam.upgrade.UpgradeException in project OpenAM by OpenRock.
the class PolicyConditionUpgrader method migrateEnvironmentConditions.
private void migrateEnvironmentConditions(Privilege privilege, MigrationReport migrationReport) throws UpgradeException, EntitlementException {
if (privilege.getCondition() == null) {
return;
}
if (privilege.getCondition() instanceof LogicalCondition) {
LogicalCondition logicalCondition = (LogicalCondition) privilege.getCondition();
Set<EntitlementCondition> conditions = logicalCondition.getEConditions();
Set<EntitlementCondition> migratedConditions = new HashSet<EntitlementCondition>();
for (EntitlementCondition condition : conditions) {
if (!(condition instanceof PolicyCondition)) {
//This should never happen due to check in initialise
throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
}
migratedConditions.add(migrateEnvironmentCondition((PolicyCondition) condition, migrationReport));
}
logicalCondition.setEConditions(migratedConditions);
} else if (privilege.getCondition() instanceof PolicyCondition) {
privilege.setCondition(migrateEnvironmentCondition((PolicyCondition) privilege.getCondition(), migrationReport));
} else {
//This should never happen due to check in initialise
throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
}
}
Aggregations