001 package org.apache.turbine.services.security.torque; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import org.apache.torque.om.Persistent; 023 024 import org.apache.turbine.om.security.Permission; 025 import org.apache.turbine.services.security.TurbineSecurity; 026 import org.apache.turbine.util.security.TurbineSecurityException; 027 028 /** 029 * This class represents a permission given to a Role associated with the 030 * current Session. It is separated from the actual Torque peer object 031 * to be able to replace the Peer with an user supplied Peer (and Object) 032 * 033 * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a> 034 * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a> 035 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> 036 * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a> 037 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> 038 * @version $Id: TorquePermission.java 534527 2007-05-02 16:10:59Z tv $ 039 */ 040 041 public class TorquePermission 042 extends TorqueObject 043 implements Permission, 044 Comparable 045 { 046 047 private static final long serialVersionUID = -5524685597021445523L; 048 049 /** 050 * Constructs a Permission 051 */ 052 public TorquePermission() 053 { 054 super(); 055 } 056 057 /** 058 * Constructs a new Permission with the sepcified name. 059 * 060 * @param name The name of the new object. 061 */ 062 public TorquePermission(String name) 063 { 064 super(name); 065 } 066 067 /** 068 * The package private Constructor is used when the PermissionPeerManager 069 * has retrieved a list of Database Objects from the peer and 070 * must 'wrap' them into TorquePermission Objects. 071 * You should not use it directly! 072 * 073 * @param obj An Object from the peer 074 */ 075 076 public TorquePermission(Persistent obj) 077 { 078 super(obj); 079 } 080 081 /** 082 * Returns the underlying Object for the Peer 083 * 084 * Used in the PermissionPeerManager when building a new Criteria. 085 * 086 * @return The underlying Persistent Object 087 * 088 */ 089 090 public Persistent getPersistentObj() 091 { 092 if (obj == null) 093 { 094 obj = PermissionPeerManager.newPersistentInstance(); 095 } 096 return obj; 097 } 098 099 /** 100 * Returns the name of this object. 101 * 102 * @return The name of the object. 103 */ 104 public String getName() 105 { 106 return PermissionPeerManager.getPermissionName(getPersistentObj()); 107 } 108 109 /** 110 * Sets the name of this object. 111 * 112 * @param name The name of the object. 113 */ 114 public void setName(String name) 115 { 116 PermissionPeerManager.setPermissionName(getPersistentObj(), name); 117 } 118 119 /** 120 * Gets the Id of this object 121 * 122 * @return The Id of the object 123 */ 124 public int getId() 125 { 126 return PermissionPeerManager.getIdAsObj(getPersistentObj()).intValue(); 127 } 128 129 /** 130 * Gets the Id of this object 131 * 132 * @return The Id of the object 133 */ 134 public Integer getIdAsObj() 135 { 136 return PermissionPeerManager.getIdAsObj(getPersistentObj()); 137 } 138 139 /** 140 * Sets the Id of this object 141 * 142 * @param id The new Id 143 */ 144 public void setId(int id) 145 { 146 PermissionPeerManager.setId(getPersistentObj(), id); 147 } 148 149 /** 150 * Creates a new Permission in the system. 151 * 152 * @param name The name of the new Permission. 153 * @return An object representing the new Permission. 154 * @throws TurbineSecurityException if the Permission could not be created. 155 * @deprecated Please use the createPermission method in TurbineSecurity. 156 */ 157 public static Permission create(String name) 158 throws TurbineSecurityException 159 { 160 return TurbineSecurity.createPermission(name); 161 } 162 163 /** 164 * Makes changes made to the Permission attributes permanent. 165 * 166 * @throws TurbineSecurityException if there is a problem while 167 * saving data. 168 */ 169 public void save() 170 throws TurbineSecurityException 171 { 172 TurbineSecurity.savePermission(this); 173 } 174 175 /** 176 * Removes a permission from the system. 177 * 178 * @throws TurbineSecurityException if the Permission could not be removed. 179 */ 180 public void remove() 181 throws TurbineSecurityException 182 { 183 TurbineSecurity.removePermission(this); 184 } 185 186 /** 187 * Renames the permission. 188 * 189 * @param name The new Permission name. 190 * @throws TurbineSecurityException if the Permission could not be renamed. 191 */ 192 public void rename(String name) 193 throws TurbineSecurityException 194 { 195 TurbineSecurity.renamePermission(this, name); 196 } 197 } 198 199 200