1 package com.atlassian.user.configuration;
2
3 import com.atlassian.user.GroupManager;
4 import com.atlassian.user.UserManager;
5 import com.atlassian.user.impl.delegation.DelegatingGroupManager;
6 import com.atlassian.user.impl.delegation.DelegatingUserManager;
7 import com.atlassian.user.impl.delegation.properties.DelegatingPropertySetFactory;
8 import com.atlassian.user.impl.delegation.search.query.DelegatingEntityQueryParser;
9 import com.atlassian.user.impl.delegation.security.authentication.DelegatingAuthenticator;
10 import com.atlassian.user.properties.PropertySetFactory;
11 import com.atlassian.user.repository.DefaultRepositoryIdentifier;
12 import com.atlassian.user.repository.RepositoryIdentifier;
13 import com.atlassian.user.search.query.EntityQueryParser;
14 import com.atlassian.user.security.authentication.Authenticator;
15
16 import java.util.*;
17
18 public class DefaultDelegationAccessor implements DelegationAccessor
19 {
20 private Map<RepositoryIdentifier, RepositoryAccessor> repositoryAccessors = new HashMap<RepositoryIdentifier, RepositoryAccessor>();
21 private List<RepositoryIdentifier> delegationOrder = new ArrayList<RepositoryIdentifier>();
22
23 private DelegatingAuthenticator delegatingAuthenticator;
24 private DelegatingGroupManager delegatingGroupManager;
25 private DelegatingPropertySetFactory delegatingPropertySetFactory;
26 private DelegatingUserManager delegatingUserManager;
27 private DelegatingEntityQueryParser delegatingEntityQueryParser;
28
29 private List<Authenticator> authenticators = new ArrayList<Authenticator>();
30 private List<UserManager> userManagers = new ArrayList<UserManager>();
31 private List<GroupManager> groupManagers = new ArrayList<GroupManager>();
32 private List<PropertySetFactory> propertySetFactories = new ArrayList<PropertySetFactory>();
33 private List<EntityQueryParser> entityQueryParsers = new ArrayList<EntityQueryParser>();
34
35 public DefaultDelegationAccessor()
36 {
37 }
38
39 public DefaultDelegationAccessor(List<RepositoryAccessor>
40 {
41 for (Iterator<RepositoryAccessor> iterator = repositoryAccessors.iterator(); iterator.hasNext();)
42 {
43 RepositoryAccessor accessor = iterator.next();
44 addRepositoryAccessor(accessor);
45 }
46 }
47
48 public RepositoryIdentifier getIdentifier()
49 {
50 return new DefaultRepositoryIdentifier("delegatingRepository", "Delegating Repository");
51 }
52
53 public UserManager getUserManager()
54 {
55 return delegatingUserManager;
56 }
57
58 public GroupManager getGroupManager()
59 {
60 return delegatingGroupManager;
61 }
62
63 public PropertySetFactory getPropertySetFactory()
64 {
65 return delegatingPropertySetFactory;
66 }
67
68 public Authenticator getAuthenticator()
69 {
70 return delegatingAuthenticator;
71 }
72
73 public EntityQueryParser getEntityQueryParser()
74 {
75 return delegatingEntityQueryParser;
76 }
77
78 public RepositoryAccessor getRepositoryAccessor(String key)
79 {
80 for (Iterator<RepositoryIdentifier> it = repositoryAccessors.keySet().iterator(); it.hasNext();)
81 {
82 RepositoryIdentifier identifier = it.next();
83 if (identifier.getKey().equals(key))
84 return repositoryAccessors.get(identifier);
85 }
86 return null;
87 }
88
89 public List getRepositoryAccessors()
90 {
91 List<RepositoryAccessor> result = new LinkedList<RepositoryAccessor>();
92 for (Iterator<RepositoryIdentifier> it = delegationOrder.iterator(); it.hasNext();)
93 {
94 RepositoryIdentifier identifier = it.next();
95 result.add(repositoryAccessors.get(identifier));
96 }
97 return result;
98 }
99
100 public void addRepositoryAccessor(RepositoryAccessor accessor)
101 {
102 repositoryAccessors.put(accessor.getIdentifier(), accessor);
103 delegationOrder.add(accessor.getIdentifier());
104
105 if (accessor.getAuthenticator() != null) authenticators.add(accessor.getAuthenticator());
106 if (accessor.getUserManager() != null) userManagers.add(accessor.getUserManager());
107 if (accessor.getGroupManager() != null) groupManagers.add(accessor.getGroupManager());
108 if (accessor.getPropertySetFactory() != null) propertySetFactories.add(accessor.getPropertySetFactory());
109 if (accessor.getEntityQueryParser() != null) entityQueryParsers.add(accessor.getEntityQueryParser());
110
111 delegatingUserManager = new DelegatingUserManager(userManagers);
112 delegatingAuthenticator = new DelegatingAuthenticator(delegatingUserManager, authenticators);
113 delegatingPropertySetFactory = new DelegatingPropertySetFactory(propertySetFactories);
114 delegatingGroupManager = new DelegatingGroupManager(groupManagers);
115 delegatingEntityQueryParser = new DelegatingEntityQueryParser(entityQueryParsers);
116 }
117 }