1/*2 * Copyright 2000-2001,2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.om.security;
1819import org.apache.turbine.services.TurbineServices;
20import org.apache.turbine.services.resources.ResourceService;
2122import org.apache.jetspeed.services.security.PermissionException;
23import org.apache.jetspeed.services.security.JetspeedSecurityService;
2425/***26 * Factory class for creating Jetspeed Permissions.27 * The permission class is configured in the JR.p28 *29 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>30 * @version $Id: JetspeedPermissionFactory.java,v 1.4 2004/02/23 03:14:12 jford Exp $ 31 */32publicclassJetspeedPermissionFactory33 {
34privatestaticfinal String CONFIG_GROUP_CLASSNAME = "permission.class";
3536privatestatic String permissionClassName = null;
37privatestatic Class permissionClass = null;
3839/***40 * Factory method to create JetspeedPermission instances. 41 *42 *43 * @throws UnknownEntityException when the permission instance cant be created.44 * @return Permission a new created permission.45 */46publicstaticPermission getInstance()
47 throws PermissionException48 {
49return getInstance(true);
50 }
5152publicstaticPermission getInstance(boolean isNew)
53 throws PermissionException54 {
55Permission permission = null;
5657if (null == permissionClassName)
58 {
59try60 {
61 ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
62 .getResources(JetspeedSecurityService.SERVICE_NAME);
63 permissionClassName = serviceConf.getString(CONFIG_GROUP_CLASSNAME);
64 permissionClass = Class.forName(permissionClassName);
65 }
66catch(Exception e)
67 {
68thrownewPermissionException(
69"PermissionFactory: Failed to create a Class object for Permission implementation: " + e.toString());
70 }
71 }
7273try74 {
75 permission = (Permission)permissionClass.newInstance();
76if (permission instanceof BaseJetspeedPermission)
77 {
78 ((BaseJetspeedPermission)permission).setNew(isNew);
79 }
80 }
81catch(Exception e)
82 {
83thrownewPermissionException("Failed instantiate an Permission implementation object: " + e.toString());
84 }
8586return permission;
87 }
888990 }
91929394