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.documentlibrary.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.documentlibrary.model.DLFolder;
031: import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
032: import com.liferay.portlet.documentlibrary.service.DLFolderLocalServiceUtil;
033:
034: /**
035: * <a href="DLFolderPermission.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class DLFolderPermission {
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: DLFolder 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 == DLFolderImpl.DEFAULT_PARENT_FOLDER_ID) {
074: return PortletPermissionUtil.contains(permissionChecker,
075: plid, PortletKeys.DOCUMENT_LIBRARY, actionId);
076: } else {
077: return contains(permissionChecker, folderId, actionId);
078: }
079: }
080:
081: public static boolean contains(PermissionChecker permissionChecker,
082: long folderId, String actionId) throws PortalException,
083: SystemException {
084:
085: DLFolder folder = DLFolderLocalServiceUtil.getFolder(folderId);
086:
087: return contains(permissionChecker, folder, actionId);
088: }
089:
090: public static boolean contains(PermissionChecker permissionChecker,
091: DLFolder folder, String actionId) throws PortalException,
092: SystemException {
093:
094: if (actionId.equals(ActionKeys.ADD_FOLDER)) {
095: actionId = ActionKeys.ADD_SUBFOLDER;
096: }
097:
098: long folderId = folder.getFolderId();
099:
100: while (folderId != DLFolderImpl.DEFAULT_PARENT_FOLDER_ID) {
101: folder = DLFolderLocalServiceUtil.getFolder(folderId);
102:
103: folderId = folder.getParentFolderId();
104:
105: if (permissionChecker.hasPermission(folder.getGroupId(),
106: DLFolder.class.getName(), folder.getFolderId(),
107: actionId)) {
108:
109: return true;
110: }
111:
112: if (actionId.equals(ActionKeys.VIEW)) {
113: break;
114: }
115: }
116:
117: return false;
118: }
119:
120: }
|