public boolean upgradePassword (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid pass"); String passwordHash = u.getPasswordHash(); assertNotNull(passwordHash, "Password is null"); HashVersion v = HashVersion.getVersion(passwordHash); if (v == HashVersion.ZERO && checkV0Password(passwordHash, u.getId(), clearpass)) { setPassword(u, clearpass, null, HashVersion.ONE); return true; } return false; }
@Override public int getItemCount() throws Exception { return (int) DB.exec(db -> { SysConfigManager mgr = new SysConfigManager(db,prefix); return mgr.getItemCount(); }); }
public static <T> T execWithTransaction(DBAction<T> action) throws Exception { try (DB db = new DB()) { db.open(); db.beginTransaction(); T obj = action.exec(db); db.commit(); return obj; } }
private void reset() { try (DB db = new DB()) { SeqNoManager mgr = new SeqNoManager(db); db.open(); db.beginTransaction(); mgr.reset("sync", 0L); db.commit(); } } }
private void ensureOpen() { if (db == null) { db = new DB(); db.open(); mgr = new SysConfigManager(db); } } private void close() {
private Role createRole (DB db, Realm realm, String name, String... permissions) { Role role = new Role(realm, name); Set<Permission> perms = role.getPermissions(); for (String p : permissions) perms.add(Permission.valueOf(p)); db.save(role); return role; } }
public boolean checkPassword (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid pass"); String passwordHash = u.getPasswordHash(); assertNotNull(passwordHash, "Password is null"); HashVersion v = HashVersion.getVersion(passwordHash); assertTrue(v != HashVersion.UNKNOWN, "Unknown password"); switch (v) { case ZERO: return checkV0Password(passwordHash, u.getId(), clearpass); case ONE: return checkV1Password(passwordHash, clearpass); } return false; }
private void setV0Password (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid password"); u.setPasswordHash(HashVersion.ZERO.hash(Long.toString(u.getId()), clearpass, null)); } }
@Override public int getItemCount() throws Exception { return (int) DB.exec(db -> { UserManager mgr = new UserManager(db); return mgr.getItemCount(); }); }
@Override public int getItemCount() throws Exception { return (int) DB.exec(db -> { RoleManager mgr = new RoleManager(db); return mgr.getItemCount(); }); }
public int getItemCount(User user) throws Exception { return DB.exec(db -> { ConsumerManager mgr = new ConsumerManager(db,user); return mgr.getItemCount(); }); }
/** * Synchronous 'reset' * @param id sequencer id * @param value reset value */ public void reset (String id, long value) { getOrCreate(id).setValue(value); }
/** * Synchronous 'next' * @param id sequencer id * @param wrapAt wrap at value * @return next sequencer value */ public long next (String id, long wrapAt) { return getOrCreate(id).next(wrapAt); }
/** * Asynchronous 'next' * * @param id sequencer ID * @param lockedBy unique client identifier (any long, has to be system-wide unique) * @param lockTimeout once lock is obtained, keep it fo 'lockTimeout' millis (if not 'released' earlier) * @param timeout time (in millis) to wait for this lock * @param wrapAt wrap at value * @return next sequencer value * @throws LockTimeoutException if lock can't be obtained after 'timeout' has elapsed */ public long next (String id, long lockedBy, long lockTimeout, long timeout, long wrapAt) { return lock (id, lockedBy, lockTimeout, timeout, seq -> seq.next(wrapAt)); }
public static <T> T execWithTransaction(String configModifier, DBAction<T> action) throws Exception { try (DB db = new DB(configModifier)) { db.open(); db.beginTransaction(); T obj = action.exec(db); db.commit(); return obj; } }
private void setV1Password (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid password"); u.setPasswordHash(HashVersion.ONE.hash(Long.toString(u.getId(),16), clearpass, HashVersion.ONE.getSalt())); }