KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > security > Role


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Role.java
20  *
21  * The role object that contains the list principals. If a user or object has
22  * a principal that matches, than access will be granted to run as that role.
23  */

24
25 // the package name
26
package com.rift.coad.lib.security;
27
28
29 // java imports
30
import java.util.Set JavaDoc;
31 import java.util.Iterator JavaDoc;
32
33 // log 4 j imports
34
import org.apache.log4j.Logger;
35
36
37 /**
38  * The role object that contains the list principals. If a user or object has
39  * a principal that matches, than access will be granted to run as that role.
40  *
41  * @author Brett Chaldecott
42  */

43 public class Role implements PrincipalContainer {
44     // log
45
private static Logger log =
46         Logger.getLogger(Role.class.getName());
47     
48     // the classes private member variables
49
private String JavaDoc name = null;
50     private Set JavaDoc principals = null;
51     
52     
53     /**
54      * Creates a new instance of a role using the supplied principal list
55      *
56      * @param name The name of the role.
57      * @param principals The list of principals assigned to this role.
58      */

59     public Role(String JavaDoc name, Set JavaDoc principals) {
60         this.name = name;
61         this.principals = principals;
62     }
63     
64     
65     /**
66      * The getter method for the name of this role.
67      *
68      * @return The string containing the name of this role.
69      */

70     public String JavaDoc getName() {
71         return name;
72     }
73     
74     
75     /**
76      * This method returns the list of principals.
77      *
78      * @return The list of principals.
79      */

80     public Set JavaDoc getPrincipals() {
81         return principals;
82     }
83     
84     
85     /**
86      * This method will return true if one of the principals match
87      *
88      * @return TRUE if one of the principals in sets match.
89      * @param queryPrincipals The set of principals that will be used to query
90      * this role.
91      */

92     public boolean canAccessRole(Set JavaDoc queryPrincipals) {
93         for (Iterator JavaDoc iter = queryPrincipals.iterator(); iter.hasNext();){
94             String JavaDoc principal = (String JavaDoc)iter.next();
95             if (principals.contains(principal)) {
96                 return true;
97             }
98         }
99         return false;
100     }
101 }
102
Popular Tags