001 package org.apache.turbine.om.security; 002 003 004 /* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 */ 022 023 024 import java.sql.Connection; 025 import java.util.Iterator; 026 027 import org.apache.turbine.services.security.TurbineSecurity; 028 import org.apache.turbine.util.security.RoleSet; 029 import org.apache.turbine.util.security.TurbineSecurityException; 030 031 /** 032 * This class represents a Group of Users in the system that are associated 033 * with specific entity or resource. The users belonging to the Group may have 034 * various Roles. The Permissions to perform actions upon the resource depend 035 * on the Roles in the Group that they are assigned. 036 * 037 * <a name="global"> 038 * <p> Certain Roles that the Users may have in the system may are not related 039 * to any specific resource nor entity. 040 * They are assigned within a special group named 'global' that can be 041 * referenced in the code as {@link #GLOBAL_GROUP_NAME}. 042 * <br> 043 * 044 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a> 045 * @version $Id: TurbineGroup.java 1078552 2011-03-06 19:58:46Z tv $ 046 */ 047 public class TurbineGroup extends SecurityObject<Group> implements Group 048 { 049 /** Serial version */ 050 private static final long serialVersionUID = -6034684697021752649L; 051 052 /** 053 * Constructs a new Group. 054 */ 055 public TurbineGroup() 056 { 057 super(); 058 } 059 060 /** 061 * Constructs a new Group with the specified name. 062 * 063 * @param name The name of the new object. 064 */ 065 public TurbineGroup(String name) 066 { 067 super(name); 068 } 069 070 // These following methods are wrappers around TurbineSecurity 071 072 /** 073 * Makes changes made to the Group attributes permanent. 074 * 075 * @throws TurbineSecurityException if there is a problem while saving data. 076 */ 077 public void save() throws TurbineSecurityException 078 { 079 TurbineSecurity.saveGroup(this); 080 } 081 082 /** 083 * not implemented 084 * 085 * @param conn 086 * @throws Exception 087 */ 088 public void save(Connection conn) throws Exception 089 { 090 throw new Exception("not implemented"); 091 } 092 093 /** 094 * not implemented 095 * 096 * @param dbname 097 * @throws Exception 098 */ 099 public void save(String dbname) throws Exception 100 { 101 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 TurbineSecurity.removeGroup(this); 112 } 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 TurbineSecurity.renameGroup(this, name); 123 } 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 TurbineSecurity.grant(user, this, role); 136 } 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 for (Iterator roles = roleSet.iterator(); roles.hasNext();) 150 { 151 TurbineSecurity.grant(user, this, (Role) roles.next()); 152 } 153 } 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 TurbineSecurity.revoke(user, this, role); 166 } 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 for (Iterator roles = roleSet.iterator(); roles.hasNext();) 180 { 181 TurbineSecurity.revoke(user, this, (Role) roles.next()); 182 } 183 } 184 }