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: IdType.java,v 1.9 2008/08/19 19:09:10 veiming Exp $
026 *
027 * Portions Copyrighted 2015 ForgeRock AS.
028 */
029
030package com.sun.identity.idm;
031
032import java.util.Collections;
033import java.util.Set;
034
035/**
036 * The class <code>IdType</code> defines the types of supported identities,
037 * and provides static constants for these identities. Currently defined
038 * identities are <code>IdType.USER</code>, <code>IdType.ROLE</code>,
039 * <code>IdType.GROUP</code> and <code>IdType.AGENT</code>. The usage of
040 * the respective types are defined along with their declaration.
041 *
042 * @supported.all.api
043 */
044public class IdType implements java.io.Serializable {
045    private String idType;
046
047    protected IdType(String type) {
048        idType = type;
049    }
050
051    /**
052     * Identity type of USER
053     */
054    public static final IdType USER = new IdType("user");
055
056    /**
057     * Identity type of ROLE
058     */
059    public static final IdType ROLE = new IdType("role");
060
061    /**
062     * Identity type of GROUP
063     */
064    public static final IdType GROUP = new IdType("group");
065
066    /**
067     * Identity type of AGENT
068     * Also from OpenSSO 8.0 onwards, this is the Identity type of
069     * the union of agents and those under the agent groups.
070     */
071    public static final IdType AGENT = new IdType("agent");
072
073    /**
074     * Identity type of filter role.
075     */
076    public static final IdType FILTEREDROLE = new IdType("filteredrole");
077
078    public static final IdType REALM = new IdType("realm");
079
080    /**
081     * Identity type of OpenAM agent only.
082     */
083    public static final IdType AGENTONLY = new IdType("agentonly");
084
085    /**
086     * Identity type of OpenAM agents under the OpenAM
087     * agent groups.
088     */
089    public static final IdType AGENTGROUP = new IdType("agentgroup");
090
091    public boolean equals(Object type) {
092        if (type instanceof IdType) {
093            return (((IdType) type).idType.equalsIgnoreCase(this.idType));
094        }
095        return (false);
096    }
097
098    public String toString() {
099        return ("IdType: " + idType);
100    }
101
102    /**
103     * Returns the hash code of the object
104     */
105    public int hashCode() {
106        return idType.hashCode();
107    }
108
109    /**
110     * Returns the name of this type, for example <code> user </code> for type
111     * User.
112     * 
113     * @return Name of the this type.
114     */
115    public String getName() {
116        return idType;
117    }
118
119    /**
120     * Returns a set of types of identities this type can hav as its' members.
121     * 
122     * @return Set of <code>IdType</code> which can be members of this
123     *         identity type.
124     */
125    public Set canHaveMembers() {
126        Set results = (Set) IdUtils.typesCanHaveMembers.get(getName());
127        return (results == null) ? Collections.EMPTY_SET : results;
128    }
129
130    /**
131     * Returns a set of types of identities that this type can be a member of.
132     * 
133     * @return Set of <code>IdType</code>.
134     */
135    public Set canBeMemberOf() {
136        Set results = (Set) IdUtils.typesCanBeMemberOf.get(getName());
137        return (results == null) ? Collections.EMPTY_SET : results;
138    }
139
140    /**
141     * Returns a set of types of identities that this type can add as members.
142     * 
143     * @return Set of <code>IdType</code>.
144     */
145    public Set canAddMembers() {
146        Set results = (Set) IdUtils.typesCanAddMembers.get(getName());
147        return (results == null) ? Collections.EMPTY_SET : results;
148    }
149}