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()
062    {
063        return ACLJCRAmetysObjectHelper.getAllProfilesForAnonymousAndAnyConnectedUser();
064    }
065    
066    public Map<Object, Map<GroupIdentity, Map<UserOrGroup, Set<String>>>> getAllProfilesForGroups(Set<GroupIdentity> groups)
067    {
068        return ACLJCRAmetysObjectHelper.getAllProfilesForGroups(groups);
069    }
070    
071    public Map<Object, Map<UserOrGroup, Set<String>>> getAllProfilesForUser(UserIdentity user)
072    {
073        return ACLJCRAmetysObjectHelper.getAllProfilesForUser(user);
074    }
075    
076    /* ----------------------- */
077    /* ALLOWED/DENIED PROFILES */
078    /* ----------------------- */
079    
080    public Map<AnonymousOrAnyConnectedKeys, Set<String>> getProfilesForAnonymousAndAnyConnectedUser(Object object)
081    {
082        ACLAmetysObject ametysObj = (ACLAmetysObject) object;
083        return ametysObj.getProfilesForAnonymousAndAnyConnectedUser();
084    }
085
086    public Map<UserIdentity, Map<UserOrGroup, Set<String>>> getProfilesForUsers(Object object, UserIdentity user)
087    {
088        ACLAmetysObject ametysObj = (ACLAmetysObject) object;
089        return ametysObj.getProfilesForUsers(user);
090    }
091
092    public Map<GroupIdentity, Map<UserOrGroup, Set<String>>> getProfilesForGroups(Object object, Set<GroupIdentity> groups)
093    {
094        ACLAmetysObject ametysObj = (ACLAmetysObject) object;
095        return ametysObj.getProfilesForGroups(groups);
096    }
097    
098    /* ----------- */
099    /* INHERITANCE */
100    /* ----------- */
101
102    public boolean isInheritanceDisallowed(Object object)
103    {
104        ACLAmetysObject ametysObj = (ACLAmetysObject) object;
105        return ametysObj.isInheritanceDisallowed();
106    }
107
108    
109    /* ------------------------------ */
110    /* SUPPORT OF OBJECT AND PRIORITY */
111    /* ------------------------------ */
112    
113    @Override
114    public boolean isSupported(Object object)
115    {
116        return object instanceof ACLAmetysObject;
117    }
118    
119    public boolean isRootContextSupported(Object rootContext)
120    {
121        return rootContext instanceof JCRAmetysObject;
122    }
123
124    @Override
125    public int getPriority()
126    {
127        // Minor priority than ModifiableACLAmetysObjectProfileAssignmentStorage
128        return ProfileAssignmentStorage.MAX_PRIORITY + 100;
129    }
130}