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