Concrete implementation of the UserDatabase interface that processes the /etc/passwd file on a Unix system.
| 32 | * on a Unix system. |
| 33 | */ |
| 34 | public final class PasswdUserDatabase implements UserDatabase { |
| 35 | |
| 36 | private static final Log log = LogFactory.getLog(PasswdUserDatabase.class); |
| 37 | private static final StringManager sm = StringManager.getManager(PasswdUserDatabase.class); |
| 38 | |
| 39 | |
| 40 | /** |
| 41 | * Construct a new {@code PasswdUserDatabase} instance. |
| 42 | */ |
| 43 | public PasswdUserDatabase() { |
| 44 | // NO-OP |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * The pathname of the Unix password file. |
| 49 | */ |
| 50 | private static final String PASSWORD_FILE = "/etc/passwd"; |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * The set of home directories for all defined users, keyed by username. |
| 55 | */ |
| 56 | private final Map<String,String> homes = new HashMap<>(); |
| 57 | |
| 58 | |
| 59 | /** |
| 60 | * The UserConfig listener with which we are associated. |
| 61 | */ |
| 62 | private UserConfig userConfig = null; |
| 63 | |
| 64 | |
| 65 | @Override |
| 66 | public UserConfig getUserConfig() { |
| 67 | return userConfig; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | @Override |
| 72 | public void setUserConfig(UserConfig userConfig) { |
| 73 | this.userConfig = userConfig; |
| 74 | init(); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | @Override |
| 79 | public String getHome(String user) { |
| 80 | return homes.get(user); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | @Override |
| 85 | public Enumeration<String> getUsers() { |
| 86 | return Collections.enumeration(homes.keySet()); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | /** |
| 91 | * Initialize our set of users and home directories. |
nothing calls this directly
no test coverage detected