001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: DomainComponent.java,v 1.4 2008/06/25 05:41:47 qcheng Exp $
026 *
027 */
028
029package com.iplanet.ums.dctree;
030
031import com.iplanet.services.ldap.Attr;
032import com.iplanet.services.ldap.ModSet;
033import com.iplanet.services.util.I18n;
034import com.iplanet.sso.SSOException;
035import com.iplanet.sso.SSOToken;
036import com.iplanet.sso.SSOTokenManager;
037import com.iplanet.ums.Guid;
038import com.iplanet.ums.IUMSConstants;
039import com.iplanet.ums.PersistentObject;
040import com.iplanet.ums.UMSException;
041import com.iplanet.ums.UMSObject;
042
043/**
044 * Represents a domain component in the domain componet tree. Each Domain
045 * Component object represent a node in the dctree and each dc may be associated
046 * with an organization in the customer DIT (the convergence tree as noted in
047 * the nortel specication).
048 * 
049 * @see DomainComponentTree
050 * @supported.api
051 */
052public class DomainComponent extends PersistentObject {
053
054    static final String[] dcObjectClasses = { "top", "domain", "inetDomain" };
055
056    static final String DEFAULT_NAMING_ATTR = "dc";
057
058    static final String TAG_ORG_LINK = "inetDomainBaseDN";
059
060    static final String TAG_DOMAIN_STATUS = "inetDomainStatus";
061
062    private static I18n i18n = I18n.getInstance(IUMSConstants.UMS_PKG);
063
064    /**
065     * Default constructor
066     */
067    public DomainComponent() {
068    }
069
070    /**
071     * Given a name for domain component, construct
072     * the dc object in memory
073     * 
074     * @param dcName
075     *            Domain Componet name
076     * @supported.api
077     */
078    public DomainComponent(SSOToken token, String dcName) throws UMSException {
079        setAttribute(new Attr("objectclass", dcObjectClasses));
080        setAttribute(new Attr("dc", dcName));
081        try {
082            SSOTokenManager.getInstance().validateToken(token);
083        } catch (SSOException se) {
084            throw new UMSException(i18n.getString(IUMSConstants.INVALID_TOKEN),
085                    se);
086        }
087        m_token = token;
088    }
089
090    /**
091     * Sets the mapping of a dc entry in the dctree to an
092     * organization or OrganizationalUnit entry in the convergence DIT, the
093     * directory tree hosting all the actual entries
094     * 
095     * @param org
096     *            Organization entry to be associated with the dc entry in the
097     *            dctree
098     * @supported.api
099     */
100    public void setAssociatedOrganization(PersistentObject org)
101            throws UMSException {
102        setAssociatedOrganization(org.getGuid());
103    }
104
105    /**
106     * Sets the mapping of a dc entry in the dctree to an
107     * organization or organizational unit entry in the convergence DIT, the
108     * directory tree hosting all the actual entries.
109     * 
110     * @param orgGuid Identifier for organization.
111     * @throws UMSException if mapping of dc entry cannot be set.
112     * @supported.api
113     */
114    public void setAssociatedOrganization(Guid orgGuid) throws UMSException {
115        if (orgGuid == null || orgGuid.getDn().length() == 0) {
116            throw new IllegalArgumentException();
117        }
118
119        modify(new Attr(TAG_ORG_LINK, orgGuid.getDn()), ModSet.REPLACE);
120
121        // Only save if it is already a persistent object
122        //
123        if (isPersistent()) {
124            save();
125        }
126    }
127
128    /**
129     * Get the domain mapping from this dc entry to the
130     * organization entry in the customer DIT. Return the organization object
131     * associated with thic dc entry
132     * 
133     * @return PersistentObject representing the organization entry associated
134     *         with dc entry
135     * @supported.api
136     */
137    public PersistentObject getOrganization() throws UMSException {
138
139        Guid orgGuid = getAssociatedOrganizationGuid();
140        return UMSObject.getObject(getSSOToken(), orgGuid);
141    }
142
143    /**
144     * Get the domain mapping from this dc entry. Domain
145     * mapping is in terms of DN
146     * 
147     * @return identifier for the domain mapping associated with this dc entry
148     * @supported.api
149     */
150    public Guid getAssociatedOrganizationGuid() throws UMSException {
151
152        Attr attr = getAttribute(TAG_ORG_LINK);
153
154        if (attr == null) {
155            return null;
156        }
157
158        return (new Guid(attr.getValue()));
159    }
160
161    /**
162     * Get the domain status in the dc entry
163     * 
164     * @return Domain status in the dc entry
165     * @supported.api
166     */
167    public String getDomainStatus() throws UMSException {
168        Attr attr = getAttribute(TAG_DOMAIN_STATUS);
169
170        if (attr == null) {
171            return null;
172        }
173
174        return attr.getValue();
175    }
176
177    /**
178     * Set the domain status in the dc entry
179     * 
180     * @param status
181     *            Domain status to be set
182     * @supported.api
183     */
184    public void setDomainStatus(String status) throws UMSException {
185        modify(new Attr(TAG_DOMAIN_STATUS, status), ModSet.REPLACE);
186
187        // Only save if it is already a persistent object
188        //
189        if (isPersistent()) {
190            save();
191        }
192    }
193
194    /**
195     * Get the naming attribute for the dc entry
196     * @supported.api
197     */
198    public String getNamingAttribute() {
199        return (DEFAULT_NAMING_ATTR);
200    }
201
202    /**
203     * get the SSO Token
204     * 
205     * @return SSOToken authenticated SSO token
206     */
207    SSOToken getSSOToken() {
208        return m_token;
209    }
210
211    /**
212     * set the SSO Token
213     */
214    void setSSOToken(SSOToken token) throws UMSException {
215        try {
216            SSOTokenManager.getInstance().validateToken(token);
217        } catch (SSOException se) {
218            throw new UMSException(i18n.getString(IUMSConstants.INVALID_TOKEN),
219                    se);
220        }
221        m_token = token;
222    }
223
224    private SSOToken m_token = null;
225
226}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.