001/*
002 *  Copyright 2010 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 */
016
017package org.ametys.plugins.repository.jcr;
018
019import java.util.Map;
020import java.util.Set;
021
022import javax.jcr.Node;
023
024import org.ametys.core.group.GroupIdentity;
025import org.ametys.core.right.ProfileAssignmentStorage.AnonymousOrAnyConnectedKeys;
026import org.ametys.core.right.ProfileAssignmentStorage.UserOrGroup;
027import org.ametys.core.user.UserIdentity;
028import org.ametys.plugins.repository.AmetysObject;
029import org.ametys.plugins.repository.AmetysObjectIterable;
030import org.ametys.plugins.repository.AmetysRepositoryException;
031import org.ametys.plugins.repository.ModifiableACLAmetysObject;
032import org.ametys.plugins.repository.RepositoryIntegrityViolationException;
033import org.ametys.plugins.repository.TraversableAmetysObject;
034import org.ametys.plugins.repository.UnknownAmetysObjectException;
035
036/**
037 * Default implementation of a {@link TraversableAmetysObject}, backed by a JCR node.<br>
038 * This implementation heavily relies on its {@link DefaultTraversableAmetysObjectFactory} counterpart.
039 * @param <F> the actual type of factory.
040 */
041public class DefaultTraversableAmetysObject<F extends DefaultTraversableAmetysObjectFactory> extends SimpleAmetysObject<F> implements JCRTraversableAmetysObject, ModifiableACLAmetysObject
042{
043    private DefaultTraversableAmetysObjectFactory _traversableFactory;
044    
045    /**
046     * Creates a DefaultTraversableAmetysObject.
047     * @param node the node backing this {@link AmetysObject}.
048     * @param parentPath the parent path in the Ametys hierarchy.
049     * @param factory the {@link DefaultTraversableAmetysObjectFactory} which creates the AmetysObject.
050     */
051    public DefaultTraversableAmetysObject(Node node, String parentPath, F factory)
052    {
053        super(node, parentPath, factory);
054        _traversableFactory = factory;
055    }
056
057    public boolean hasChild(String name) throws AmetysRepositoryException
058    {
059        return _traversableFactory.hasChild(this, name);
060    }
061
062    @SuppressWarnings("unchecked")
063    public <A extends AmetysObject> A createChild(String name, String type) throws AmetysRepositoryException, RepositoryIntegrityViolationException
064    {
065        return (A) _traversableFactory.createChild(this, name, type);
066    }
067    
068    @SuppressWarnings("unchecked")
069    public <A extends AmetysObject> A getChild(String path) throws AmetysRepositoryException, UnknownAmetysObjectException
070    {
071        return (A) _traversableFactory.getChild(this, path);
072    }
073
074    public <A extends AmetysObject> AmetysObjectIterable<A> getChildren() throws AmetysRepositoryException
075    {
076        return _traversableFactory.getChildren(this);
077    }
078
079    public Map<AnonymousOrAnyConnectedKeys, Set<String>> getProfilesForAnonymousAndAnyConnectedUser()
080    {
081        return ACLJCRAmetysObjectHelper.getProfilesForAnonymousAndAnyConnectedUser(getNode());
082    }
083    
084    public Map<GroupIdentity, Map<UserOrGroup, Set<String>>> getProfilesForGroups(Set<GroupIdentity> groups)
085    {
086        return ACLJCRAmetysObjectHelper.getProfilesForGroups(getNode(), groups);
087    }
088    
089    public Map<UserIdentity, Map<UserOrGroup, Set<String>>> getProfilesForUsers(UserIdentity user)
090    {
091        return ACLJCRAmetysObjectHelper.getProfilesForUsers(getNode(), user);
092    }
093    
094    public void addAllowedProfilesForAnyConnectedUser(Set<String> profileIds)
095    {
096        ACLJCRAmetysObjectHelper.addAllowedProfilesForAnyConnectedUser(getNode(), profileIds);
097    }
098    
099    public void removeAllowedProfilesForAnyConnectedUser(Set<String> profileIds)
100    {
101        ACLJCRAmetysObjectHelper.removeAllowedProfilesForAnyConnectedUser(getNode(), profileIds);
102    }
103    
104    public void addDeniedProfilesForAnyConnectedUser(Set<String> profileIds)
105    {
106        ACLJCRAmetysObjectHelper.addDeniedProfilesForAnyConnectedUser(getNode(), profileIds);
107    }
108    
109    public void removeDeniedProfilesForAnyConnectedUser(Set<String> profileIds)
110    {
111        ACLJCRAmetysObjectHelper.removeDeniedProfilesForAnyConnectedUser(getNode(), profileIds);
112    }
113    
114    public void addAllowedProfilesForAnonymous(Set<String> profileIds)
115    {
116        ACLJCRAmetysObjectHelper.addAllowedProfilesForAnonymous(getNode(), profileIds);
117    }
118    
119    public void removeAllowedProfilesForAnonymous(Set<String> profileIds)
120    {
121        ACLJCRAmetysObjectHelper.removeAllowedProfilesForAnonymous(getNode(), profileIds);
122    }
123    
124    public void addDeniedProfilesForAnonymous(Set<String> profileIds)
125    {
126        ACLJCRAmetysObjectHelper.addDeniedProfilesForAnonymous(getNode(), profileIds);
127    }
128    
129    public void removeDeniedProfilesForAnonymous(Set<String> profileIds)
130    {
131        ACLJCRAmetysObjectHelper.removeDeniedProfilesForAnonymous(getNode(), profileIds);
132    }
133    
134    public void addAllowedUsers(Set<UserIdentity> users, String profileId)
135    {
136        ACLJCRAmetysObjectHelper.addAllowedUsers(users, getNode(), profileId);
137    }
138    
139    public void removeAllowedUsers(Set<UserIdentity> users, String profileId)
140    {
141        ACLJCRAmetysObjectHelper.removeAllowedUsers(users, getNode(), profileId);
142    }
143    
144    public void removeAllowedUsers(Set<UserIdentity> users)
145    {
146        ACLJCRAmetysObjectHelper.removeAllowedUsers(users, getNode());
147    }
148    
149    public void addAllowedGroups(Set<GroupIdentity> groups, String profileId)
150    {
151        ACLJCRAmetysObjectHelper.addAllowedGroups(groups, getNode(), profileId);
152    }
153    
154    public void removeAllowedGroups(Set<GroupIdentity> groups, String profileId)
155    {
156        ACLJCRAmetysObjectHelper.removeAllowedGroups(groups, getNode(), profileId);
157    }
158    
159    public void removeAllowedGroups(Set<GroupIdentity> groups)
160    {
161        ACLJCRAmetysObjectHelper.removeAllowedGroups(groups, getNode());
162    }
163    
164    public void addDeniedUsers(Set<UserIdentity> users, String profileId)
165    {
166        ACLJCRAmetysObjectHelper.addDeniedUsers(users, getNode(), profileId);
167    }
168    
169    public void removeDeniedUsers(Set<UserIdentity> users, String profileId)
170    {
171        ACLJCRAmetysObjectHelper.removeDeniedUsers(users, getNode(), profileId);
172    }
173    
174    public void removeDeniedUsers(Set<UserIdentity> users)
175    {
176        ACLJCRAmetysObjectHelper.removeDeniedUsers(users, getNode());
177    }
178    
179    public void addDeniedGroups(Set<GroupIdentity> groups, String profileId)
180    {
181        ACLJCRAmetysObjectHelper.addDeniedGroups(groups, getNode(), profileId);
182    }
183    
184    public void removeDeniedGroups(Set<GroupIdentity> groups, String profileId)
185    {
186        ACLJCRAmetysObjectHelper.removeDeniedGroups(groups, getNode(), profileId);
187    }
188    
189    public void removeDeniedGroups(Set<GroupIdentity> groups)
190    {
191        ACLJCRAmetysObjectHelper.removeDeniedGroups(groups, getNode());
192    }
193    
194    public boolean isInheritanceDisallowed()
195    {
196        return ACLJCRAmetysObjectHelper.isInheritanceDisallowed(getNode());
197    }
198    
199    public void disallowInheritance(boolean disallow)
200    {
201        ACLJCRAmetysObjectHelper.disallowInheritance(getNode(), disallow);
202    }
203}