/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.staging.security.internal.permission;
import aQute.bnd.annotation.ProviderType;
import com.liferay.exportimport.kernel.staging.StagingUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.security.permission.PermissionChecker;
import com.liferay.portal.kernel.security.permission.UserBag;
import com.liferay.portal.kernel.service.GroupLocalServiceUtil;
import com.liferay.portal.kernel.service.ResourceBlockLocalService;
import java.util.List;
import java.util.Map;
/**
* @author Tomas Polesovsky
*/
@ProviderType
public class StagingPermissionChecker implements PermissionChecker {
public StagingPermissionChecker(
PermissionChecker permissionChecker,
ResourceBlockLocalService resourceBlockLocalService) {
_permissionChecker = permissionChecker;
_resourceBlockLocalService = resourceBlockLocalService;
}
@Override
public PermissionChecker clone() {
return new StagingPermissionChecker(
_permissionChecker.clone(), _resourceBlockLocalService);
}
@Override
public long getCompanyId() {
return _permissionChecker.getCompanyId();
}
@Override
public long[] getGuestUserRoleIds() {
return _permissionChecker.getGuestUserRoleIds();
}
@Override
public List<Long> getOwnerResourceBlockIds(
long companyId, long groupId, String name, String actionId) {
return _permissionChecker.getOwnerResourceBlockIds(
companyId, groupId, name, actionId);
}
@Override
public long getOwnerRoleId() {
return _permissionChecker.getOwnerRoleId();
}
@Override
public Map<Object, Object> getPermissionChecksMap() {
return _permissionChecker.getPermissionChecksMap();
}
@Override
public List<Long> getResourceBlockIds(
long companyId, long groupId, long userId, String name,
String actionId) {
return _permissionChecker.getResourceBlockIds(
companyId, groupId, userId, name, actionId);
}
@Override
public long[] getRoleIds(long userId, long groupId) {
long liveGroupId = StagingUtil.getLiveGroupId(groupId);
return _permissionChecker.getRoleIds(userId, liveGroupId);
}
@Override
public User getUser() {
return _permissionChecker.getUser();
}
@Override
public UserBag getUserBag() throws Exception {
return _permissionChecker.getUserBag();
}
@Override
public long getUserId() {
return _permissionChecker.getUserId();
}
@Override
public boolean hasOwnerPermission(
long companyId, String name, long primKey, long ownerId,
String actionId) {
return _permissionChecker.hasOwnerPermission(
companyId, name, primKey, ownerId, actionId);
}
@Override
public boolean hasOwnerPermission(
long companyId, String name, String primKey, long ownerId,
String actionId) {
return _permissionChecker.hasOwnerPermission(
companyId, name, primKey, ownerId, actionId);
}
@Override
public boolean hasPermission(
Group group, String name, long primKey, String actionId) {
if ((group == null) || _resourceBlockLocalService.isSupported(name)) {
return _permissionChecker.hasPermission(
group, name, primKey, actionId);
}
Group liveGroup = StagingUtil.getLiveGroup(group);
if (liveGroup != group) {
if (primKey == group.getGroupId()) {
primKey = liveGroup.getGroupId();
}
}
return _permissionChecker.hasPermission(
liveGroup, name, primKey, actionId);
}
@Override
public boolean hasPermission(
Group group, String name, String primKey, String actionId) {
if ((group == null) || _resourceBlockLocalService.isSupported(name)) {
return _permissionChecker.hasPermission(
group, name, primKey, actionId);
}
Group liveGroup = StagingUtil.getLiveGroup(group);
if (liveGroup != group) {
if (primKey.equals(String.valueOf(group.getGroupId()))) {
primKey = String.valueOf(liveGroup.getGroupId());
}
}
return _permissionChecker.hasPermission(
liveGroup, name, primKey, actionId);
}
@Override
public boolean hasPermission(
long groupId, String name, long primKey, String actionId) {
return hasPermission(
GroupLocalServiceUtil.fetchGroup(groupId), name, primKey, actionId);
}
@Override
public boolean hasPermission(
long groupId, String name, String primKey, String actionId) {
return hasPermission(
GroupLocalServiceUtil.fetchGroup(groupId), name, primKey, actionId);
}
@Override
public void init(User user) {
_permissionChecker.init(user);
}
@Override
public boolean isCheckGuest() {
return _permissionChecker.isCheckGuest();
}
@Override
public boolean isCompanyAdmin() {
return _permissionChecker.isCompanyAdmin();
}
@Override
public boolean isCompanyAdmin(long companyId) {
return _permissionChecker.isCompanyAdmin(companyId);
}
@Override
public boolean isContentReviewer(long companyId, long groupId) {
long liveGroupId = StagingUtil.getLiveGroupId(groupId);
return _permissionChecker.isContentReviewer(companyId, liveGroupId);
}
@Override
public boolean isGroupAdmin(long groupId) {
long liveGroupId = StagingUtil.getLiveGroupId(groupId);
return _permissionChecker.isGroupAdmin(liveGroupId);
}
@Override
public boolean isGroupMember(long groupId) {
long liveGroupId = StagingUtil.getLiveGroupId(groupId);
return _permissionChecker.isGroupMember(liveGroupId);
}
@Override
public boolean isGroupOwner(long groupId) {
long liveGroupId = StagingUtil.getLiveGroupId(groupId);
return _permissionChecker.isGroupOwner(liveGroupId);
}
@Override
public boolean isOmniadmin() {
return _permissionChecker.isOmniadmin();
}
@Override
public boolean isOrganizationAdmin(long organizationId) {
return _permissionChecker.isOrganizationAdmin(organizationId);
}
@Override
public boolean isOrganizationOwner(long organizationId) {
return _permissionChecker.isOrganizationOwner(organizationId);
}
@Override
public boolean isSignedIn() {
return _permissionChecker.isSignedIn();
}
private final PermissionChecker _permissionChecker;
private final ResourceBlockLocalService _resourceBlockLocalService;
}