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: AccessRightObject.java,v 1.3 2008/06/25 05:41:43 qcheng Exp $
026 *
027 */
028
029package com.iplanet.ums;
030
031import java.util.Collection;
032import java.util.HashSet;
033import java.util.Iterator;
034
035/**
036 * Represents the attribute access rights associated with a user or role.
037 * 
038 * @supported.api
039 */
040public class AccessRightObject {
041    // readable attributes
042    private HashSet readables = new HashSet();
043
044    // writable attributes
045    private HashSet writables = new HashSet();
046
047    /**
048     * Default constructor
049     *
050     * @supported.api
051     */
052    public AccessRightObject() {
053    }
054
055    /**
056     * This constructor establishes collections of readable attribute names and
057     * writeable attribute names.
058     * 
059     * @param readableAttributeNames
060     *            Collection of readable attribute names
061     * @param writableAttributeNames
062     *            Collection of writable attribute names
063     *           
064     *
065     * @supported.api
066     */
067    public AccessRightObject(Collection readableAttributeNames,
068            Collection writableAttributeNames) {
069        // need to convert all attribute names to lower case
070        if (readableAttributeNames != null) {
071            Iterator it = readableAttributeNames.iterator();
072            while (it.hasNext()) {
073                String temp = (String) it.next();
074                readables.add(temp.toLowerCase());
075            }
076        }
077        if (writableAttributeNames != null) {
078            Iterator it = writableAttributeNames.iterator();
079            while (it.hasNext()) {
080                String temp = (String) it.next();
081                writables.add(temp.toLowerCase());
082            }
083        }
084    }
085
086    /**
087     * Grant read permission to attributes.
088     * 
089     * @param attributeNames
090     *            A collection of attribute names to which read permission will
091     *            be granted.
092     * 
093     * @supported.api
094     */
095    public void grantReadPermission(Collection attributeNames) {
096        // need to convert all attribute names to lower case
097        Iterator it = attributeNames.iterator();
098        if (it != null) {
099            while (it.hasNext()) {
100                String temp = (String) it.next();
101                readables.add(temp.toLowerCase());
102            }
103        }
104    }
105
106    /**
107     * Grant write permission to attributes.
108     * 
109     * @param attributeNames
110     *            A collection of attribute names to which write permission will
111     *            be granted.
112     * 
113     * @supported.api
114     */
115    public void grantWritePermission(Collection attributeNames) {
116        // need to convert all attribute names to lower case
117        Iterator it = attributeNames.iterator();
118        if (it != null) {
119            while (it.hasNext()) {
120                String temp = (String) it.next();
121                writables.add(temp.toLowerCase());
122            }
123        }
124    }
125
126    /**
127     * Revoke read permission on attributes.
128     * 
129     * @param attributeNames
130     *            A collection of attribute names on which read permission will
131     *            be revoked.
132     * 
133     * @supported.api
134     */
135    public void revokeReadPermission(Collection attributeNames) {
136        // need to convert all attribute names to lower case
137        Iterator it = attributeNames.iterator();
138        if (it != null) {
139            while (it.hasNext()) {
140                String temp = (String) it.next();
141                readables.remove(temp.toLowerCase());
142            }
143        }
144    }
145
146    /**
147     * Revoke write permission on attributes.
148     * 
149     * @param attributeNames
150     *            A collection of attribute names on which write permission will
151     *            be revoked.
152     * 
153     * @supported.api
154     */
155    public void revokeWritePermission(Collection attributeNames) {
156        // need to convert all attribute names to lower case
157        Iterator it = attributeNames.iterator();
158        if (it != null) {
159            while (it.hasNext()) {
160                String temp = (String) it.next();
161                writables.remove(temp.toLowerCase());
162            }
163        }
164    }
165
166    /**
167     * Get all the readable attribute names.
168     * 
169     * @return Collection of all the readable attribute names
170     * 
171     * @supported.api
172     */
173    public Collection getReadableAttributeNames() {
174        return (Collection) readables.clone();
175    }
176
177    /**
178     * Get all the writable attribute names.
179     * 
180     * @return Collection of all the writable attribute names
181     * 
182     * @supported.api
183     */
184    public Collection getWritableAttributeNames() {
185        return (Collection) writables.clone();
186    }
187
188    /**
189     * Check if an attribute is readable.
190     * 
191     * @param attributeName
192     *            The attribute to be checked
193     * @return <code>boolean; </code> true if this attribute is readable, false
194     *         otherwise
195     * 
196     * @supported.api
197     */
198    public boolean isReadable(String attributeName) {
199        if (readables.contains(attributeName.toLowerCase()))
200            return true;
201        else
202            return false;
203    }
204
205    /**
206     * Check if an attribute is writable.
207     * 
208     * @param attributeName
209     *            The attribute to be checked.
210     * @return <code>boolean;</code> true if this attribute is writable, false
211     *         otherwise
212     * 
213     * @supported.api
214     */
215    public boolean isWritable(String attributeName) {
216        if (writables.contains(attributeName.toLowerCase()))
217            return true;
218        else
219            return false;
220    }
221}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.