Search in sources :

Example 56 with PolicyManager

use of com.sun.identity.policy.PolicyManager in project OpenAM by OpenRock.

the class PolicyModelImpl method createCondition.

/**
     * Returns a condition object.
     *
     * @param realmName Name of Realm.
     * @param conditionType Name of condition type.
     * @param values Values of the condition.
     * @return condition object.
     * @throws AMConsoleException if condition cannot be created.
     */
public Condition createCondition(String realmName, String conditionType, Map values) throws AMConsoleException {
    Condition condition = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ConditionTypeManager conditionTypeMgr = policyMgr.getConditionTypeManager();
            condition = conditionTypeMgr.getCondition(conditionType);
            condition.setProperties(values);
        }
    } catch (NameNotFoundException e) {
        throw new AMConsoleException(getErrorString(e));
    } catch (PolicyException e) {
        throw new AMConsoleException(getErrorString(e));
    }
    return condition;
}
Also used : Condition(com.sun.identity.policy.interfaces.Condition) PolicyManager(com.sun.identity.policy.PolicyManager) ConditionTypeManager(com.sun.identity.policy.ConditionTypeManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 57 with PolicyManager

use of com.sun.identity.policy.PolicyManager in project OpenAM by OpenRock.

the class ConfigureData method createPolicies.

private void createPolicies(String realmName, String xmlFile) throws FileNotFoundException, PolicyException, SSOException, IOException {
    PolicyManager pm = new PolicyManager(ssoToken, realmName);
    InputStreamReader fin = new InputStreamReader(AMSetupUtils.getResourceAsStream(sctx, xmlFile));
    StringBuilder sbuf = new StringBuilder();
    char[] cbuf = new char[1024];
    int len;
    while ((len = fin.read(cbuf)) > 0) {
        sbuf.append(cbuf, 0, len);
    }
    String data = ServicesDefaultValues.tagSwap(sbuf.toString(), true);
    ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes());
    PolicyUtils.createPolicies(pm, bis);
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 58 with PolicyManager

use of com.sun.identity.policy.PolicyManager in project OpenAM by OpenRock.

the class OpenSSOPolicyDataStore method createPolicy.

private Object createPolicy(SSOToken adminToken, String realm, String xml) throws Exception, SSOException, PolicyException {
    Object policy = null;
    if (xml.startsWith("xmlpolicy=")) {
        xml = xml.substring(10);
    }
    Document doc = XMLUtils.getXMLDocument(new ByteArrayInputStream(xml.getBytes("UTF8")));
    if (EntitlementConfiguration.getInstance(SubjectUtils.createSubject(adminToken), "/").xacmlPrivilegeEnabled()) {
    //TODO: create xacml policy from xml document
    } else {
        PolicyManager pm = new PolicyManager(adminToken, realm);
        Node rootNode = XMLUtils.getRootNode(doc, PolicyManager.POLICY_ROOT_NODE);
        policy = new Policy(pm, rootNode);
    }
    return policy;
}
Also used : Policy(com.sun.identity.policy.Policy) PolicyManager(com.sun.identity.policy.PolicyManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 59 with PolicyManager

use of com.sun.identity.policy.PolicyManager in project OpenAM by OpenRock.

the class PolicyPrivilegeManager method initialize.

/**
     * Initializes the object
     * @param subject subject that would be used for privilege management
     * operations
     */
@Override
public void initialize(String realm, Subject subject) {
    super.initialize(realm, subject);
    this.realm = realm;
    SSOToken ssoToken = SubjectUtils.getSSOToken(subject);
    if (!migratedToEntitlementSvc) {
        try {
            pm = new PolicyManager(ssoToken, realm);
        } catch (SSOException e) {
            PrivilegeManager.debug.error("PolicyPrivilegeManager.initialize", e);
        } catch (PolicyException e) {
            PrivilegeManager.debug.error("PolicyPrivilegeManager.initialize", e);
        }
    }
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) SSOToken(com.iplanet.sso.SSOToken) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException)

Example 60 with PolicyManager

use of com.sun.identity.policy.PolicyManager in project OpenAM by OpenRock.

the class IDPPTest method cleanup.

@AfterClass
public void cleanup() throws Exception {
    if (!migrated) {
        return;
    }
    PolicyManager policyMgr = new PolicyManager(adminToken, orgName);
    policyMgr.removePolicy("IDPPTestPolicy1");
    Set<AMIdentity> identities = new HashSet<AMIdentity>();
    identities.add(user1);
    identities.add(group1);
    IdRepoUtils.deleteIdentities(orgName, identities);
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) AMIdentity(com.sun.identity.idm.AMIdentity) HashSet(java.util.HashSet) AfterClass(org.testng.annotations.AfterClass)

Aggregations

PolicyManager (com.sun.identity.policy.PolicyManager)61 PolicyException (com.sun.identity.policy.PolicyException)40 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)33 SSOException (com.iplanet.sso.SSOException)28 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)23 HashSet (java.util.HashSet)18 Set (java.util.Set)18 Policy (com.sun.identity.policy.Policy)16 Map (java.util.Map)13 HashMap (java.util.HashMap)12 Iterator (java.util.Iterator)11 SubjectTypeManager (com.sun.identity.policy.SubjectTypeManager)10 SSOToken (com.iplanet.sso.SSOToken)8 Subject (com.sun.identity.policy.interfaces.Subject)8 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)8 ReferralTypeManager (com.sun.identity.policy.ReferralTypeManager)7 Referral (com.sun.identity.policy.interfaces.Referral)7 ConditionTypeManager (com.sun.identity.policy.ConditionTypeManager)6 ResponseProviderTypeManager (com.sun.identity.policy.ResponseProviderTypeManager)6 Condition (com.sun.identity.policy.interfaces.Condition)5