Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TorquePermission |
|
| 1.0769230769230769;1,077 |
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 org.apache.torque.om.Persistent; | |
23 | ||
24 | import org.apache.turbine.om.security.Permission; | |
25 | import org.apache.turbine.services.security.TurbineSecurity; | |
26 | import org.apache.turbine.util.security.TurbineSecurityException; | |
27 | ||
28 | /** | |
29 | * This class represents a permission given to a Role associated with the | |
30 | * current Session. It is separated from the actual Torque peer object | |
31 | * to be able to replace the Peer with an user supplied Peer (and Object) | |
32 | * | |
33 | * @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a> | |
34 | * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a> | |
35 | * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a> | |
36 | * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a> | |
37 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> | |
38 | * @version $Id: TorquePermission.java 534527 2007-05-02 16:10:59Z tv $ | |
39 | */ | |
40 | ||
41 | public class TorquePermission | |
42 | extends TorqueObject | |
43 | implements Permission, | |
44 | Comparable | |
45 | { | |
46 | ||
47 | private static final long serialVersionUID = -5524685597021445523L; | |
48 | ||
49 | /** | |
50 | * Constructs a Permission | |
51 | */ | |
52 | public TorquePermission() | |
53 | { | |
54 | 0 | super(); |
55 | 0 | } |
56 | ||
57 | /** | |
58 | * Constructs a new Permission with the sepcified name. | |
59 | * | |
60 | * @param name The name of the new object. | |
61 | */ | |
62 | public TorquePermission(String name) | |
63 | { | |
64 | 0 | super(name); |
65 | 0 | } |
66 | ||
67 | /** | |
68 | * The package private Constructor is used when the PermissionPeerManager | |
69 | * has retrieved a list of Database Objects from the peer and | |
70 | * must 'wrap' them into TorquePermission Objects. | |
71 | * You should not use it directly! | |
72 | * | |
73 | * @param obj An Object from the peer | |
74 | */ | |
75 | ||
76 | public TorquePermission(Persistent obj) | |
77 | { | |
78 | 0 | super(obj); |
79 | 0 | } |
80 | ||
81 | /** | |
82 | * Returns the underlying Object for the Peer | |
83 | * | |
84 | * Used in the PermissionPeerManager when building a new Criteria. | |
85 | * | |
86 | * @return The underlying Persistent Object | |
87 | * | |
88 | */ | |
89 | ||
90 | public Persistent getPersistentObj() | |
91 | { | |
92 | 0 | if (obj == null) |
93 | { | |
94 | 0 | obj = PermissionPeerManager.newPersistentInstance(); |
95 | } | |
96 | 0 | return obj; |
97 | } | |
98 | ||
99 | /** | |
100 | * Returns the name of this object. | |
101 | * | |
102 | * @return The name of the object. | |
103 | */ | |
104 | public String getName() | |
105 | { | |
106 | 0 | 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 | 0 | PermissionPeerManager.setPermissionName(getPersistentObj(), name); |
117 | 0 | } |
118 | ||
119 | /** | |
120 | * Gets the Id of this object | |
121 | * | |
122 | * @return The Id of the object | |
123 | */ | |
124 | public int getId() | |
125 | { | |
126 | 0 | 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 | 0 | 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 | 0 | PermissionPeerManager.setId(getPersistentObj(), id); |
147 | 0 | } |
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 | 0 | 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 | 0 | TurbineSecurity.savePermission(this); |
173 | 0 | } |
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 | 0 | TurbineSecurity.removePermission(this); |
184 | 0 | } |
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 | 0 | TurbineSecurity.renamePermission(this, name); |
196 | 0 | } |
197 | } | |
198 | ||
199 | ||
200 |