Search in sources :

Example 41 with Entitlement

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

the class RestPermissionTest method createPrivilege.

private void createPrivilege() throws EntitlementException {
    PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
    Privilege privilege = Privilege.getNewInstance();
    privilege.setName(PRIVILEGE_NAME);
    privilege.setDescription("desciption");
    Map<String, Boolean> actions = new HashMap<String, Boolean>();
    actions.put("GET", true);
    Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
    privilege.setEntitlement(entitlement);
    EntitlementSubject sbj = new AuthenticatedUsers();
    privilege.setSubject(sbj);
    pm.add(privilege);
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) HashMap(java.util.HashMap) AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) DelegationPrivilege(com.sun.identity.delegation.DelegationPrivilege) Entitlement(com.sun.identity.entitlement.Entitlement)

Example 42 with Entitlement

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

the class ResourceSetService method isSharedWith.

/**
     * Checks whether a ResourceSet is accessible by a user.
     * @param resourceSet The resource set to check.
     * @param resourceUserId The id of the user to check.
     * @param realm The realm to check in.
     * @return @code{true} if the user can access that ResourceSet.
     */
public boolean isSharedWith(ResourceSetDescription resourceSet, String resourceUserId, String realm) throws InternalServerErrorException {
    Subject subject = createSubject(resourceUserId, realm);
    try {
        Evaluator evaluator = umaProviderSettingsFactory.get(realm).getPolicyEvaluator(subject, resourceSet.getClientId().toLowerCase());
        String sharedResourceName = "uma://" + resourceSet.getId();
        List<Entitlement> entitlements = evaluator.evaluate(realm, subject, sharedResourceName, null, false);
        if (!entitlements.isEmpty() && !entitlements.iterator().next().getActionValues().isEmpty()) {
            return true;
        }
    } catch (EntitlementException | NotFoundException e) {
        throw new InternalServerErrorException(e);
    }
    return false;
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) Evaluator(com.sun.identity.entitlement.Evaluator) Entitlement(com.sun.identity.entitlement.Entitlement) Subject(javax.security.auth.Subject)

Example 43 with Entitlement

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

the class AuthorizationRequestEndpointTest method createEntitlement.

private Entitlement createEntitlement(String action) {
    Entitlement entitlement = new Entitlement();
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put(action, true);
    entitlement.setActionValues(actionValues);
    return entitlement;
}
Also used : HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Entitlement(com.sun.identity.entitlement.Entitlement) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean)

Aggregations

Entitlement (com.sun.identity.entitlement.Entitlement)43 Privilege (com.sun.identity.entitlement.Privilege)19 HashMap (java.util.HashMap)19 HashSet (java.util.HashSet)19 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)14 Test (org.testng.annotations.Test)14 Subject (javax.security.auth.Subject)13 EntitlementException (com.sun.identity.entitlement.EntitlementException)12 Evaluator (com.sun.identity.entitlement.Evaluator)9 Set (java.util.Set)9 JsonValue (org.forgerock.json.JsonValue)9 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)8 SSOToken (com.iplanet.sso.SSOToken)7 OrSubject (com.sun.identity.entitlement.OrSubject)6 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)6 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)6 SSOException (com.iplanet.sso.SSOException)5 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)5 OpenSSOUserSubject (com.sun.identity.entitlement.opensso.OpenSSOUserSubject)5 AuthenticatedUsers (org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers)5