KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > security > UserGroupRef


1 /* ************************************************************************** *
2  * Copyright (C) 2004 NightLabs GmbH, Marco Schulze *
3  * All rights reserved. *
4  * http://www.NightLabs.de *
5  * *
6  * This program and the accompanying materials are free software; you can re- *
7  * distribute it and/or modify it under the terms of the GNU General Public *
8  * License as published by the Free Software Foundation; either ver 2 of the *
9  * License, or any later version. *
10  * *
11  * This module is distributed in the hope that it will be useful, but WITHOUT *
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FIT- *
13  * NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more *
14  * details. *
15  * *
16  * You should have received a copy of the GNU General Public License along *
17  * with this module; if not, write to the Free Software Foundation, Inc.: *
18  * 59 Temple Place, Suite 330 *
19  * Boston MA 02111-1307 *
20  * USA *
21  * *
22  * Or get it online: *
23  * http://www.opensource.org/licenses/gpl-license.php *
24  * *
25  * In case, you want to use this module or parts of it in a proprietary pro- *
26  * ject, you can purchase it under the NightLabs Commercial License. Please *
27  * contact NightLabs GmbH under info AT nightlabs DOT com for more infos or *
28  * visit http://www.NightLabs.com *
29  * ************************************************************************** */

30
31 /*
32  * Created on 03.07.2004
33  */

34 package com.nightlabs.ipanema.security;
35
36 import java.util.Iterator JavaDoc;
37
38 /**
39  * @author marco
40  *
41  * @jdo.persistence-capable
42  * identity-type = "application"
43  * persistence-capable-superclass = "com.nightlabs.ipanema.security.UserRef"
44  * detachable = "true"
45  *
46  * @jdo.inheritance strategy = "new-table"
47  */

48 public class UserGroupRef extends UserRef
49 {
50
51     public UserGroupRef() { }
52     /**
53      * @param _authority
54      * @param _user
55      * @param _visible
56      */

57     public UserGroupRef(Authority _authority, User _user, boolean _visible)
58     {
59         super(_authority, _user, _visible);
60         if (!(_user instanceof UserGroup))
61             throw new IllegalArgumentException JavaDoc("user must be an instance of UserGroup!");
62     }
63
64     /**
65      * @see com.nightlabs.ipanema.security.UserRef#_addRole(com.nightlabs.ipanema.security.Role, int)
66      */

67     protected void _addRole(Role role, int incRefCount)
68     {
69         super._addRole(role, incRefCount);
70
71         // Why do I get a class cast exception in the following line? Maybe a jpox bug?
72
UserGroup userGroup = (UserGroup)getUser();
73
74         // We need to add this role to all UserRefs belonging to the Users of this group.
75
for (Iterator JavaDoc itUsers = userGroup.getUsers().iterator(); itUsers.hasNext(); ) {
76             User user = (User)itUsers.next();
77             UserRef userRef = user.getUserRef(getAuthorityID());
78             if (userRef == null)
79                 LOGGER.warn("User \""+user.getUserID()+"\" is member of UserGroup \""+getUserID()+"\", which has a UserGroupRef in authority \""+getAuthorityID()+"\", but there is no UserRef for this User in this Authority!", new IllegalStateException JavaDoc("Missing UserRef!"));
80             else
81                 userRef._addRole(role, incRefCount);
82         }
83     }
84
85     /**
86      * @see com.nightlabs.ipanema.security.UserRef#_removeRole(com.nightlabs.ipanema.security.Role, int)
87      */

88     protected void _removeRole(Role role, int decRefCount)
89     {
90         UserGroup userGroup = (UserGroup)getUser();
91         
92         // We need to remove this role from all UserRefs belonging to the Users of this group.
93
for (Iterator JavaDoc itUsers = userGroup.getUsers().iterator(); itUsers.hasNext(); ) {
94             User user = (User)itUsers.next();
95             UserRef userRef = user.getUserRef(getAuthorityID());
96             if (userRef == null)
97                 LOGGER.warn("User \""+user.getUserID()+"\" is member of UserGroup \""+getUserID()+"\", which has a UserGroupRef in authority \""+getAuthorityID()+"\", but there is no UserRef for this User in this Authority!", new IllegalStateException JavaDoc("Missing UserRef!"));
98             else
99                 userRef._removeRole(role, decRefCount);
100         }
101         
102         super._removeRole(role, decRefCount);
103     }
104
105 }
106
Popular Tags