OrConditionEvalTest.java revision 94bba0f00a89bd3995d00513446d4849ecc79858
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * Copyright (c) 2009 Sun Microsystems Inc. All Rights Reserved
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * The contents of this file are subject to the terms
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * of the Common Development and Distribution License
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * (the License). You may not use this file except in
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * compliance with the License.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * You can obtain a copy of the License at
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * See the License for the specific language governing
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * permission and limitations under the License.
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * When distributing Covered Code, include this CDDL
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * Header Notice in each file and include the License file
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * If applicable, add the following below the CDDL Header,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * with the fields enclosed by brackets [] replaced by
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * your own identifying information:
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster * $Id: OrConditionEvalTest.java,v 1.1 2009/09/05 00:24:03 veiming Exp $
d1b57e78cf72f41c7c6a52bd7c2a6d6aa4da6ba4Craig McDonnell * Portions Copyrighted 2014 ForgeRock AS
6909255a1970175507277a0f2f105979625f76b2Jaco Jooste * Portions copyright 2014 ForgeRock AS.
869a36e2649ae064c98063cf1e55198488d78d12Allan Fosterimport com.sun.identity.entitlement.opensso.SubjectUtils;
869a36e2649ae064c98063cf1e55198488d78d12Allan Fosterimport com.sun.identity.security.AdminTokenAction;
6466ccf2fa7622ea05ba8cd089a224c8fc710f9aCraig McDonnellimport org.forgerock.openam.entitlement.conditions.environment.IPv4Condition;
6909255a1970175507277a0f2f105979625f76b2Jaco Joosteimport static org.forgerock.openam.entitlement.conditions.environment.ConditionConstants.REQUEST_IP;
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private static final String PRIVILEGE_NAME = "OrConditionEvalTest";
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private static final String ROOT_RESOURCE_NAME =
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private static final String START_IP = "100.100.100.100";
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private static final String END_IP = "200.200.200.200";
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private static final String DNS_MASK = "*.OrConditionEvalTest.com";
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private SSOToken adminToken = (SSOToken) AccessController.doPrivileged(
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private Subject adminSubject = SubjectUtils.createSubject(adminToken);
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster private boolean migrated = EntitlementConfiguration.getInstance(
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster adminSubject, "/").migratedToEntitlementService();
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Map<String, Boolean> actions = new HashMap<String, Boolean>();
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster ApplicationTypeManager.URL_APPLICATION_TYPE_NAME,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Privilege privilege = Privilege.getNewInstance();
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster PrivilegeManager pm = PrivilegeManager.getInstance("/",
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster public void clean() throws EntitlementException {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster PrivilegeManager pm = PrivilegeManager.getInstance("/",
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Map<String, Set<String>> environment = getEnvironment(
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "100.100.100.200", "www.OrConditionEvalTest.com");
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Evaluator evaluator = new Evaluator(adminSubject,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster ApplicationTypeManager.URL_APPLICATION_TYPE_NAME);
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster List<Entitlement> entitlements = evaluator.evaluate("/", adminSubject,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster ROOT_RESOURCE_NAME + "/index.html", environment, false);
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster if ((entitlements == null) || entitlements.isEmpty()) {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.positiveTest: no entitlements returned");
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.positiveTest: incorrect decision");
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Map<String, Set<String>> advice = ent.getAdvices();
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.positiveTest: do not expect advices.");
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Map<String, Set<String>> environment = getEnvironment(
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "210.100.100.200", "www.OrConditionEvalTest1.com");
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Evaluator evaluator = new Evaluator(adminSubject,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster ApplicationTypeManager.URL_APPLICATION_TYPE_NAME);
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster List<Entitlement> entitlements = evaluator.evaluate("/", adminSubject,
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster ROOT_RESOURCE_NAME + "/index.html", environment, false);
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster if ((entitlements == null) || entitlements.isEmpty()) {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.negativeTest: no entitlements returned");
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.negativeTest: incorrect decision");
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster Map<String, Set<String>> advices = ent.getAdvices();
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.negativeTest: no advices.");
6466ccf2fa7622ea05ba8cd089a224c8fc710f9aCraig McDonnell Set<String> ipAdvice = advices.get(IPv4Condition.class.getName());
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster if ((ipAdvice == null) || ipAdvice.isEmpty()) {
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.negativeTest: no advice for IPCondition.");
6909255a1970175507277a0f2f105979625f76b2Jaco Jooste if (!adv.equals(REQUEST_IP + "=" + START_IP + "-" + END_IP)
869a36e2649ae064c98063cf1e55198488d78d12Allan Foster "OrConditionEvalTest.negativeTest: incorrect decision for IPCondition");