| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| TurbineGroup |
|
| 1.3636363636363635;1,364 |
| 1 | package org.apache.turbine.om.security; | |
| 2 | ||
| 3 | ||
| 4 | /* | |
| 5 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 6 | * or more contributor license agreements. See the NOTICE file | |
| 7 | * distributed with this work for additional information | |
| 8 | * regarding copyright ownership. The ASF licenses this file | |
| 9 | * to you under the Apache License, Version 2.0 (the | |
| 10 | * "License"); you may not use this file except in compliance | |
| 11 | * with the License. You may obtain a copy of the License at | |
| 12 | * | |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 14 | * | |
| 15 | * Unless required by applicable law or agreed to in writing, | |
| 16 | * software distributed under the License is distributed on an | |
| 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 18 | * KIND, either express or implied. See the License for the | |
| 19 | * specific language governing permissions and limitations | |
| 20 | * under the License. | |
| 21 | */ | |
| 22 | ||
| 23 | ||
| 24 | import java.sql.Connection; | |
| 25 | import java.util.Iterator; | |
| 26 | ||
| 27 | import org.apache.turbine.services.security.TurbineSecurity; | |
| 28 | import org.apache.turbine.util.security.RoleSet; | |
| 29 | import org.apache.turbine.util.security.TurbineSecurityException; | |
| 30 | ||
| 31 | /** | |
| 32 | * This class represents a Group of Users in the system that are associated | |
| 33 | * with specific entity or resource. The users belonging to the Group may have | |
| 34 | * various Roles. The Permissions to perform actions upon the resource depend | |
| 35 | * on the Roles in the Group that they are assigned. | |
| 36 | * | |
| 37 | * <a name="global"> | |
| 38 | * <p> Certain Roles that the Users may have in the system may are not related | |
| 39 | * to any specific resource nor entity. | |
| 40 | * They are assigned within a special group named 'global' that can be | |
| 41 | * referenced in the code as {@link #GLOBAL_GROUP_NAME}. | |
| 42 | * <br> | |
| 43 | * | |
| 44 | * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a> | |
| 45 | * @version $Id: TurbineGroup.java 1078552 2011-03-06 19:58:46Z tv $ | |
| 46 | */ | |
| 47 | public class TurbineGroup extends SecurityObject<Group> implements Group | |
| 48 | { | |
| 49 | /** Serial version */ | |
| 50 | private static final long serialVersionUID = -6034684697021752649L; | |
| 51 | ||
| 52 | /** | |
| 53 | * Constructs a new Group. | |
| 54 | */ | |
| 55 | public TurbineGroup() | |
| 56 | { | |
| 57 | 0 | super(); |
| 58 | 0 | } |
| 59 | ||
| 60 | /** | |
| 61 | * Constructs a new Group with the specified name. | |
| 62 | * | |
| 63 | * @param name The name of the new object. | |
| 64 | */ | |
| 65 | public TurbineGroup(String name) | |
| 66 | { | |
| 67 | 0 | super(name); |
| 68 | 0 | } |
| 69 | ||
| 70 | // These following methods are wrappers around TurbineSecurity | |
| 71 | ||
| 72 | /** | |
| 73 | * Makes changes made to the Group attributes permanent. | |
| 74 | * | |
| 75 | * @throws TurbineSecurityException if there is a problem while saving data. | |
| 76 | */ | |
| 77 | public void save() throws TurbineSecurityException | |
| 78 | { | |
| 79 | 0 | TurbineSecurity.saveGroup(this); |
| 80 | 0 | } |
| 81 | ||
| 82 | /** | |
| 83 | * not implemented | |
| 84 | * | |
| 85 | * @param conn | |
| 86 | * @throws Exception | |
| 87 | */ | |
| 88 | public void save(Connection conn) throws Exception | |
| 89 | { | |
| 90 | 0 | throw new Exception("not implemented"); |
| 91 | } | |
| 92 | ||
| 93 | /** | |
| 94 | * not implemented | |
| 95 | * | |
| 96 | * @param dbname | |
| 97 | * @throws Exception | |
| 98 | */ | |
| 99 | public void save(String dbname) throws Exception | |
| 100 | { | |
| 101 | 0 | throw new Exception("not implemented"); |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * Removes a group from the system. | |
| 106 | * | |
| 107 | * @throws TurbineSecurityException if the Group could not be removed. | |
| 108 | */ | |
| 109 | public void remove() throws TurbineSecurityException | |
| 110 | { | |
| 111 | 0 | TurbineSecurity.removeGroup(this); |
| 112 | 0 | } |
| 113 | ||
| 114 | /** | |
| 115 | * Renames the role. | |
| 116 | * | |
| 117 | * @param name The new Group name. | |
| 118 | * @throws TurbineSecurityException if the Group could not be renamed. | |
| 119 | */ | |
| 120 | public void rename(String name) throws TurbineSecurityException | |
| 121 | { | |
| 122 | 0 | TurbineSecurity.renameGroup(this, name); |
| 123 | 0 | } |
| 124 | ||
| 125 | /** | |
| 126 | * Grants a Role in this Group to an User. | |
| 127 | * | |
| 128 | * @param user An User. | |
| 129 | * @param role A Role. | |
| 130 | * @throws TurbineSecurityException if there is a problem while assigning | |
| 131 | * the Role. | |
| 132 | */ | |
| 133 | public void grant(User user, Role role) throws TurbineSecurityException | |
| 134 | { | |
| 135 | 0 | TurbineSecurity.grant(user, this, role); |
| 136 | 0 | } |
| 137 | ||
| 138 | /** | |
| 139 | * Grants Roles in this Group to an User. | |
| 140 | * | |
| 141 | * @param user An User. | |
| 142 | * @param roleSet A RoleSet. | |
| 143 | * @throws TurbineSecurityException if there is a problem while assigning | |
| 144 | * the Roles. | |
| 145 | */ | |
| 146 | public void grant(User user, RoleSet roleSet) | |
| 147 | throws TurbineSecurityException | |
| 148 | { | |
| 149 | 0 | for (Iterator roles = roleSet.iterator(); roles.hasNext();) |
| 150 | { | |
| 151 | 0 | TurbineSecurity.grant(user, this, (Role) roles.next()); |
| 152 | } | |
| 153 | 0 | } |
| 154 | ||
| 155 | /** | |
| 156 | * Revokes a Role in this Group from an User. | |
| 157 | * | |
| 158 | * @param user An User. | |
| 159 | * @param role A Role. | |
| 160 | * @throws TurbineSecurityException if there is a problem while unassigning | |
| 161 | * the Role. | |
| 162 | */ | |
| 163 | public void revoke(User user, Role role) throws TurbineSecurityException | |
| 164 | { | |
| 165 | 0 | TurbineSecurity.revoke(user, this, role); |
| 166 | 0 | } |
| 167 | ||
| 168 | /** | |
| 169 | * Revokes Roles in this group from an User. | |
| 170 | * | |
| 171 | * @param user An User. | |
| 172 | * @param roleSet a RoleSet. | |
| 173 | * @throws TurbineSecurityException if there is a problem while unassigning | |
| 174 | * the Roles. | |
| 175 | */ | |
| 176 | public void revoke(User user, RoleSet roleSet) | |
| 177 | throws TurbineSecurityException | |
| 178 | { | |
| 179 | 0 | for (Iterator roles = roleSet.iterator(); roles.hasNext();) |
| 180 | { | |
| 181 | 0 | TurbineSecurity.revoke(user, this, (Role) roles.next()); |
| 182 | } | |
| 183 | 0 | } |
| 184 | } |