Search in sources :

Example 36 with Privilege

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

the class PolicyIndexTest method storeAndRetrieve.

@Test
public void storeAndRetrieve() throws SSOException, PolicyException, EntitlementException, Exception {
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    PolicyManager pm = new PolicyManager(adminToken, "/");
    Set<String> hostIndexes = new HashSet<String>();
    Set<String> pathIndexes = new HashSet<String>();
    Set<String> parentPathIndexes = new HashSet<String>();
    hostIndexes.add("http://www.sun.com");
    pathIndexes.add("/private");
    parentPathIndexes.add("/");
    ResourceSearchIndexes indexes = new ResourceSearchIndexes(hostIndexes, pathIndexes, parentPathIndexes);
    PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(SubjectUtils.createSubject(adminToken), "/");
    for (Iterator<IPrivilege> i = pis.search("/", indexes, Collections.EMPTY_SET, false); i.hasNext(); ) {
        IPrivilege eval = i.next();
        if (!(eval instanceof Privilege)) {
            throw new Exception("incorrect deserialized policy, wrong type");
        }
        Privilege p = (Privilege) eval;
        if (!p.getEntitlement().getResourceName().equals(URL_RESOURCE)) {
            throw new Exception("incorrect deserialized policy");
        }
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) PrivilegeIndexStore(com.sun.identity.entitlement.PrivilegeIndexStore) IPrivilege(com.sun.identity.entitlement.IPrivilege) ResourceSearchIndexes(com.sun.identity.entitlement.ResourceSearchIndexes) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 37 with Privilege

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

the class XACMLPrivilegeUtils method privilegesToPolicySetInternal.

private static PolicySet privilegesToPolicySetInternal(String realm, Collection<Privilege> privileges) throws JAXBException {
    if (privileges == null) {
        return null;
    }
    Set<Policy> policies = new HashSet<Policy>();
    for (Privilege privilege : privileges) {
        Policy policy = privilegeToPolicy(privilege);
        policies.add(policy);
    }
    PolicySet policySet = policiesToPolicySetInternal(realm, policies);
    return policySet;
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) XACMLOpenSSOPrivilege(com.sun.identity.entitlement.opensso.XACMLOpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) HashSet(java.util.HashSet)

Example 38 with Privilege

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

the class ListPolicyNamesTest method createPrivilege.

private void createPrivilege(String name) throws EntitlementException {
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("GET", Boolean.TRUE);
    actionValues.put("POST", Boolean.FALSE);
    String resourceName = "http://www.listpolicynamestest.com:80";
    Entitlement entitlement = new Entitlement(APPL_NAME, resourceName, actionValues);
    entitlement.setName("ent1");
    String user = "id=demo,ou=user," + ServiceManager.getBaseDN();
    OpenSSOUserSubject usersubj = new OpenSSOUserSubject();
    usersubj.setID(user);
    Privilege priv = Privilege.getNewInstance();
    priv.setName(name);
    priv.setEntitlement(entitlement);
    priv.setSubject(usersubj);
    pm.addPrivilege(priv);
}
Also used : HashMap(java.util.HashMap) OpenSSOUserSubject(com.sun.identity.entitlement.opensso.OpenSSOUserSubject) Entitlement(com.sun.identity.entitlement.Entitlement) Privilege(com.sun.identity.entitlement.Privilege)

Example 39 with Privilege

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

the class JsonPolicyParserTest method shouldIgnoreAdvice.

@Test
public void shouldIgnoreAdvice() throws Exception {
    // Given
    Map<String, List<String>> advice = Collections.singletonMap("test", Arrays.asList("one", "two"));
    JsonValue content = buildJson(field("advice", advice));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getEntitlement().getAdvices()).isNullOrEmpty();
}
Also used : JsonValue(org.forgerock.json.JsonValue) List(java.util.List) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 40 with Privilege

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

the class JsonPolicyParserTest method shouldPrintCreationDateInIsoFormatButWithMilliseconds.

@Test
public void shouldPrintCreationDateInIsoFormatButWithMilliseconds() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    Date createdDate = new Date(123456789l);
    policy.setCreationDate(createdDate.getTime());
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("creationDate").asString()).isEqualTo(DateUtils.toUTCDateFormatWithMilliseconds(createdDate));
}
Also used : JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

Privilege (com.sun.identity.entitlement.Privilege)122 Test (org.testng.annotations.Test)76 JsonValue (org.forgerock.json.JsonValue)46 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 HashSet (java.util.HashSet)30 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)26 EntitlementException (com.sun.identity.entitlement.EntitlementException)23 IPrivilege (com.sun.identity.entitlement.IPrivilege)23 Entitlement (com.sun.identity.entitlement.Entitlement)19 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)18 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)17 HashMap (java.util.HashMap)15 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)13 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)11 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)9 SSOToken (com.iplanet.sso.SSOToken)8 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)8 Subject (javax.security.auth.Subject)8 ResourceResponse (org.forgerock.json.resource.ResourceResponse)8