Search in sources :

Example 6 with ResourceName

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

the class EntitlementService method getApplicationData.

private Map<String, Set<String>> getApplicationData(Application appl) {
    Map<String, Set<String>> map = new HashMap<String, Set<String>>();
    Set<String> setServiceID = new HashSet<String>(2);
    map.put(SMSEntry.ATTR_SERVICE_ID, setServiceID);
    setServiceID.add("application");
    Set<String> setObjectClass = new HashSet<String>(4);
    map.put(SMSEntry.ATTR_OBJECTCLASS, setObjectClass);
    setObjectClass.add(SMSEntry.OC_TOP);
    setObjectClass.add(SMSEntry.OC_SERVICE_COMP);
    Set<String> data = new HashSet<String>();
    map.put(SMSEntry.ATTR_KEYVAL, data);
    data.add(EntitlementUtils.APPLICATION_TYPE + '=' + appl.getApplicationType().getName());
    if (appl.getDescription() != null) {
        data.add(EntitlementUtils.CONFIG_DESCRIPTION + "=" + appl.getDescription());
    } else {
        data.add(EntitlementUtils.CONFIG_DESCRIPTION + "=");
    }
    data.add(CONFIG_ENTITLEMENT_COMBINER + "=" + appl.getEntitlementCombiner().getClass().getName());
    Set<String> conditions = appl.getConditions();
    if ((conditions != null) && !conditions.isEmpty()) {
        for (String c : conditions) {
            data.add(CONFIG_CONDITIONS + "=" + c);
        }
    } else {
        data.add(CONFIG_CONDITIONS + "=");
    }
    Set<String> subjects = appl.getSubjects();
    if ((subjects != null) && !subjects.isEmpty()) {
        for (String s : subjects) {
            data.add(CONFIG_SUBJECTS + "=" + s);
        }
    } else {
        data.add(CONFIG_SUBJECTS + "=");
    }
    ISaveIndex sIndex = appl.getSaveIndex();
    if (sIndex != null) {
        String saveIndexClassName = sIndex.getClass().getName();
        data.add(CONFIG_SAVE_INDEX_IMPL + "=" + saveIndexClassName);
    }
    ISearchIndex searchIndex = appl.getSearchIndex();
    if (searchIndex != null) {
        String searchIndexClassName = searchIndex.getClass().getName();
        data.add(CONFIG_SEARCH_INDEX_IMPL + "=" + searchIndexClassName);
    }
    ResourceName recComp = appl.getResourceComparator(false);
    if (recComp != null) {
        String resCompClassName = recComp.getClass().getName();
        data.add(CONFIG_RESOURCE_COMP_IMPL + "=" + resCompClassName);
    }
    Set<String> sbjAttributes = appl.getAttributeNames();
    if ((sbjAttributes != null) && !sbjAttributes.isEmpty()) {
        for (String s : sbjAttributes) {
            data.add(ATTR_NAME_SUBJECT_ATTR_NAMES + "=" + s);
        }
    } else {
        data.add(ATTR_NAME_SUBJECT_ATTR_NAMES + "=");
    }
    for (String m : appl.getMetaData()) {
        data.add(ATTR_NAME_META + "=" + m);
    }
    if (!appl.getResourceTypeUuids().isEmpty()) {
        Set<String> searchableAttributes = new HashSet<String>();
        for (String resourceTypeUuid : appl.getResourceTypeUuids()) {
            searchableAttributes.add(EntitlementUtils.CONFIG_RESOURCE_TYPE_UUIDS + "=" + resourceTypeUuid);
        }
        map.put(SMSEntry.ATTR_XML_KEYVAL, searchableAttributes);
    }
    map.put("ou", getApplicationIndices(appl));
    return map;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ISearchIndex(com.sun.identity.entitlement.interfaces.ISearchIndex) ResourceName(com.sun.identity.entitlement.interfaces.ResourceName) ISaveIndex(com.sun.identity.entitlement.interfaces.ISaveIndex) HashSet(java.util.HashSet)

Example 7 with ResourceName

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

the class ApplicationTest method shouldDeferToApplicationTypeComparator.

@Test
public void shouldDeferToApplicationTypeComparator() throws IllegalAccessException, InstantiationException {
    //given
    ApplicationType appType = new ApplicationType(null, null, null, null, null);
    ResourceName appTypeResourceName = appType.getResourceComparator();
    testApplication.setApplicationType(appType);
    //when
    ResourceName result = testApplication.getResourceComparator();
    //then
    assertEquals(appTypeResourceName, result);
}
Also used : ResourceName(com.sun.identity.entitlement.interfaces.ResourceName) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 8 with ResourceName

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

the class EntitlementService method getApplicationTypeData.

private Map<String, Set<String>> getApplicationTypeData(ApplicationType applType) {
    Map<String, Set<String>> data = new HashMap<String, Set<String>>();
    data.put(EntitlementUtils.CONFIG_ACTIONS, EntitlementUtils.getActionSet(applType.getActions()));
    ISaveIndex sIndex = applType.getSaveIndex();
    String saveIndexClassName = (sIndex != null) ? sIndex.getClass().getName() : null;
    data.put(CONFIG_SAVE_INDEX_IMPL, (saveIndexClassName == null) ? Collections.EMPTY_SET : getSet(saveIndexClassName));
    ISearchIndex searchIndex = applType.getSearchIndex();
    String searchIndexClassName = (searchIndex != null) ? searchIndex.getClass().getName() : null;
    data.put(CONFIG_SEARCH_INDEX_IMPL, (searchIndexClassName == null) ? Collections.EMPTY_SET : getSet(searchIndexClassName));
    ResourceName recComp = applType.getResourceComparator();
    String resCompClassName = (recComp != null) ? recComp.getClass().getName() : null;
    data.put(CONFIG_RESOURCE_COMP_IMPL, (resCompClassName == null) ? Collections.EMPTY_SET : getSet(resCompClassName));
    return data;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ISearchIndex(com.sun.identity.entitlement.interfaces.ISearchIndex) ResourceName(com.sun.identity.entitlement.interfaces.ResourceName) ISaveIndex(com.sun.identity.entitlement.interfaces.ISaveIndex)

Example 9 with ResourceName

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

the class ApplicationTest method shouldNotDeferToApplicationTypeComparator.

@Test
public void shouldNotDeferToApplicationTypeComparator() throws IllegalAccessException, InstantiationException {
    //given
    ApplicationType appType = new ApplicationType(null, null, null, null, null);
    Class resourceNameClass = PrefixResourceName.class;
    testApplication.setApplicationType(appType);
    testApplication.setResourceComparator(resourceNameClass);
    //when
    ResourceName result = testApplication.getResourceComparator(false);
    //then
    assertEquals(resourceNameClass, result.getClass());
}
Also used : ResourceName(com.sun.identity.entitlement.interfaces.ResourceName) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 10 with ResourceName

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

the class Entitlement method getMatchingResources.

protected Set<String> getMatchingResources(Subject adminSubject, String realm, Subject subject, String applicationName, String resourceName, boolean recursive) throws EntitlementException {
    if ((resourceNames == null) || resourceNames.isEmpty()) {
        return Collections.EMPTY_SET;
    }
    if (!this.applicationName.endsWith(applicationName)) {
        return Collections.EMPTY_SET;
    }
    ResourceName resComparator = getResourceComparator(adminSubject, realm);
    Set<String> matched = new HashSet<String>();
    Set<String> resources = (subject != null) ? tagswapResourceNames(subject, resourceNames) : resourceNames;
    for (String r : resources) {
        if (!recursive) {
            if (resComparator instanceof RegExResourceName) {
                ResourceMatch match = resComparator.compare(resourceName, r, true);
                if (match.equals(ResourceMatch.EXACT_MATCH) || match.equals(ResourceMatch.SUPER_RESOURCE_MATCH) || match.equals(ResourceMatch.WILDCARD_MATCH)) {
                    matched.add(r);
                }
            } else {
                ResourceMatch match = resComparator.compare(r, resourceName, false);
                if (match.equals(ResourceMatch.EXACT_MATCH)) {
                    matched.add(r);
                } else {
                    match = resComparator.compare(resourceName, r, true);
                    if (match.equals(ResourceMatch.WILDCARD_MATCH)) {
                        matched.add(r);
                    }
                }
            }
        } else {
            if (resComparator instanceof RegExResourceName) {
                ResourceMatch match = resComparator.compare(r, resourceName, true);
                if (!match.equals(ResourceMatch.NO_MATCH)) {
                    matched.add(r);
                }
            } else {
                ResourceMatch match = resComparator.compare(resourceName, r, true);
                if (match.equals(ResourceMatch.WILDCARD_MATCH) || match.equals(ResourceMatch.SUB_RESOURCE_MATCH)) {
                    matched.add(r);
                } else {
                    match = resComparator.compare(r, resourceName, false);
                    if (match.equals(ResourceMatch.EXACT_MATCH) || match.equals(ResourceMatch.SUPER_RESOURCE_MATCH)) {
                        matched.add(r);
                    }
                }
            }
        }
    }
    return matched;
}
Also used : ResourceName(com.sun.identity.entitlement.interfaces.ResourceName) HashSet(java.util.HashSet)

Aggregations

ResourceName (com.sun.identity.entitlement.interfaces.ResourceName)11 HashSet (java.util.HashSet)7 Set (java.util.Set)3 ISaveIndex (com.sun.identity.entitlement.interfaces.ISaveIndex)2 ISearchIndex (com.sun.identity.entitlement.interfaces.ISearchIndex)2 HashMap (java.util.HashMap)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 CLIException (com.sun.identity.cli.CLIException)1 RegExResourceName (com.sun.identity.entitlement.RegExResourceName)1 ResourceMatch (com.sun.identity.entitlement.ResourceMatch)1 Subject (javax.security.auth.Subject)1