1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.security;
18
19 import org.apache.turbine.services.TurbineServices;
20 import org.apache.turbine.services.resources.ResourceService;
21
22 import org.apache.jetspeed.services.security.PermissionException;
23 import org.apache.jetspeed.services.security.JetspeedSecurityService;
24
25 /***
26 * Factory class for creating Jetspeed Permissions.
27 * The permission class is configured in the JR.p
28 *
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 */
32 public class JetspeedPermissionFactory
33 {
34 private static final String CONFIG_GROUP_CLASSNAME = "permission.class";
35
36 private static String permissionClassName = null;
37 private static Class permissionClass = null;
38
39 /***
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 */
46 public static Permission getInstance()
47 throws PermissionException
48 {
49 return getInstance(true);
50 }
51
52 public static Permission getInstance(boolean isNew)
53 throws PermissionException
54 {
55 Permission permission = null;
56
57 if (null == permissionClassName)
58 {
59 try
60 {
61 ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
62 .getResources(JetspeedSecurityService.SERVICE_NAME);
63 permissionClassName = serviceConf.getString(CONFIG_GROUP_CLASSNAME);
64 permissionClass = Class.forName(permissionClassName);
65 }
66 catch(Exception e)
67 {
68 throw new PermissionException(
69 "PermissionFactory: Failed to create a Class object for Permission implementation: " + e.toString());
70 }
71 }
72
73 try
74 {
75 permission = (Permission)permissionClass.newInstance();
76 if (permission instanceof BaseJetspeedPermission)
77 {
78 ((BaseJetspeedPermission)permission).setNew(isNew);
79 }
80 }
81 catch(Exception e)
82 {
83 throw new PermissionException("Failed instantiate an Permission implementation object: " + e.toString());
84 }
85
86 return permission;
87 }
88
89
90 }
91
92
93
94