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  /**
14   * @deprecated since 2.2 because it should not be used in production. Will be moved to test code in 3.0.
15   */
16  public class MemoryUserManagerReadOnly extends ReadOnlyUserManager implements UserManager
17  {
18      private final RepositoryIdentifier repository;
19      private final MemoryProvider provider;
20      private final PasswordEncryptor encryptor;
21  
22      public MemoryUserManagerReadOnly(RepositoryIdentifier repository, MemoryProvider provider, PasswordEncryptor passwordEncryptor)
23      {
24          this.repository = repository;
25          this.provider = provider;
26          this.encryptor = passwordEncryptor;
27      }
28  
29      /**
30       * @return a {@link PasswordEncryptor} which handles the encrypytion of passwords for users managed by this object.
31       */
32      public PasswordEncryptor getPasswordEncryptor(User user) throws EntityException
33      {
34          if (getUser(user.getName()) != null)
35              return encryptor;
36  
37          return null;
38      }
39  
40      public Pager<User> getUsers()
41       {
42           return provider.getUsers();
43       }
44  
45       public Pager<String> getUserNames() throws EntityException
46       {
47           return provider.getUserNames();
48       }
49  
50       public User getUser(String username)
51       {
52           return provider.getUser(username);
53       }
54  
55      /**
56       * @return the {@link RepositoryIdentifier} which is managed by this instance.
57       */
58      public RepositoryIdentifier getIdentifier()
59      {
60          return repository;
61      }
62  
63      /**
64       * @return the {@link RepositoryIdentifier} in which the entity is stored, otherwise null.
65       */
66      public RepositoryIdentifier getRepository(Entity entity) throws EntityException
67      {
68          if (getUser(entity.getName()) != null)
69              return repository;
70  
71          return null;
72      }
73  }