Search in sources :

Example 16 with ApplicationType

use of com.sun.identity.entitlement.ApplicationType in project OpenAM by OpenRock.

the class UmaPolicyApplicationListener method createApplication.

private void createApplication(String realm, String resourceServerId) {
    Subject adminSubject = SubjectUtils.createSuperAdminSubject();
    try {
        Application application = applicationManager.getApplication(adminSubject, realm, resourceServerId);
        if (application == null) {
            ApplicationType applicationType = applicationTypeManagerWrapper.getApplicationType(adminSubject, UmaConstants.UMA_POLICY_APPLICATION_TYPE);
            application = new Application(resourceServerId, applicationType);
            application.setEntitlementCombiner(DenyOverride.class);
            applicationManager.saveApplication(adminSubject, realm, application);
        }
    } catch (EntitlementException e) {
        logger.error("Failed to create policy application", e);
    }
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) EntitlementException(com.sun.identity.entitlement.EntitlementException) Application(com.sun.identity.entitlement.Application) Subject(javax.security.auth.Subject)

Example 17 with ApplicationType

use of com.sun.identity.entitlement.ApplicationType in project OpenAM by OpenRock.

the class UpgradeEntitlementSubConfigsStep method addMissingApplications.

/**
     * Adds missing applications.
     *
     * @throws UpgradeException
     *         should the processing of creating new applications fail
     */
private void addMissingApplications() throws UpgradeException {
    for (final Node applicationNode : missingApps) {
        final Map<String, Set<String>> keyValueMap = parseAttributeValuePairTags(applicationNode);
        final String name = getNodeAttributeValue(applicationNode, NAME);
        UpgradeProgress.reportStart(AUDIT_NEW_APPLICATION_START, name);
        keyValueMap.put(NAME, Collections.singleton(name));
        final String typeName = retrieveSingleValue(APPLICATION_TYPE, keyValueMap);
        final ApplicationType applicationType = getType(typeName);
        if (applicationType == null) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException("Unknown requested application type " + typeName);
        }
        try {
            DEBUG.message("Saving new entitlement application: " + name);
            entitlementService.storeApplication(createApplication(applicationType, name, keyValueMap));
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_SUCCESS);
        } catch (EntitlementException eE) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(eE);
        } catch (InstantiationException ie) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(ie);
        } catch (IllegalAccessException iae) {
            UpgradeProgress.reportEnd(AUDIT_UPGRADE_FAIL);
            throw new UpgradeException(iae);
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) ApplicationType(com.sun.identity.entitlement.ApplicationType) EntitlementException(com.sun.identity.entitlement.EntitlementException) HashSet(java.util.HashSet) Set(java.util.Set) Node(org.w3c.dom.Node)

Example 18 with ApplicationType

use of com.sun.identity.entitlement.ApplicationType in project OpenAM by OpenRock.

the class UpgradeEntitlementSubConfigsStep method initialize.

@Override
public void initialize() throws UpgradeException {
    DEBUG.message("Initialising the upgrade entitlement sub-config step");
    final Set<ApplicationType> existingApplicationTypes = entitlementService.getApplicationTypes();
    final Set<String> existingResourceTypeUUIDs = getResourceTypeUUIDs(ROOT_REALM);
    final Set<String> presentTypes = extract(existingApplicationTypes, new TypeNameExtractor());
    final Set<String> presentApps = extract(entitlementService.getApplications(), new AppNameExtractor());
    final Document entitlementDoc = getEntitlementXML();
    final NodeList subConfigs = entitlementDoc.getElementsByTagName(SMSUtils.SUB_CONFIG);
    for (int idx = 0; idx < subConfigs.getLength(); idx++) {
        final Node subConfig = subConfigs.item(idx);
        final String id = getNodeAttributeValue(subConfig, ID);
        final String name = getNodeAttributeValue(subConfig, NAME);
        if (APPLICATION_TYPE.equals(id)) {
            captureMissingEntry(name, subConfig, presentTypes, missingApplicationTypes);
            captureMissingActions(name, subConfig);
        } else if (APPLICATION.equals(id)) {
            captureMissingEntry(name, subConfig, presentApps, missingApps);
            //app will be null if application needs to be created (see missing entries)
            final Application app = getApplication(name);
            final Map<String, Set<String>> subConfigAttrs = parseAttributeValuePairTags(subConfig);
            captureDifferentSet(app == null ? null : app.getSubjects(), getSubjects(subConfigAttrs), changedSubjects, name);
            captureDifferentSet(app == null ? null : app.getConditions(), getConditions(subConfigAttrs), changedConditions, name);
            captureDifferentSet(app == null ? null : app.getResourceTypeUuids(), EntitlementUtils.getResourceTypeUUIDs(subConfigAttrs), changedResourceTypeUUIDs, name);
            Set<String> configDescriptionSet = getDescription(subConfigAttrs);
            String configDescription = null;
            if (configDescriptionSet != null && !configDescriptionSet.isEmpty()) {
                configDescription = configDescriptionSet.iterator().next();
            }
            captureDifferentString(app == null ? null : app.getDescription(), configDescription, changedDescriptions, name);
            final EntitlementCombiner combiner = (app == null ? null : app.getEntitlementCombiner());
            captureDifferentEntitlementCombiner(combiner == null ? null : combiner.getName(), getCombiner(subConfigAttrs), name);
        } else if (RESOURCE_TYPE.equals(id)) {
            // note that the name variable actually holds the UUID of the ResourceType
            // the name is buried in the config.
            //
            captureMissingEntry(name, subConfig, existingResourceTypeUUIDs, missingResourceTypes);
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) ApplicationType(com.sun.identity.entitlement.ApplicationType) Application(com.sun.identity.entitlement.Application) HashMap(java.util.HashMap) Map(java.util.Map) EntitlementUtils.resourceTypeFromMap(org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap) EntitlementCombiner(com.sun.identity.entitlement.EntitlementCombiner) DenyOverride(com.sun.identity.entitlement.DenyOverride)

Example 19 with ApplicationType

use of com.sun.identity.entitlement.ApplicationType in project OpenAM by OpenRock.

the class UpgradeEntitlementSubConfigsStepTest method modifiedApplicationType.

@Test
public void modifiedApplicationType() throws Exception {
    //application type type4 does not have the UPDATE action, so it needs to be upgraded
    ApplicationType type = newType("type4");
    type.getActions().remove("UPDATE");
    mockTypes.add(type);
    mockApplications.add(app);
    when(entitlementService.getApplicationTypes()).thenReturn(mockTypes);
    when(entitlementService.getApplications()).thenReturn(mockApplications);
    upgradeStep.initialize();
    assertThat(upgradeStep.isApplicable()).isTrue();
    upgradeStep.perform();
    verify(entitlementService, atMost(3)).getApplicationTypes();
    verify(entitlementService, atMost(5)).getApplications();
    verify(entitlementService).storeApplicationType(argThat(new TypeMatch()));
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) Test(org.testng.annotations.Test)

Example 20 with ApplicationType

use of com.sun.identity.entitlement.ApplicationType in project OpenAM by OpenRock.

the class UpgradeEntitlementSubConfigsStepTest method setUp.

@BeforeMethod
public void setUp() throws IllegalAccessException, InstantiationException {
    mockTypes = new HashSet<ApplicationType>(3);
    final ApplicationType type1 = newType("type1");
    final ApplicationType type2 = newType("type2");
    final ApplicationType type3 = newType("type3");
    mockTypes.addAll(Arrays.asList(type1, type2, type3));
    this.type1 = type1;
    mockApplications = new HashSet<Application>(3);
    final Application application1 = newApplication("application1", type1);
    final Application application2 = newApplication("application2", type1);
    final Application application3 = newApplication("application3", type1);
    mockApplications.addAll(Arrays.asList(application1, application2, application3));
    entitlementService = mock(EntitlementConfiguration.class);
    adminTokenAction = mock(PrivilegedAction.class);
    connectionFactory = mock(ConnectionFactory.class);
    resourceTypeConfiguration = mock(ResourceTypeConfiguration.class);
    upgradeStep = new SafeUpgradeEntitlementSubConfigsStep(entitlementService, resourceTypeConfiguration, adminTokenAction, connectionFactory);
    final HashSet<String> conditions = new HashSet<String>();
    conditions.add("condition.entry.1");
    conditions.add("condition.entry.2");
    final HashSet<String> subjects = new HashSet<String>();
    subjects.add("subject.entry.1");
    subjects.add("subject.entry.2");
    final HashSet<String> resources = new HashSet<String>();
    resources.add("http://*");
    resources.add("https://*");
    app = newApplication("application4", type1);
    app.setConditions(conditions);
    app.setSubjects(subjects);
    app.setEntitlementCombinerName(DEFAULT_COMBINER);
}
Also used : ApplicationType(com.sun.identity.entitlement.ApplicationType) ConnectionFactory(org.forgerock.openam.sm.datalayer.api.ConnectionFactory) PrivilegedAction(java.security.PrivilegedAction) EntitlementConfiguration(com.sun.identity.entitlement.EntitlementConfiguration) ResourceTypeConfiguration(org.forgerock.openam.entitlement.configuration.ResourceTypeConfiguration) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ApplicationType (com.sun.identity.entitlement.ApplicationType)20 EntitlementException (com.sun.identity.entitlement.EntitlementException)6 Set (java.util.Set)6 Application (com.sun.identity.entitlement.Application)5 HashSet (java.util.HashSet)5 Subject (javax.security.auth.Subject)5 CLIException (com.sun.identity.cli.CLIException)3 List (java.util.List)3 ResourceResponse (org.forgerock.json.resource.ResourceResponse)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)2 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)2 ApplicationTypeWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeWrapper)2 EntitlementUtils.resourceTypeFromMap (org.forgerock.openam.entitlement.utils.EntitlementUtils.resourceTypeFromMap)2 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)2 Test (org.testng.annotations.Test)2 Node (org.w3c.dom.Node)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1