8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: PeerOrgReferral.java,v 1.3 2008/06/25 05:43:51 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.policy.plugins;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.policy.PolicyException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.policy.PolicyManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.policy.ResBundleUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.policy.ValidValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.OrganizationConfigManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/** Class to facilitate policy referrals to peer
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * organizations
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class PeerOrgReferral extends OrgReferral {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster = Debug.getInstance(PolicyManager.POLICY_DEBUG_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private final static String PEER_ORG_REFERRAL = "PeerOrgReferral";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /** No argument constructor */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public PeerOrgReferral() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**Gets the name of the ReferralType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return name of the ReferralType representing this referral
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getReferralTypeName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return PEER_ORG_REFERRAL;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Gets the valid values for this referral
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token SSOToken
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>ValidValues</code> object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception SSOException if <code>SSOToken></code> is not valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception PolicyException if unable to get the list of valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public ValidValues getValidValues(SSOToken token)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws SSOException, PolicyException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return getValidValues(token ,"*");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**Gets the valid values for this referral
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * matching a pattern
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token SSOToken
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pattern a pattern to match against the value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>ValidValues</code> object
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception SSOException if <code>SSOToken></code> is not valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception PolicyException if unable to get the list of valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public ValidValues getValidValues(SSOToken token, String pattern)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws SSOException, PolicyException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set values = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int status = ValidValues.SUCCESS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("PeerOrgReferral.getValidValues():entering");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set orgSet = (Set) _configurationMap.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PolicyManager.ORGANIZATION_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ( (orgSet == null) || (orgSet.isEmpty()) ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("PeerOrgReferral.getValidValues(): "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + " Organization name not set");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new PolicyException(ResBundleUtils.rbName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "org_name_not_set", null, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator iter = orgSet.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String orgName = (String) iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster OrganizationConfigManager orgConfigManager
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster = new OrganizationConfigManager(token, orgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String fullOrgName = orgConfigManager.getOrganizationName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("PeerOrgReferral.getValidValues():fullOrgName="
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + fullOrgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster OrganizationConfigManager parentOrgConfig
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster = orgConfigManager.getParentOrgConfigManager();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String fullParentOrgName = parentOrgConfig.getOrganizationName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set subOrgNames = parentOrgConfig.getSubOrganizationNames(pattern,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster false); //get only first level children
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ( !fullOrgName.equals(fullParentOrgName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster && (subOrgNames != null) && !subOrgNames.isEmpty()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator subOrgsIter = subOrgNames.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (subOrgsIter.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String subOrgName = (String)subOrgsIter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster OrganizationConfigManager subOrgManager =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster parentOrgConfig.getSubOrgConfigManager(subOrgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (subOrgManager != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String fullSubOrgName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster = subOrgManager.getOrganizationName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!fullOrgName.equals(fullSubOrgName)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster values.add(fullSubOrgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("PeerOrgReferral.getValidValues():returning="
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + values);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SMSException smse) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Can not get valid values for referral "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + getReferralTypeName()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + smse );
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] objs = {getReferralTypeName()};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new PolicyException(ResBundleUtils.rbName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "can_not_get_values_for_referral", objs, smse);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (new ValidValues(status, values));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster