001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.permission;
022:
023: import com.liferay.portal.kernel.bean.BeanLocatorUtil;
024: import com.liferay.portal.kernel.security.permission.PermissionChecker;
025: import com.liferay.portal.security.auth.PrincipalException;
026:
027: /**
028: * <a href="UserPermissionUtil.java.html"><b><i>View Source</i></b></a>
029: *
030: * @author Brian Wing Shun Chan
031: *
032: */
033: public class UserPermissionUtil {
034:
035: public static void check(PermissionChecker permissionChecker,
036: long userId, String actionId) throws PrincipalException {
037:
038: getUserPermission().check(permissionChecker, userId, actionId);
039: }
040:
041: /**
042: * @deprecated
043: */
044: public static void check(PermissionChecker permissionChecker,
045: long userId, long organizationId, long locationId,
046: String actionId) throws PrincipalException {
047:
048: check(permissionChecker, userId, new long[] { organizationId,
049: locationId }, actionId);
050: }
051:
052: public static void check(PermissionChecker permissionChecker,
053: long userId, long[] organizationIds, String actionId)
054: throws PrincipalException {
055:
056: getUserPermission().check(permissionChecker, userId,
057: organizationIds, actionId);
058: }
059:
060: public static boolean contains(PermissionChecker permissionChecker,
061: long userId, String actionId) {
062:
063: return getUserPermission().contains(permissionChecker, userId,
064: actionId);
065: }
066:
067: /**
068: * @deprecated
069: */
070: public static boolean contains(PermissionChecker permissionChecker,
071: long userId, long organizationId, long locationId,
072: String actionId) {
073:
074: return contains(permissionChecker, userId, new long[] {
075: organizationId, locationId }, actionId);
076: }
077:
078: public static boolean contains(PermissionChecker permissionChecker,
079: long userId, long[] organizationIds, String actionId) {
080:
081: return getUserPermission().contains(permissionChecker, userId,
082: organizationIds, actionId);
083: }
084:
085: public static UserPermission getUserPermission() {
086: return _getUtil()._userPermission;
087: }
088:
089: public void setUserPermission(UserPermission userPermission) {
090: _userPermission = userPermission;
091: }
092:
093: private static UserPermissionUtil _getUtil() {
094: if (_util == null) {
095: _util = (UserPermissionUtil) BeanLocatorUtil.locate(_UTIL);
096: }
097:
098: return _util;
099: }
100:
101: private static final String _UTIL = UserPermissionUtil.class
102: .getName();
103:
104: private static UserPermissionUtil _util;
105:
106: private UserPermission _userPermission;
107:
108: }
|