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.portlet.imagegallery.service.permission;
022:
023: import com.liferay.portal.PortalException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.security.permission.ActionKeys;
026: import com.liferay.portal.kernel.security.permission.PermissionChecker;
027: import com.liferay.portal.security.auth.PrincipalException;
028: import com.liferay.portal.service.permission.PortletPermissionUtil;
029: import com.liferay.portal.util.PortletKeys;
030: import com.liferay.portlet.imagegallery.model.IGFolder;
031: import com.liferay.portlet.imagegallery.model.impl.IGFolderImpl;
032: import com.liferay.portlet.imagegallery.service.IGFolderLocalServiceUtil;
033:
034: /**
035: * <a href="IGFolderPermission.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class IGFolderPermission {
041:
042: public static void check(PermissionChecker permissionChecker,
043: long plid, long folderId, String actionId)
044: throws PortalException, SystemException {
045:
046: if (!contains(permissionChecker, plid, folderId, actionId)) {
047: throw new PrincipalException();
048: }
049: }
050:
051: public static void check(PermissionChecker permissionChecker,
052: long folderId, String actionId) throws PortalException,
053: SystemException {
054:
055: if (!contains(permissionChecker, folderId, actionId)) {
056: throw new PrincipalException();
057: }
058: }
059:
060: public static void check(PermissionChecker permissionChecker,
061: IGFolder folder, String actionId) throws PortalException,
062: SystemException {
063:
064: if (!contains(permissionChecker, folder, actionId)) {
065: throw new PrincipalException();
066: }
067: }
068:
069: public static boolean contains(PermissionChecker permissionChecker,
070: long plid, long folderId, String actionId)
071: throws PortalException, SystemException {
072:
073: if (folderId == IGFolderImpl.DEFAULT_PARENT_FOLDER_ID) {
074:
075: return PortletPermissionUtil.contains(permissionChecker,
076: plid, PortletKeys.IMAGE_GALLERY, actionId);
077: } else {
078: return contains(permissionChecker, folderId, actionId);
079: }
080: }
081:
082: public static boolean contains(PermissionChecker permissionChecker,
083: long folderId, String actionId) throws PortalException,
084: SystemException {
085:
086: IGFolder folder = IGFolderLocalServiceUtil.getFolder(folderId);
087:
088: return contains(permissionChecker, folder, actionId);
089: }
090:
091: public static boolean contains(PermissionChecker permissionChecker,
092: IGFolder folder, String actionId) throws PortalException,
093: SystemException {
094:
095: if (actionId.equals(ActionKeys.ADD_FOLDER)) {
096: actionId = ActionKeys.ADD_SUBFOLDER;
097: }
098:
099: long folderId = folder.getFolderId();
100:
101: while (folderId != IGFolderImpl.DEFAULT_PARENT_FOLDER_ID) {
102: folder = IGFolderLocalServiceUtil.getFolder(folderId);
103:
104: folderId = folder.getParentFolderId();
105:
106: if (permissionChecker.hasPermission(folder.getGroupId(),
107: IGFolder.class.getName(), folder.getFolderId(),
108: actionId)) {
109:
110: return true;
111: }
112:
113: if (actionId.equals(ActionKeys.VIEW)) {
114: break;
115: }
116: }
117:
118: return false;
119: }
120:
121: }
|