KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > security > MantaPrincipal


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Shirley Sasson.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46
47 package org.mr.kernel.security;
48
49 import java.security.Principal JavaDoc;
50 import java.util.Map JavaDoc;
51 import java.util.HashMap JavaDoc;
52
53 /**
54  * Abstract class for a principal. Principal is an entity that may have
55  * permissions to perform secured action.
56  * Each principal has a name and a Map of proprties.
57  *
58  * @version 1.0
59  * @since Mar 23, 2006
60  * @author Shirley Sasson
61  *
62  */

63 public abstract class MantaPrincipal implements Principal JavaDoc {
64     protected String JavaDoc _name;
65     protected Map JavaDoc _properties;
66
67     /**
68      * Constructs a MantaPrincipal from the provided string input.
69      *
70      * @param name the principal name
71      */

72     public MantaPrincipal(String JavaDoc name){
73         _name = name;
74     }
75
76     /**
77      * Returns the name of the principal.
78      *
79      * @return the name of the principal
80      */

81     public String JavaDoc getName(){
82         return _name;
83     }
84
85     /**
86      * Compares the specified Object with this MantaPrincipal for equality.
87      * Returns true if the given object is also a MantaPrincipal and the two MantaPrincipal
88      * instances have the same name.
89      *
90      * @param obj - the Object to compare to
91      * @return true if the Object passed in represents the same MantaPrincipal as this one, false otherwise.
92      */

93     public boolean equals(Object JavaDoc obj){
94         if (!(obj instanceof MantaPrincipal))
95             return false;
96         MantaPrincipal other = (MantaPrincipal) obj;
97         return (_name.equals(other._name));
98     }
99
100     /**
101      * Sets a property with a given name and value.
102      *
103      * @param name the name of the property
104      * @param value the value of the property
105      */

106     public void setProperty(String JavaDoc name, Object JavaDoc value){
107         if (_properties == null)
108             _properties = new HashMap JavaDoc();
109
110         _properties.put(name, value);
111     }
112
113     /**
114      * Returns a value of a property.
115      *
116      * @param name the name of the property
117      * @return Object the value of the property, or null if the property is not found
118      */

119     public Object JavaDoc getProperty(String JavaDoc name){
120         if (_properties == null)
121             return null;
122         if (_properties.containsKey(name))
123             return _properties.get(name);
124         return null;
125     }
126
127     /**
128      * Returns the map of the proprties.
129      *
130      * @return Map map that holds the properties for thisn MantaPrincipal
131      */

132     public Map JavaDoc getProperties(){
133         return _properties;
134     }
135
136     /**
137      * Returns a string representation of this MantaPrincipal.
138      *
139      * @return a string representation of this MantaPrincipal.
140      */

141     public String JavaDoc toString(){
142         return _name;
143     }
144
145     /**
146      * Sets the map of the properties with the given map.
147      *
148      * @param proprties the properties map
149      */

150     public void setProperties(Map JavaDoc proprties){
151         _properties = proprties;
152     }
153 }
154
Popular Tags