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.Set;
019
020import org.ametys.core.group.GroupIdentity;
021import org.ametys.core.right.ModifiableProfileAssignmentStorage;
022import org.ametys.core.right.ProfileAssignmentStorage;
023import org.ametys.core.user.UserIdentity;
024import org.ametys.plugins.repository.jcr.ACLJCRAmetysObjectHelper;
025
026/**
027 * Implementation of {@link ProfileAssignmentStorage} for {@link ModifiableACLAmetysObject}s which stores profile assignments in subnodes of the node representing this object.
028 */
029public class ModifiableACLAmetysObjectProfileAssignmentStorage extends ACLAmetysObjectProfileAssignmentStorage implements ModifiableProfileAssignmentStorage
030{
031    @Override
032    public void addAllowedProfilesForAnyConnectedUser(Object object, Set<String> profileIds)
033    {
034        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
035        ametysObj.addAllowedProfilesForAnyConnectedUser(profileIds);
036    }
037
038    @Override
039    public void removeAllowedProfilesForAnyConnectedUser(Object object, Set<String> profileIds)
040    {
041        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
042        ametysObj.removeAllowedProfilesForAnyConnectedUser(profileIds);
043    }
044
045    
046    /* -------------------------------------- */
047    /* DENIED PROFILES FOR ANY CONNECTED USER */
048    /* -------------------------------------- */
049    
050    @Override
051    public void addDeniedProfilesForAnyConnectedUser(Object object, Set<String> profileIds)
052    {
053        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
054        ametysObj.addDeniedProfilesForAnyConnectedUser(profileIds);
055    }
056    
057    @Override
058    public void removeDeniedProfilesForAnyConnectedUser(Object object, Set<String> profileIds)
059    {
060        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
061        ametysObj.removeDeniedProfilesForAnyConnectedUser(profileIds);
062    }
063    
064    
065    /* ------------------------------ */
066    /* ALLOWED PROFILES FOR ANONYMOUS */
067    /* ------------------------------ */
068    
069    @Override
070    public void addAllowedProfilesForAnonymous(Object object, Set<String> profileIds)
071    {
072        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
073        ametysObj.addAllowedProfilesForAnonymous(profileIds);
074    }
075    
076    @Override
077    public void removeAllowedProfilesForAnonymous(Object object, Set<String> profileIds)
078    {
079        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
080        ametysObj.removeAllowedProfilesForAnonymous(profileIds);
081    }
082    
083    
084    /* ----------------------------- */
085    /* DENIED PROFILES FOR ANONYMOUS */
086    /* ----------------------------- */
087    
088    @Override
089    public void addDeniedProfilesForAnonymous(Object object, Set<String> profileIds)
090    {
091        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
092        ametysObj.addDeniedProfilesForAnonymous(profileIds);
093    }
094    
095    @Override
096    public void removeDeniedProfilesForAnonymous(Object object, Set<String> profileIds)
097    {
098        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
099        ametysObj.removeDeniedProfilesForAnonymous(profileIds);
100    }
101    
102    
103    /* --------------------------- */
104    /* MANAGEMENT OF ALLOWED USERS */
105    /* --------------------------- */
106
107    @Override
108    public Set<UserIdentity> getAllowedUsers(Object object, String profileId)
109    {
110        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
111        return ametysObj.getAllowedUsers(profileId);
112    }
113
114    @Override
115    public void addAllowedUsers(Set<UserIdentity> users, Object object, String profileId)
116    {
117        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
118        ametysObj.addAllowedUsers(users, profileId);
119    }
120
121    @Override
122    public void removeAllowedUsers(Set<UserIdentity> users, Object object, String profileId)
123    {
124        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
125        ametysObj.removeAllowedUsers(users, profileId);
126    }
127
128    @Override
129    public void removeAllowedUsers(Set<UserIdentity> users, Object object)
130    {
131        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
132        ametysObj.removeAllowedUsers(users);
133    }
134    
135    
136    /* ---------------------------- */
137    /* MANAGEMENT OF ALLOWED GROUPS */
138    /* ---------------------------- */
139
140    @Override
141    public void addAllowedGroups(Set<GroupIdentity> groups, Object object, String profileId)
142    {
143        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
144        ametysObj.addAllowedGroups(groups, profileId);
145    }
146
147    @Override
148    public void removeAllowedGroups(Set<GroupIdentity> groups, Object object, String profileId)
149    {
150        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
151        ametysObj.removeAllowedGroups(groups, profileId);
152    }
153
154    @Override
155    public void removeAllowedGroups(Set<GroupIdentity> groups, Object object)
156    {
157        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
158        ametysObj.removeAllowedGroups(groups);
159    }
160
161    
162    /* ---------------------------- */
163    /* MANAGEMENT OF DENIED USERS */
164    /* ---------------------------- */
165
166    @Override
167    public void addDeniedUsers(Set<UserIdentity> users, Object object, String profileId)
168    {
169        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
170        ametysObj.addDeniedUsers(users, profileId);
171    }
172
173    @Override
174    public void removeDeniedUsers(Set<UserIdentity> users, Object object, String profileId)
175    {
176        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
177        ametysObj.removeDeniedUsers(users, profileId);
178    }
179
180    @Override
181    public void removeDeniedUsers(Set<UserIdentity> users, Object object)
182    {
183        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
184        ametysObj.removeDeniedUsers(users);
185    }
186
187    
188    /* ----------------------------- */
189    /* MANAGEMENT OF DENIED GROUPS */
190    /* ----------------------------- */
191
192    @Override
193    public void addDeniedGroups(Set<GroupIdentity> groups, Object object, String profileId)
194    {
195        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
196        ametysObj.addDeniedGroups(groups, profileId);
197    }
198
199    @Override
200    public void removeDeniedGroups(Set<GroupIdentity> groups, Object object, String profileId)
201    {
202        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
203        ametysObj.removeDeniedGroups(groups, profileId);
204    }
205
206    @Override
207    public void removeDeniedGroups(Set<GroupIdentity> groups, Object object)
208    {
209        ModifiableACLAmetysObject ametysObj = (ModifiableACLAmetysObject) object;
210        ametysObj.removeDeniedGroups(groups);
211    }
212    
213    
214    /* ------ */
215    /* REMOVE */
216    /* ------ */
217
218    @Override
219    public void removeProfile(String profileId)
220    {
221        ACLJCRAmetysObjectHelper.removeProfile(profileId);
222    }
223    
224    @Override
225    public void removeUser(UserIdentity user)
226    {
227        ACLJCRAmetysObjectHelper.removeUser(user);
228    }
229    
230    @Override
231    public void removeGroup(GroupIdentity group)
232    {
233        ACLJCRAmetysObjectHelper.removeGroup(group);
234    }
235    
236    
237    /* ------------------------------ */
238    /* SUPPORT OF OBJECT AND PRIORITY */
239    /* ------------------------------ */
240    
241    @Override
242    public boolean isSupported(Object object)
243    {
244        return object instanceof ModifiableACLAmetysObject;
245    }
246
247    @Override
248    public int getPriority()
249    {
250        return ProfileAssignmentStorage.MAX_PRIORITY;
251    }
252}