001/* 002 * Copyright 2016 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.repository; 017 018import java.util.Map; 019import java.util.Set; 020 021import org.ametys.core.group.GroupIdentity; 022import org.ametys.core.right.ProfileAssignmentStorage; 023import org.ametys.core.user.UserIdentity; 024import org.ametys.plugins.repository.jcr.ACLJCRAmetysObjectHelper; 025import org.ametys.plugins.repository.jcr.JCRAmetysObject; 026import org.ametys.runtime.plugin.component.AbstractLogEnabled; 027 028/** 029 * Implementation of {@link ProfileAssignmentStorage} for {@link ACLAmetysObject}s which stores profile assignments in subnodes of the node representing this object. 030 */ 031public class ACLAmetysObjectProfileAssignmentStorage extends AbstractLogEnabled implements ProfileAssignmentStorage 032{ 033 /* -------------- */ 034 /* HAS PERMISSION */ 035 /* -------------- */ 036 037 public Set<String> hasUserAnyAllowedProfile(Set< ? extends Object> rootContexts, UserIdentity user, Set<String> profileIds) 038 { 039 return ACLJCRAmetysObjectHelper.hasUserAnyAllowedProfile(rootContexts, user, profileIds); 040 } 041 042 public Set<String> hasGroupAnyAllowedProfile(Set< ? extends Object> rootContexts, Set<GroupIdentity> groups, Set<String> profileIds) 043 { 044 return ACLJCRAmetysObjectHelper.hasGroupAnyAllowedProfile(rootContexts, groups, profileIds); 045 } 046 047 public Set<String> hasAnyConnectedAnyAllowedProfile(Set< ? extends Object> rootContexts, Set<String> profileIds) 048 { 049 return ACLJCRAmetysObjectHelper.hasAnyConnectedAnyAllowedProfile(rootContexts, profileIds); 050 } 051 052 public Set<String> hasAnonymousAnyAllowedProfile(Set< ? extends Object> rootContexts, Set<String> profileIds) 053 { 054 return ACLJCRAmetysObjectHelper.hasAnonymousAnyAllowedProfile(rootContexts, profileIds); 055 } 056 057 /* ----------------------- */ 058 /* GET ALL PROFILES */ 059 /* ----------------------- */ 060 061 public Map<Object, Map<AnonymousOrAnyConnectedKeys, Set<String>>> getAllProfilesForAnonymousAndAnyConnectedUser(Set< ? extends Object> rootContexts) 062 { 063 return ACLJCRAmetysObjectHelper.getAllProfilesForAnonymousAndAnyConnectedUser(rootContexts); 064 } 065 066 public Map<Object, Map<GroupIdentity, Map<UserOrGroup, Set<String>>>> getAllProfilesForGroups(Set< ? extends Object> rootContexts, Set<GroupIdentity> groups) 067 { 068 return ACLJCRAmetysObjectHelper.getAllProfilesForGroups(rootContexts, groups); 069 } 070 071 public Map<Object, Map<UserOrGroup, Set<String>>> getAllProfilesForUser(Set< ? extends Object> rootContexts, UserIdentity user) 072 { 073 return ACLJCRAmetysObjectHelper.getAllProfilesForUser(rootContexts, user); 074 } 075 076 public Map<Object, Set<AnonymousOrAnyConnectedKeys>> getAllAssignmentsForAnonymousAndAnyConnectedUser(Set< ? extends Object> rootContexts, String profileId) 077 { 078 return ACLJCRAmetysObjectHelper.getProfilePermissionsForAnonymousAndAnyConnectedUser(rootContexts, profileId); 079 } 080 081 public Map<Object, Map<UserIdentity, Set<UserOrGroup>>> getAllAssignmentsForUsers(Set< ? extends Object> rootContexts, String profileId) 082 { 083 return ACLJCRAmetysObjectHelper.getProfilePermissionsForUsers(rootContexts, profileId); 084 } 085 086 public Map<Object, Map<GroupIdentity, Set<UserOrGroup>>> getAllAssignmentsForGroups(Set< ? extends Object> rootContexts, String profileId) 087 { 088 return ACLJCRAmetysObjectHelper.getProfilePermissionsForGroups(rootContexts, profileId); 089 } 090 091 /* ----------------------- */ 092 /* ALLOWED/DENIED PROFILES */ 093 /* ----------------------- */ 094 095 public Map<AnonymousOrAnyConnectedKeys, Set<String>> getProfilesForAnonymousAndAnyConnectedUser(Object object) 096 { 097 ACLAmetysObject ametysObj = (ACLAmetysObject) object; 098 return ametysObj.getProfilesForAnonymousAndAnyConnectedUser(); 099 } 100 101 public Map<UserIdentity, Map<UserOrGroup, Set<String>>> getProfilesForUsers(Object object, UserIdentity user) 102 { 103 ACLAmetysObject ametysObj = (ACLAmetysObject) object; 104 return ametysObj.getProfilesForUsers(user); 105 } 106 107 public Map<GroupIdentity, Map<UserOrGroup, Set<String>>> getProfilesForGroups(Object object, Set<GroupIdentity> groups) 108 { 109 ACLAmetysObject ametysObj = (ACLAmetysObject) object; 110 return ametysObj.getProfilesForGroups(groups); 111 } 112 113 /* ----------- */ 114 /* INHERITANCE */ 115 /* ----------- */ 116 117 public boolean isInheritanceDisallowed(Object object) 118 { 119 ACLAmetysObject ametysObj = (ACLAmetysObject) object; 120 return ametysObj.isInheritanceDisallowed(); 121 } 122 123 124 /* ------------------------------ */ 125 /* SUPPORT OF OBJECT AND PRIORITY */ 126 /* ------------------------------ */ 127 128 public boolean supports(Object object) 129 { 130 return object instanceof ACLAmetysObject; 131 } 132 133 public boolean isRootContextSupported(Object rootContext) 134 { 135 return rootContext instanceof JCRAmetysObject; 136 } 137 138 @Override 139 public int getPriority() 140 { 141 // Minor priority than ModifiableACLAmetysObjectProfileAssignmentStorage 142 return ProfileAssignmentStorage.MAX_PRIORITY + 100; 143 } 144}