Concrete implementation of the UserDatabase interface that considers all directories in a specified base directory to be "home" directories for those users.
| 27 | * directory to be "home" directories for those users. |
| 28 | */ |
| 29 | public final class HomesUserDatabase implements UserDatabase { |
| 30 | |
| 31 | /** |
| 32 | * Constructs a new HomesUserDatabase. |
| 33 | */ |
| 34 | public HomesUserDatabase() { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * The set of home directories for all defined users, keyed by username. |
| 39 | */ |
| 40 | private final Map<String,String> homes = new HashMap<>(); |
| 41 | |
| 42 | /** |
| 43 | * The UserConfig listener with which we are associated. |
| 44 | */ |
| 45 | private UserConfig userConfig = null; |
| 46 | |
| 47 | |
| 48 | @Override |
| 49 | public UserConfig getUserConfig() { |
| 50 | return this.userConfig; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | @Override |
| 55 | public void setUserConfig(UserConfig userConfig) { |
| 56 | this.userConfig = userConfig; |
| 57 | init(); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | @Override |
| 62 | public String getHome(String user) { |
| 63 | return homes.get(user); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | @Override |
| 68 | public Enumeration<String> getUsers() { |
| 69 | return Collections.enumeration(homes.keySet()); |
| 70 | } |
| 71 | |
| 72 | |
| 73 | /** |
| 74 | * Initialize our set of users and home directories. |
| 75 | */ |
| 76 | private void init() { |
| 77 | |
| 78 | String homeBase = userConfig.getHomeBase(); |
| 79 | File homeBaseDir = new File(homeBase); |
| 80 | if (!homeBaseDir.exists() || !homeBaseDir.isDirectory()) { |
| 81 | return; |
| 82 | } |
| 83 | String[] homeBaseFiles = homeBaseDir.list(); |
| 84 | if (homeBaseFiles == null) { |
| 85 | return; |
| 86 | } |
nothing calls this directly
no outgoing calls
no test coverage detected