AuthorizationManager.java

biz/hammurapi/authorization/AuthorizationManager.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 085 Do not declare runtime exceptions in the throws clause. 2 39:9
Java Inspector 085 Do not declare runtime exceptions in the throws clause. 2 63:9
Java Inspector 089 Undocumented method 2 34:9
Java Inspector 089 Undocumented method 2 39:9
Java Inspector 089 Parameter instance is not documented 2 52:9
Java Inspector 089 Parameter action is not documented 2 52:9
Java Inspector 089 Method return value is not properly documented 2 52:9
Java Inspector 089 Parameter instance is not documented 2 63:9
Java Inspector 089 Parameter action is not documented 2 63:9
Java Inspector 089 Undocumented exception AccessControlException 2 63:9
Java Inspector 089 @return tag is not applicable to void methods 2 63:9
Java Inspector 089 Undocumented parameter className 2 77:9
Java Inspector 089 Parameter action is not documented 2 77:9
Java Inspector 089 Javadoc contains tag for non-existent parameter subject 2 77:9
Java Inspector 089 Method return value is not properly documented 2 77:9
Java Inspector 089 Undocumented method 2 85:9

Source code

1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.authorization;
24
25import java.security.AccessControlException;
26
27/**
28 * "Hub" class for authorization checks.
29 * @author Pavel Vlasov
30 * @revision $Revision$
31 */
32public class AuthorizationManager {
33
34 public static boolean hasClassPermission(Class clazz, String action) {
35 AuthorizationProvider provider = (AuthorizationProvider) threadProvider.get();
36 return provider==null ? true : provider.hasClassPermission(clazz, action);
37 }
38
39 public static void checkClassPermission(Class clazz, String action) throws AccessControlException {
40 AuthorizationProvider provider = (AuthorizationProvider) threadProvider.get();
41 if (provider!=null) {
42 provider.checkClassPermission(clazz, action);
43 }
44 }
45
46 /**
47 * Authorization provider determines permission type from subject type
48 * @param instance
49 * @param action
50 * @return
51 */
52 public static boolean hasObjectPermission(Object instance, String action) {
53 AuthorizationProvider provider = (AuthorizationProvider) threadProvider.get();
54 return provider==null ? true : provider.hasInstancePermission(instance, action);
55 }
56
57 /**
58 * Authorization provider determines permission type from subject.
59 * @param instance
60 * @param action
61 * @return
62 */
63 public static void checkInstancePermission(Object instance, String action) throws AccessControlException {
64 AuthorizationProvider provider = (AuthorizationProvider) threadProvider.get();
65 if (provider!=null) {
66 provider.checkInstancePermission(instance, action);
67 }
68 }
69
70 /**
71 * Authorization provider determines permission type from className.
72 * This method is to be used from XSL stylesheets.
73 * @param subject
74 * @param action
75 * @return
76 */
77 public static boolean hasClassPermission(String className, String action) {
78 AuthorizationProvider provider = (AuthorizationProvider) threadProvider.get();
79 return provider==null ? true : provider.hasClassPermission(className, action);
80 }
81
82
83 private static InheritableThreadLocal threadProvider=new InheritableThreadLocal();
84
85 public static void setThreadProvider(AuthorizationProvider provider) {
86 threadProvider.set(provider);
87 }
88
89}
90