##### Coverage Report - org.apache.turbine.services.security.torque.TorqueGroup

Classes in this File | Line Coverage | Branch Coverage | Complexity
TorqueGroup |
0% | 0/36
0% | 0/6
| 1.1666666666666667;1,167

1 |  |
     package org.apache.turbine.services.security.torque;
2 |  |
3 |  |
     /*
4 |  |
      * Licensed to the Apache Software Foundation (ASF) under one
5 |  |
      * or more contributor license agreements.  See the NOTICE file
6 |  |
      * distributed with this work for additional information
7 |  |
      * regarding copyright ownership.  The ASF licenses this file
8 |  |
      * to you under the Apache License, Version 2.0 (the
9 |  |
      * "License"); you may not use this file except in compliance
10 |  |
      * with the License.  You may obtain a copy of the License at
11 |  |
      *
12 |  |
      *   http://www.apache.org/licenses/LICENSE-2.0
13 |  |
      *
14 |  |
      * Unless required by applicable law or agreed to in writing,
15 |  |
      * software distributed under the License is distributed on an
16 |  |
      * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 |  |
      * KIND, either express or implied.  See the License for the
18 |  |
      * specific language governing permissions and limitations
19 |  |
      * under the License.
20 |  |
      */
21 |  |
22 |  |
     import java.util.Iterator;
23 |  |
24 |  |
     import org.apache.torque.om.Persistent;
25 |  |
26 |  |
     import org.apache.turbine.om.security.Group;
27 |  |
     import org.apache.turbine.om.security.Role;
28 |  |
     import org.apache.turbine.om.security.User;
29 |  |
     import org.apache.turbine.services.security.TurbineSecurity;
30 |  |
     import org.apache.turbine.util.security.RoleSet;
31 |  |
     import org.apache.turbine.util.security.TurbineSecurityException;
32 |  |
33 |  |
     /**
34 |  |
      * This class represents a Group of Users in the system that are associated
35 |  |
      * with specific entity or resource. The users belonging to the Group may
36 |  |
      * have various Roles. The Permissions to perform actions upon the resource
37 |  |
      * depend on the Roles in the Group that they are assigned. It is separated
38 |  |
      * from the actual Torque peer object to be able to replace the Peer with an
39 |  |
      * user supplied Peer (and Object)
40 |  |
      *
41 |  |
      * <a name="global">
42 |  |
      * <p> Certain Roles that the Users may have in the system are not related
43 |  |
      * to any specific resource nor entity.
44 |  |
      * They are assigned within a special group named 'global' that can be
45 |  |
      * referenced in the code as {@link #GLOBAL_GROUP_NAME}.
46 |  |
      * <br>
47 |  |
      *
48 |  |
      * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
49 |  |
      * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
50 |  |
      * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
51 |  |
      * @version $Id: TorqueGroup.java 1096130 2011-04-23 10:37:19Z ludwig $
52 |  |
      */
53 |  |
54 |  |
     public class TorqueGroup
55 |  |
         extends TorqueObject
56 |  |
         implements Group,
57 |  |
                    Comparable
58 |  |
     {
59 |  |
60 |  |
             /** Serial Version UID */
61 |  |
             private static final long serialVersionUID = -2034684697021752888L;
62 |  |
63 |  |
         /**
64 |  |
          * Constructs a new Group.
65 |  |
          */
66 |  |
         public TorqueGroup()
67 |  |
         {
68 | 0 |
             super();
69 | 0 |
         }
70 |  |
71 |  |
         /**
72 |  |
          * Constructs a new Group with the specified name.
73 |  |
          *
74 |  |
          * @param name The name of the new object.
75 |  |
          */
76 |  |
77 |  |
         public TorqueGroup(String name)
78 |  |
         {
79 | 0 |
             super(name);
80 | 0 |
         }
81 |  |
82 |  |
         /**
83 |  |
          * The package private Constructor is used when the GroupPeerManager
84 |  |
          * has retrieved a list of Database Objects from the peer and
85 |  |
          * must 'wrap' them into TorqueGroup Objects.
86 |  |
          * You should not use it directly!
87 |  |
          *
88 |  |
          * @param obj An Object from the peer
89 |  |
          */
90 |  |
         public TorqueGroup(Persistent obj)
91 |  |
         {
92 | 0 |
             super(obj);
93 | 0 |
         }
94 |  |
95 |  |
         /**
96 |  |
          * Returns the underlying Object for the Peer
97 |  |
          *
98 |  |
          * Used in the GroupPeerManager when building a new Criteria.
99 |  |
          *
100 |  |
          * @return The underlying persistent object
101 |  |
          *
102 |  |
          */
103 |  |
104 |  |
         public Persistent getPersistentObj()
105 |  |
         {
106 | 0 |
             if (obj == null)
107 |  |
             {
108 | 0 |
                 obj = GroupPeerManager.newPersistentInstance();
109 |  |
             }
110 | 0 |
             return obj;
111 |  |
         }
112 |  |
113 |  |
         /**
114 |  |
          * Returns the name of this object.
115 |  |
          *
116 |  |
          * @return The name of the object.
117 |  |
          */
118 |  |
         public String getName()
119 |  |
         {
120 | 0 |
             return GroupPeerManager.getGroupName(getPersistentObj());
121 |  |
         }
122 |  |
123 |  |
         /**
124 |  |
          * Sets the name of this object.
125 |  |
          *
126 |  |
          * @param name The name of the object.
127 |  |
          */
128 |  |
         public void setName(String name)
129 |  |
         {
130 | 0 |
             GroupPeerManager.setGroupName(getPersistentObj(), name);
131 | 0 |
         }
132 |  |
133 |  |
         /**
134 |  |
          * Gets the Id of this object
135 |  |
          *
136 |  |
          * @return The Id of the object
137 |  |
          */
138 |  |
         public int getId()
139 |  |
         {
140 | 0 |
             return GroupPeerManager.getIdAsObj(getPersistentObj()).intValue();
141 |  |
         }
142 |  |
143 |  |
         /**
144 |  |
          * Gets the Id of this object
145 |  |
          *
146 |  |
          * @return The Id of the object
147 |  |
          */
148 |  |
         public Integer getIdAsObj()
149 |  |
         {
150 | 0 |
             return GroupPeerManager.getIdAsObj(getPersistentObj());
151 |  |
         }
152 |  |
153 |  |
         /**
154 |  |
          * Sets the Id of this object
155 |  |
          *
156 |  |
          * @param id The new Id
157 |  |
          */
158 |  |
         public void setId(int id)
159 |  |
         {
160 | 0 |
             GroupPeerManager.setId(getPersistentObj(), id);
161 | 0 |
         }
162 |  |
163 |  |
         /**
164 |  |
          * Provides a reference to the Group object that represents the
165 |  |
          * <a href="#global">global group</a>.
166 |  |
          *
167 |  |
          * @return a Group object that represents the global group.
168 |  |
          * @deprecated Please use the method in TurbineSecurity now.
169 |  |
          */
170 |  |
         public static Group getGlobalGroup()
171 |  |
         {
172 | 0 |
             return TurbineSecurity.getGlobalGroup();
173 |  |
         }
174 |  |
175 |  |
         /**
176 |  |
          * Creates a new Group in the system.
177 |  |
          *
178 |  |
          * @param name The name of the new Group.
179 |  |
          * @return An object representing the new Group.
180 |  |
          * @throws TurbineSecurityException if the Group could not be created.
181 |  |
          * @deprecated Please use the createGroup method in TurbineSecurity now.
182 |  |
          */
183 |  |
         public static Group create(String name)
184 |  |
             throws TurbineSecurityException
185 |  |
         {
186 | 0 |
             return TurbineSecurity.createGroup(name);
187 |  |
         }
188 |  |
189 |  |
         // These following methods are wrappers around TurbineSecurity
190 |  |
191 |  |
         /**
192 |  |
          * Makes changes made to the Group attributes permanent.
193 |  |
          *
194 |  |
          * @throws TurbineSecurityException if there is a problem while
195 |  |
          *  saving data.
196 |  |
          */
197 |  |
         public void save()
198 |  |
             throws TurbineSecurityException
199 |  |
         {
200 | 0 |
             TurbineSecurity.saveGroup(this);
201 | 0 |
         }
202 |  |
203 |  |
         /**
204 |  |
          * Removes a group from the system.
205 |  |
          *
206 |  |
          * @throws TurbineSecurityException if the Group could not be removed.
207 |  |
          */
208 |  |
         public void remove()
209 |  |
             throws TurbineSecurityException
210 |  |
         {
211 | 0 |
             TurbineSecurity.removeGroup(this);
212 | 0 |
         }
213 |  |
214 |  |
         /**
215 |  |
          * Renames the role.
216 |  |
          *
217 |  |
          * @param name The new Group name.
218 |  |
          * @throws TurbineSecurityException if the Group could not be renamed.
219 |  |
          */
220 |  |
         public void rename(String name)
221 |  |
             throws TurbineSecurityException
222 |  |
         {
223 | 0 |
             TurbineSecurity.renameGroup(this, name);
224 | 0 |
         }
225 |  |
226 |  |
         /**
227 |  |
          * Grants a Role in this Group to an User.
228 |  |
          *
229 |  |
          * @param user An User.
230 |  |
          * @param role A Role.
231 |  |
          * @throws TurbineSecurityException if there is a problem while assigning
232 |  |
          * the Role.
233 |  |
          */
234 |  |
         public void grant(User user, Role role)
235 |  |
             throws TurbineSecurityException
236 |  |
         {
237 | 0 |
             TurbineSecurity.grant(user, this, role);
238 | 0 |
         }
239 |  |
240 |  |
         /**
241 |  |
          * Grants Roles in this Group to an User.
242 |  |
          *
243 |  |
          * @param user An User.
244 |  |
          * @param roleSet A RoleSet.
245 |  |
          * @throws TurbineSecurityException if there is a problem while assigning
246 |  |
          * the Roles.
247 |  |
          */
248 |  |
         public void grant(User user, RoleSet roleSet)
249 |  |
             throws TurbineSecurityException
250 |  |
         {
251 | 0 |
             Iterator roles = roleSet.iterator();
252 | 0 |
             while (roles.hasNext())
253 |  |
             {
254 | 0 |
                 TurbineSecurity.grant(user, this, (Role) roles.next());
255 |  |
             }
256 | 0 |
         }
257 |  |
258 |  |
         /**
259 |  |
          * Revokes a Role in this Group from an User.
260 |  |
          *
261 |  |
          * @param user An User.
262 |  |
          * @param role A Role.
263 |  |
          * @throws TurbineSecurityException if there is a problem while unassigning
264 |  |
          * the Role.
265 |  |
          */
266 |  |
         public void revoke(User user, Role role)
267 |  |
             throws TurbineSecurityException
268 |  |
         {
269 | 0 |
             TurbineSecurity.revoke(user, this, role);
270 | 0 |
         }
271 |  |
272 |  |
         /**
273 |  |
          * Revokes Roles in this group from an User.
274 |  |
          *
275 |  |
          * @param user An User.
276 |  |
          * @param roleSet a RoleSet.
277 |  |
          * @throws TurbineSecurityException if there is a problem while unassigning
278 |  |
          * the Roles.
279 |  |
          */
280 |  |
         public void revoke(User user, RoleSet roleSet)
281 |  |
             throws TurbineSecurityException
282 |  |
         {
283 | 0 |
             Iterator roles = roleSet.iterator();
284 | 0 |
             while (roles.hasNext())
285 |  |
             {
286 | 0 |
                 TurbineSecurity.revoke(user, this, (Role) roles.next());
287 |  |
             }
288 | 0 |
         }
289 |  |
290 |  |
     }
291 |  |