01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.portal.security.permission;
22:
23: import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
24: import com.liferay.portal.kernel.cache.PortalCache;
25: import com.liferay.portal.kernel.util.StringMaker;
26: import com.liferay.portal.kernel.util.StringPool;
27:
28: /**
29: * <a href="PermissionCacheUtil.java.html"><b><i>View Source</i></b></a>
30: *
31: * @author Charles May
32: * @author Michael Young
33: *
34: */
35: public class PermissionCacheUtil {
36:
37: public static final String CACHE_NAME = PermissionCacheUtil.class
38: .getName();
39:
40: public static void clearCache() {
41: _cache.removeAll();
42: }
43:
44: public static Boolean hasPermission(long userId, long groupId,
45: String name, String primKey, String actionId) {
46:
47: String key = _encodeKey(userId, groupId, name, primKey,
48: actionId);
49:
50: Boolean value = (Boolean) MultiVMPoolUtil.get(_cache, key);
51:
52: return value;
53: }
54:
55: public static Boolean putPermission(long userId, long groupId,
56: String name, String primKey, String actionId, Boolean value) {
57:
58: if (value != null) {
59: String key = _encodeKey(userId, groupId, name, primKey,
60: actionId);
61:
62: MultiVMPoolUtil.put(_cache, key, value);
63: }
64:
65: return value;
66: }
67:
68: private static String _encodeKey(long userId, long groupId,
69: String name, String primKey, String actionId) {
70:
71: StringMaker sm = new StringMaker();
72:
73: sm.append(CACHE_NAME);
74: sm.append(StringPool.POUND);
75: sm.append(userId);
76: sm.append(StringPool.POUND);
77: sm.append(groupId);
78: sm.append(StringPool.POUND);
79: sm.append(name);
80: sm.append(StringPool.POUND);
81: sm.append(primKey);
82: sm.append(StringPool.POUND);
83: sm.append(actionId);
84:
85: return sm.toString();
86: }
87:
88: private static PortalCache _cache = MultiVMPoolUtil
89: .getCache(CACHE_NAME);
90:
91: }
|