Search in sources :

Example 26 with Subject

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

the class PolicyModelImpl method createSubject.

/**
     * Returns a subject object.
     *
     * @param realmName Name of Realm.
     * @param subjectType Name of subject type.
     * @param values Values of the subject.
     * @return subject object.
     * @throws AMConsoleException if subject cannot be created.
     */
public Subject createSubject(String realmName, String subjectType, Set values) throws AMConsoleException {
    Subject subject = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
            subject = subjectTypeMgr.getSubject(subjectType);
            subject.setValues(values);
        }
    } catch (NameNotFoundException e) {
        throw new AMConsoleException(getErrorString(e));
    } catch (PolicyException e) {
        throw new AMConsoleException(getErrorString(e));
    }
    return subject;
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) SubjectTypeManager(com.sun.identity.policy.SubjectTypeManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Subject(com.sun.identity.policy.interfaces.Subject)

Example 27 with Subject

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

the class PolicyModelImpl method getActiveSubjectTypes.

/**
     * Returns a map of active subject types for a realm to its display name.
     *
     * @param realmName Name of Realm.
     * @return a map of active subject types for a realm to its display name.
     */
public QueryResults getActiveSubjectTypes(String realmName) {
    Map subjectTypes = Collections.EMPTY_MAP;
    String strError = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
            if (subjectTypeMgr != null) {
                Set types = subjectTypeMgr.getSelectedSubjectTypeNames();
                subjectTypes = new HashMap(types.size() * 2);
                for (Iterator iter = types.iterator(); iter.hasNext(); ) {
                    String rName = (String) iter.next();
                    try {
                        Subject subject = subjectTypeMgr.getSubject(rName);
                        if (subject != null) {
                            Syntax syntax = subject.getValueSyntax(getUserSSOToken());
                            if (!syntax.equals(Syntax.NONE)) {
                                subjectTypes.put(rName, subjectTypeMgr.getDisplayName(rName));
                            }
                        }
                    } catch (SSOException e) {
                        strError = getErrorString(e);
                    } catch (NameNotFoundException e) {
                        strError = getErrorString(e);
                    } catch (PolicyException e) {
                        strError = getErrorString(e);
                    }
                }
            }
        }
    } catch (AMConsoleException e) {
        debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
    } catch (SSOException e) {
        debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
    } catch (NameNotFoundException e) {
        debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
    } catch (PolicyException e) {
        debug.error("PolicyModelImpl.getActiveSubjectTypes", e);
    }
    return new QueryResults(subjectTypes, strError);
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) SSOException(com.iplanet.sso.SSOException) Subject(com.sun.identity.policy.interfaces.Subject) QueryResults(com.sun.identity.console.base.model.QueryResults) SubjectTypeManager(com.sun.identity.policy.SubjectTypeManager) PolicyException(com.sun.identity.policy.PolicyException) Iterator(java.util.Iterator) Syntax(com.sun.identity.policy.Syntax) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 28 with Subject

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

the class PolicyModelImpl method getSubjectViewBeanURL.

/**
     * Returns properties view bean URL of a subject.
     *
     * @param realmName Name of realm.
     * @param subjectTypeName Name of Subject Type.
     * @return properties view bean URL of a subject.
     */
public String getSubjectViewBeanURL(String realmName, String subjectTypeName) {
    String url = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
            Subject subject = subjectTypeMgr.getSubject(subjectTypeName);
            url = subjectTypeMgr.getViewBeanURL(subject);
        }
    } catch (AMConsoleException e) {
        debug.warning("PolicyModelImpl.getSubjectViewBeanURL", e);
    } catch (NameNotFoundException e) {
        debug.warning("PolicyModelImpl.getSubjectViewBeanURL", e);
    } catch (PolicyException e) {
        debug.warning("PolicyModelImpl.getSubjectViewBeanURL", e);
    }
    return url;
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) SubjectTypeManager(com.sun.identity.policy.SubjectTypeManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Subject(com.sun.identity.policy.interfaces.Subject)

Example 29 with Subject

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

the class SharedSubject method isMember.

/**
     * Determines if the user identified by <code>SSOToken</cdoe> 
     * is a member of this <code>Subject</code>.
     *
     * @param token single-sign-on token of the user
     *
     * @return <code>true</code> if the user is member of the
     * given subject, <code>false</code> otherwise.
     *
     * @exception SSOException if SSO token is not valid
     * @exception PolicyException if an error occurred while
     * checking if the user is a member of this subject
     */
public boolean isMember(SSOToken token) throws SSOException, PolicyException {
    boolean member = false;
    if (mstm == null) {
        String realmName = stm.getPolicyManager().getOrganizationDN();
        mstm = PolicyCache.getInstance().getPolicyManager(realmName).getSubjectTypeManager();
    }
    Subject subject = mstm.getCachedSubjectByName(subjectName);
    if (subject != null) {
        member = subject.isMember(token);
    } else {
        if (debug.warningEnabled()) {
            debug.warning("Realm subject: " + subjectName + " not found");
        }
    }
    return member;
}
Also used : Subject(com.sun.identity.policy.interfaces.Subject)

Example 30 with Subject

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

the class SubjectTypeManager method removeSubject.

/**
     * Removes the subject with the given name  from the realm.
     * This method would throw PolicyException if the subject 
     * is being used by any policy unless <code>forcedRemove</code> 
     * argument  is set to <code>true</code>. 
     * If the <code>forcedRemove</code> argument is set to 
     * <code>true</code> policies that are using the subject would 
     * be modified to  remove the references to the subject
     *
     * @param subjectName name of the Subject
     * @param forcedRemove if set to <code>true</code>, policies that
     *    use the subject would be modifed to remove the references
     *    to the subject. Otherwise, <code>ObjectInUseException</code>
     *    would be thrown if there is any policy using the subject
     *
     * @return returns the Subject object being removed,
     *         returns <code>null</code> if Subject with 
     *         the given subjectName is not present 
     *
     * @throws PolicyException if can not remove the Subject 
     */
public Subject removeSubject(String subjectName, boolean forcedRemove) throws ObjectInUseException, PolicyException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("Removing realm subject : " + subjectName + ", in realm:" + pmRealmName);
    }
    if (realmSubjects == null) {
        initRealmSubjects();
    }
    if (forcedRemove) {
        Set userPolicies = pm.getPoliciesUsingRealmSubject(subjectName);
        for (Iterator policyIter = userPolicies.iterator(); policyIter.hasNext(); ) {
            Policy policy = (Policy) policyIter.next();
            policy.removeSubject(subjectName);
        }
    } else {
        Policy p = pm.getPolicyUsingRealmSubject(subjectName);
        if (p != null) {
            //Object[] args, String name, Object user) 
            throw new ObjectInUseException(null, null, null, null, null);
        }
    }
    Subject subject = realmSubjects.removeSubject(subjectName);
    saveSubjects();
    if (debug.messageEnabled()) {
        debug.message("Removed realm subject : " + subjectName + ", in realm:" + pmRealmName);
    }
    return subject;
}
Also used : Subject(com.sun.identity.policy.interfaces.Subject)

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