Search in sources :

Example 16 with Referral

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

the class PolicyModelImpl method getReferralViewBeanURL.

/**
     * Returns properties view bean URL of a referral.
     *
     * @param realmName Name of realm.
     * @param referralTypeName Name of Referral Type.
     * @return properties view bean URL of a referral.
     */
public String getReferralViewBeanURL(String realmName, String referralTypeName) {
    String url = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ReferralTypeManager referralTypeMgr = policyMgr.getReferralTypeManager();
            Referral referral = referralTypeMgr.getReferral(referralTypeName);
            url = referralTypeMgr.getViewBeanURL(referral);
        }
    } catch (AMConsoleException e) {
        debug.warning("PolicyModelImpl.getReferralViewBeanURL", e);
    } catch (NameNotFoundException e) {
        debug.warning("PolicyModelImpl.getReferralViewBeanURL", e);
    } catch (PolicyException e) {
        debug.warning("PolicyModelImpl.getReferralViewBeanURL", e);
    }
    return url;
}
Also used : ReferralTypeManager(com.sun.identity.policy.ReferralTypeManager) PolicyManager(com.sun.identity.policy.PolicyManager) Referral(com.sun.identity.policy.interfaces.Referral) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 17 with Referral

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

the class PolicyModelImpl method getReferralSyntax.

/**
     * Returns syntax for a referral.
     *
     * @param realmName Name of Realm.
     * @param referralType Name of referral type.
     * @return syntax for a referral.
     */
public Syntax getReferralSyntax(String realmName, String referralType) {
    Syntax syntax = Syntax.NONE;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ReferralTypeManager referralTypeMgr = policyMgr.getReferralTypeManager();
            Referral referral = referralTypeMgr.getReferral(referralType);
            syntax = referral.getValueSyntax(getUserSSOToken());
        }
    } catch (SSOException e) {
        debug.warning("PolicyModelImpl.getActiveReferralTypes", e);
    } catch (NameNotFoundException e) {
        debug.warning("PolicyModelImpl.getActiveReferralTypes", e);
    } catch (PolicyException e) {
        debug.warning("PolicyModelImpl.getActiveReferralTypes", e);
    } catch (AMConsoleException e) {
        debug.warning("PolicyModelImpl.getReferralActionSchema", e);
    }
    return syntax;
}
Also used : ReferralTypeManager(com.sun.identity.policy.ReferralTypeManager) PolicyManager(com.sun.identity.policy.PolicyManager) Referral(com.sun.identity.policy.interfaces.Referral) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) SSOException(com.iplanet.sso.SSOException) Syntax(com.sun.identity.policy.Syntax) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 18 with Referral

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

the class PrivilegeUtils method referralPrivilegeToPolicy.

public static Policy referralPrivilegeToPolicy(String realm, ReferralPrivilege referralPrivilege) throws PolicyException, SSOException, EntitlementException {
    Policy policy = new Policy(referralPrivilege.getName(), referralPrivilege.getDescription(), true);
    SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    javax.security.auth.Subject adminSubject = SubjectUtils.createSubject(adminToken);
    PolicyManager pm = new PolicyManager(adminToken, realm);
    ReferralTypeManager rm = pm.getReferralTypeManager();
    policy.setCreatedBy(referralPrivilege.getCreatedBy());
    policy.setCreationDate(referralPrivilege.getCreationDate());
    policy.setLastModifiedBy(referralPrivilege.getLastModifiedBy());
    policy.setLastModifiedDate(referralPrivilege.getLastModifiedDate());
    int count = 1;
    for (String r : referralPrivilege.getRealms()) {
        Referral referral = rm.getReferral("SubOrgReferral");
        Set<String> tmp = new HashSet<String>();
        tmp.add(r);
        referral.setValues(tmp);
        policy.addReferral("referral" + count++, referral);
    }
    Map<String, Set<String>> map = referralPrivilege.getOriginalMapApplNameToResources();
    count = 1;
    String realmName = LDAPUtils.isDN(realm) ? DNMapper.orgNameToRealmName(realm) : realm;
    for (String appName : map.keySet()) {
        Set<String> res = map.get(appName);
        Application application = ApplicationManager.getApplication(PolicyConstants.SUPER_ADMIN_SUBJECT, realmName, appName);
        if (application == null) {
            Object[] params = { appName, realm };
            throw new EntitlementException(105, params);
        }
        String serviceName = application.getApplicationType().getName();
        for (String r : res) {
            Rule rule = new Rule("rule" + count++, serviceName, r, Collections.EMPTY_MAP);
            rule.setApplicationName(appName);
            policy.addRule(rule);
        }
    }
    return policy;
}
Also used : Policy(com.sun.identity.policy.Policy) ReferralTypeManager(com.sun.identity.policy.ReferralTypeManager) PolicyManager(com.sun.identity.policy.PolicyManager) SSOToken(com.iplanet.sso.SSOToken) HashSet(java.util.HashSet) Set(java.util.Set) EntitlementException(com.sun.identity.entitlement.EntitlementException) Referral(com.sun.identity.policy.interfaces.Referral) Rule(com.sun.identity.policy.Rule) Application(com.sun.identity.entitlement.Application) HashSet(java.util.HashSet)

Example 19 with Referral

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

the class PrivilegeUtils method getReferrals.

private static Set<String> getReferrals(Policy policy) throws NameNotFoundException {
    Set<String> results = new HashSet<String>();
    Set<String> names = policy.getReferralNames();
    for (String name : names) {
        Referral r = policy.getReferral(name);
        Set<String> values = r.getValues();
        for (String s : values) {
            if (LDAPUtils.isDN(s)) {
                results.add(DNMapper.orgNameToRealmName(s));
            } else {
                results.add(s);
            }
        }
    }
    return results;
}
Also used : Referral(com.sun.identity.policy.interfaces.Referral) HashSet(java.util.HashSet)

Example 20 with Referral

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

the class ResourceIndexManager method addPolicyToResourceTree.

/**
     *  Adds a policy's relevant content to the resource tree.
     *
     *  @param svtm service type manager
     *  @param token sso token
     *  @param policy the policy to be added
     *
     *  @exception PolicyException if unable to get the policy services,
     *  and will contain the exception thrown by SMS.
     *  @exception SSOException single-sign-on token invalid or expired
     */
void addPolicyToResourceTree(ServiceTypeManager svtm, SSOToken token, Policy policy) throws PolicyException, SSOException {
    Set ruleNames = policy.getRuleNames();
    Iterator iter = ruleNames.iterator();
    Set serviceNames = new HashSet();
    while (iter.hasNext()) {
        String ruleName = (String) iter.next();
        Rule rule = policy.getRule(ruleName);
        String serviceName = rule.getServiceTypeName();
        serviceNames.add(serviceName);
        ServiceType resourceType = svtm.getServiceType(serviceName);
        addIndexEntry(resourceType, rule.getResourceName(), policy.getName());
    }
    iter = serviceNames.iterator();
    while (iter.hasNext()) {
        String serviceName = (String) iter.next();
        saveResourceIndex(serviceName);
    }
    //Process Referrals
    Referrals referrals = policy.getReferrals();
    if (referrals != null) {
        Set referralNames = referrals.getReferralNames();
        if ((referralNames != null) && (!referralNames.isEmpty())) {
            Iterator referralIter = referralNames.iterator();
            while (referralIter.hasNext()) {
                String referralName = (String) referralIter.next();
                Referral referral = referrals.getReferral(referralName);
                if (referral instanceof OrgReferral) {
                    Set values = referral.getValues();
                    if ((values != null) && (!values.isEmpty())) {
                        Iterator valueIter = values.iterator();
                        while (valueIter.hasNext()) {
                            Map servicePrefixMap = new HashMap();
                            String value = (String) valueIter.next();
                            PolicyManager pm = new PolicyManager(token, value);
                            ResourceManager rm = pm.getResourceManager();
                            Set ruleNames1 = policy.getRuleNames();
                            Iterator ruleIter = ruleNames1.iterator();
                            while (ruleIter.hasNext()) {
                                String ruleName1 = (String) ruleIter.next();
                                Rule rule1 = policy.getRule(ruleName1);
                                String resourceName = rule1.getResourceName();
                                if (resourceName != null) {
                                    String service = rule1.getServiceTypeName();
                                    Set resourceNames = (Set) servicePrefixMap.get(service);
                                    if (resourceNames == null) {
                                        resourceNames = new HashSet();
                                        servicePrefixMap.put(service, resourceNames);
                                    }
                                    resourceNames.add(resourceName);
                                }
                            }
                            Iterator serviceIter = servicePrefixMap.keySet().iterator();
                            while (serviceIter.hasNext()) {
                                String service = (String) serviceIter.next();
                                Set resourceNames = (Set) servicePrefixMap.get(service);
                                rm.addResourcePrefixes(service, resourceNames);
                            }
                        }
                    //processed a referral value
                    }
                }
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Referral(com.sun.identity.policy.interfaces.Referral) OrgReferral(com.sun.identity.policy.plugins.OrgReferral) Iterator(java.util.Iterator) OrgReferral(com.sun.identity.policy.plugins.OrgReferral) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

Referral (com.sun.identity.policy.interfaces.Referral)23 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)10 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)10 Set (java.util.Set)10 OrgReferral (com.sun.identity.policy.plugins.OrgReferral)8 HashSet (java.util.HashSet)8 Iterator (java.util.Iterator)8 PolicyManager (com.sun.identity.policy.PolicyManager)7 ReferralTypeManager (com.sun.identity.policy.ReferralTypeManager)7 Policy (com.sun.identity.policy.Policy)6 PolicyException (com.sun.identity.policy.PolicyException)6 CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 SSOException (com.iplanet.sso.SSOException)4 PolicyModel (com.sun.identity.console.policy.model.PolicyModel)3 InvalidNameException (com.sun.identity.policy.InvalidNameException)2 NameAlreadyExistsException (com.sun.identity.policy.NameAlreadyExistsException)2 Syntax (com.sun.identity.policy.Syntax)2 SSOToken (com.iplanet.sso.SSOToken)1