View Javadoc

1   package com.atlassian.user.impl.memory;
2   
3   import com.atlassian.user.Entity;
4   import com.atlassian.user.EntityException;
5   import com.atlassian.user.User;
6   import com.atlassian.user.UserManager;
7   import com.atlassian.user.impl.ReadOnlyUserManager;
8   import com.atlassian.user.impl.memory.provider.MemoryProvider;
9   import com.atlassian.user.repository.RepositoryIdentifier;
10  import com.atlassian.user.search.page.Pager;
11  import com.atlassian.user.security.password.PasswordEncryptor;
12  
13  public class MemoryUserManagerReadOnly extends ReadOnlyUserManager implements UserManager
14  {
15      private final RepositoryIdentifier repository;
16      private final MemoryProvider provider;
17      private final PasswordEncryptor encryptor;
18  
19      public MemoryUserManagerReadOnly(RepositoryIdentifier repository, MemoryProvider provider, PasswordEncryptor passwordEncryptor)
20      {
21          this.repository = repository;
22          this.provider = provider;
23          this.encryptor = passwordEncryptor;
24      }
25  
26      /**
27       * @return a {@link PasswordEncryptor} which handles the encrypytion of passwords for users managed by this object.
28       */
29      public PasswordEncryptor getPasswordEncryptor(User user) throws EntityException
30      {
31          if (getUser(user.getName()) != null)
32              return encryptor;
33  
34          return null;
35      }
36  
37      public Pager<User> getUsers()
38       {
39           return provider.getUsers();
40       }
41  
42       public Pager<String> getUserNames() throws EntityException
43       {
44           return provider.getUserNames();
45       }
46  
47       public User getUser(String username)
48       {
49           return provider.getUser(username);
50       }
51  
52      /**
53       * @return the {@link RepositoryIdentifier} which is managed by this instance.
54       */
55      public RepositoryIdentifier getIdentifier()
56      {
57          return repository;
58      }
59  
60      /**
61       * @return the {@link RepositoryIdentifier} in which the entity is stored, otherwise null.
62       */
63      public RepositoryIdentifier getRepository(Entity entity) throws EntityException
64      {
65          if (getUser(entity.getName()) != null)
66              return repository;
67  
68          return null;
69      }
70  }