Search in sources :

Example 76 with UpgradeException

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);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException)

Example 77 with UpgradeException

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);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException)

Example 78 with UpgradeException

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);
            }
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) Set(java.util.Set) HashSet(java.util.HashSet) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) HashMap(java.util.HashMap) Map(java.util.Map)

Example 79 with UpgradeException

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);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException)

Example 80 with UpgradeException

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();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ResourceTypeService(org.forgerock.openam.entitlement.service.ResourceTypeService) Document(org.w3c.dom.Document) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ConnectionFactory(org.forgerock.openam.sm.datalayer.api.ConnectionFactory) PrivilegedAction(java.security.PrivilegedAction) ServiceConfig(com.sun.identity.sm.ServiceConfig) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

UpgradeException (org.forgerock.openam.upgrade.UpgradeException)81 SSOException (com.iplanet.sso.SSOException)29 HashMap (java.util.HashMap)27 SMSException (com.sun.identity.sm.SMSException)25 Set (java.util.Set)25 HashSet (java.util.HashSet)22 Map (java.util.Map)22 ServiceConfig (com.sun.identity.sm.ServiceConfig)21 EntitlementException (com.sun.identity.entitlement.EntitlementException)16 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)14 Application (com.sun.identity.entitlement.Application)10 IOException (java.io.IOException)10 PolicyManager (com.sun.identity.policy.PolicyManager)8 PolicyException (com.sun.identity.policy.PolicyException)6 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)6 EntitlementUtils.resourceTypeFromMap (org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)6 Node (org.w3c.dom.Node)5 ServiceSchema (com.sun.identity.sm.ServiceSchema)4 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)4 Properties (java.util.Properties)4