/** * Returns a collection of passwords. This collection is used for managing * secure credentials. * * @param args Collection arguments that specify the number of entities to * return and how to sort them. See {@link CollectionArgs}. * @return A collection of passwords. */ public PasswordCollection getPasswords(Args args) { return new PasswordCollection(this, args); }
@Override public Password remove(String key) { // Make it compatible with the old way (low-efficient) if (!key.contains(":")) { Password password = getByUsername((String) key); validate(); if (password == null) return null; password.remove(); // by invalidating any access to items will get refreshed invalidate(); return password; } return super.remove(key); }
@Override public boolean containsKey(Object key) { if (key instanceof String && !((String) key).contains(":")) { return getByUsername((String) key) != null; } return super.containsKey(key); }
/** * Creates a credential with a username and password. * * @param name The username. * @param password The password. * * @return The new credential. */ public Password create(String name, String password) { Args args = new Args("password", password); return create(name, args); }
private Password getByUsername(String name) { for (Password password : this.values()) { if (password.getUsername().equals(name)) return password; } return null; } }
@Override public Password get(Object key) { // Make it compatible with the old way (low-efficient) if (key instanceof String && !((String) key).contains(":")) { return getByUsername((String) key); } return super.get(key); }
/** * Creates a credential with a username, password, and realm. * * @param name The username. * @param password The password. * @param realm The credential realm. * @return The new credential. */ public Password create(String name, String password, String realm) { Args args = new Args(); args.put("password", password); args.put("realm", realm); return create(name, args); }