public static void changePasswordCurrentUser(String newPassword) { ODatabaseRecordTx db = DbHelper.getConnection(); String username = db.getUser().getName(); db = DbHelper.reconnectAsAdmin(); db.getMetadata().getSecurity().getUser(username).setPassword(newPassword).save(); // DbHelper.removeConnectionFromPool(); }
public static void changePassword(String username, String newPassword) throws SqlInjectionException, UserNotFoundException { ODatabaseRecordTx db = DbHelper.getConnection(); db = DbHelper.reconnectAsAdmin(); UserDao udao = UserDao.getInstance(); ODocument user = udao.getByUserName(username); if (user == null) { if (Logger.isDebugEnabled()) Logger.debug("User " + username + " does not exist"); throw new UserNotFoundException("User " + username + " does not exist"); } db.getMetadata().getSecurity().getUser(username).setPassword(newPassword).save(); }
public static void addUserToRole(String username, String role) { boolean admin = true; if (!DbHelper.currentUsername().equals(BBConfiguration.getBaasBoxAdminUsername())) { DbHelper.reconnectAsAdmin(); admin = false; } String sqlAdd = "update ouser add roles = {TO_ROLE} where name = ?"; ORole toRole = RoleDao.getRole(role); ORID toRID = toRole.getDocument().getRecord().getIdentity(); sqlAdd = sqlAdd.replace("{TO_ROLE}", toRID.toString()); GenericDao.getInstance().executeCommand(sqlAdd, new String[] {username}); if (!admin) { DbHelper.reconnectAsAuthenticatedUser(); } }
public static void removeUserFromRole(String username, String role) { boolean admin = false; if (!DbHelper.currentUsername().equals(BBConfiguration.getBaasBoxAdminUsername())) { DbHelper.reconnectAsAdmin(); admin = true; } String sqlRemove = "update ouser remove roles = {FROM_ROLE} where roles contains {FROM_ROLE} and name = ?"; ORole fromRole = RoleDao.getRole(role); ORID fromRID = fromRole.getDocument().getRecord().getIdentity(); sqlRemove = sqlRemove.replace("{FROM_ROLE}", fromRID.toString()); GenericDao.getInstance().executeCommand(sqlRemove, new String[] {username}); if (admin) { DbHelper.reconnectAsAuthenticatedUser(); } }