Search in sources :

Example 21 with Subject

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

the class SubjectEditViewBean method getDefaultValues.

protected Set getDefaultValues() {
    Set values = null;
    try {
        CachedPolicy cachedPolicy = getCachedPolicy();
        Policy policy = cachedPolicy.getPolicy();
        String subjectName = (String) getPageSessionAttribute(SubjectOpViewBeanBase.PG_SESSION_SUBJECT_NAME);
        Subject subject = policy.getSubject(subjectName);
        values = subject.getValues();
    } catch (NameNotFoundException e) {
        debug.warning("SubjectEditViewBean.getDefaultValues", e);
    } catch (AMConsoleException e) {
        debug.warning("SubjectEditViewBean.getDefaultValues", e);
    }
    return values;
}
Also used : Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) Set(java.util.Set) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Subject(com.sun.identity.policy.interfaces.Subject)

Example 22 with Subject

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

the class SubjectAddViewBean method handleButton2Request.

/**
     * Handles create policy's subject request.
     *
     * @param event Request invocation event
     */
public void handleButton2Request(RequestInvocationEvent event) throws ModelControlException {
    boolean forwarded = false;
    submitCycle = true;
    bFilter = true;
    try {
        Subject subject = createSubject();
        if (subject != null) {
            CachedPolicy cachedPolicy = getCachedPolicy();
            Policy policy = cachedPolicy.getPolicy();
            String name = (String) propertySheetModel.getValue(SUBJECT_NAME);
            policy.addSubject(name, subject, isExclusive());
            backTrail();
            forwardToPolicyViewBean();
            forwarded = true;
        }
    } catch (NameAlreadyExistsException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (InvalidNameException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (AMConsoleException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
    } finally {
        if (!forwarded) {
            forwardTo();
        }
    }
}
Also used : Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) InvalidNameException(com.sun.identity.policy.InvalidNameException) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) NameAlreadyExistsException(com.sun.identity.policy.NameAlreadyExistsException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Subject(com.sun.identity.policy.interfaces.Subject)

Example 23 with Subject

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

the class DelegationPolicyImpl method privilegeToPolicy.

/** 
     * Converts a delegation privilege to a policy.
     * @param pm PolicyManager object to be used to create the <code>Policy
     *         </code> object.
     * @param priv <code>DelegationPrivilege</code> which needs to be
               converted.
     * @return policy object.
     */
private Policy privilegeToPolicy(PolicyManager pm, DelegationPrivilege priv, String orgName) throws DelegationException {
    try {
        /* the name of the policy is in the form of 
             * orgName^^privilegeName, the privilegeName is the
             * name of the delegation privilege that the policy 
             * is corresponding to. In case the orgName is in a 
             * DN format, the special char ',' is replaced to 
             * avoid saving problem.
             */
        String prefix = null;
        if (orgName != null) {
            prefix = orgName.toLowerCase() + NAME_DELIMITER;
            prefix = prefix.replace(',', REPLACEMENT_FOR_COMMA);
        } else {
            prefix = NAME_DELIMITER;
        }
        String name = prefix + priv.getName();
        Policy policy = new Policy(name);
        Set permissions = priv.getPermissions();
        if ((permissions != null) && (!permissions.isEmpty())) {
            Iterator pmit = permissions.iterator();
            int seqNum = 0;
            while (pmit.hasNext()) {
                DelegationPermission perm = (DelegationPermission) pmit.next();
                String resourceName = getResourceName(perm);
                Map actions = new HashMap();
                Set permActions = perm.getActions();
                if (permActions != null) {
                    Set values = new HashSet();
                    values.add(ACTION_ALLOW);
                    Iterator it = permActions.iterator();
                    while (it.hasNext()) {
                        String actionName = (String) it.next();
                        actions.put(actionName, values);
                    }
                }
                String ruleName = DELEGATION_RULE;
                if (seqNum != 0) {
                    ruleName += seqNum;
                }
                Rule rule = new Rule(ruleName, DelegationManager.DELEGATION_SERVICE, resourceName, actions);
                policy.addRule(rule);
                seqNum++;
            }
        }
        Set sv = new HashSet(priv.getSubjects());
        if ((sv != null) && (sv.contains(AUTHN_USERS_ID))) {
            Subject allauthNUsers = pm.getSubjectTypeManager().getSubject(AUTHENTICATED_USERS_SUBJECT);
            policy.addSubject(DELEGATION_AUTHN_USERS, allauthNUsers);
            sv.remove(AUTHN_USERS_ID);
        }
        if ((sv != null) && (!sv.isEmpty())) {
            Subject subject = pm.getSubjectTypeManager().getSubject(POLICY_SUBJECT);
            subject.setValues(sv);
            policy.addSubject(DELEGATION_SUBJECT, subject);
        }
        return policy;
    } catch (Exception e) {
        DelegationManager.debug.error("unable to convert a privilege to a policy", e);
        throw new DelegationException(e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) DelegationException(com.sun.identity.delegation.DelegationException) DelegationPermission(com.sun.identity.delegation.DelegationPermission) Subject(com.sun.identity.policy.interfaces.Subject) DelegationException(com.sun.identity.delegation.DelegationException) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException) IdRepoException(com.sun.identity.idm.IdRepoException) Iterator(java.util.Iterator) Rule(com.sun.identity.policy.Rule) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 24 with Subject

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

the class PolicySubject method evaluate.

/**
     * Returns subject decision.
     *
     * @param realm Realm name.
     * @param mgr Subject attribute manager
     * @param subject Subject to be evaluated.
     * @param resourceName Resource name to be evaluated.
     * @param environment Environment map.
     * @return subject decision.
     * @throws com.sun.identity.entitlement.EntitlementException if error
     *         occurs.
     */
public SubjectDecision evaluate(String realm, SubjectAttributesManager mgr, javax.security.auth.Subject subject, String resourceName, Map<String, Set<String>> environment) throws EntitlementException {
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    try {
        PolicyManager pm = new PolicyManager(adminToken, realm);
        Subject sbj = getPolicySubject();
        sbj.initialize(pm.getPolicyConfig());
        SSOToken token = getSSOToken(subject);
        boolean result = (token == null) ? true : sbj.isMember(token) ^ exclusive;
        return new SubjectDecision(result, Collections.EMPTY_MAP);
    } catch (SSOException ex) {
        throw new EntitlementException(508, ex);
    } catch (PolicyException ex) {
        throw new EntitlementException(508, ex);
    }
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOToken(com.iplanet.sso.SSOToken) SubjectDecision(com.sun.identity.entitlement.SubjectDecision) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Subject(com.sun.identity.policy.interfaces.Subject)

Example 25 with Subject

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

the class UpgradeUtils method createPolicyAdminPolicy.

/**
     * Creates Policy Admin Policy.
     *
     * @param policyManager the policy manager object.
     * @param orgDN the organization dn.
     * @param orgID the organization identifier.
     */
private static void createPolicyAdminPolicy(PolicyManager policyManager, String orgDN, String orgID) {
    String classMethod = "UpgradeUtils:createRealmReadOnlyPolicy";
    try {
        String policyName = orgID + "^^PolicyAdmin";
        Policy realmPolicy = new Policy(policyName, null, false, true);
        // create Rule
        String resourceName = "sms://*" + orgDN + "/" + POLICY_SERVICE;
        Rule rule = getRule(DELEGATION_SERVICE, resourceName);
        if (rule != null) {
            realmPolicy.addRule(rule);
        }
        // add subjects
        String policyAdminRoleUniversalID = getUniversalID(orgDN, ORG_POLICY_ADMIN_ROLE);
        Subject subject = getSubject(policyManager, policyAdminRoleUniversalID);
        if (subject != null) {
            realmPolicy.addSubject(DELEGATION_SUBJECT, subject, false);
        }
        policyManager.addPolicy(realmPolicy);
    } catch (Exception e) {
        debug.error(classMethod + "Error creating policy admin policy", e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) ByteString(org.forgerock.opendj.ldap.ByteString) Rule(com.sun.identity.policy.Rule) Subject(com.sun.identity.policy.interfaces.Subject) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException)

Aggregations

Subject (com.sun.identity.policy.interfaces.Subject)47 HashSet (java.util.HashSet)18 PolicyException (com.sun.identity.policy.PolicyException)17 SSOException (com.iplanet.sso.SSOException)14 Policy (com.sun.identity.policy.Policy)14 Set (java.util.Set)12 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)11 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)11 SubjectTypeManager (com.sun.identity.policy.SubjectTypeManager)11 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)8 Rule (com.sun.identity.policy.Rule)8 Iterator (java.util.Iterator)8 PolicyManager (com.sun.identity.policy.PolicyManager)7 CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)6 AMException (com.iplanet.am.sdk.AMException)5 InvalidAuthContextException (com.sun.identity.authentication.internal.InvalidAuthContextException)5 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)5 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)5 SMSException (com.sun.identity.sm.SMSException)5 FileNotFoundException (java.io.FileNotFoundException)5