Exemple #1
0
 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();
 }
Exemple #2
0
 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();
 }
Exemple #3
0
 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();
   }
 }
Exemple #4
0
 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();
   }
 }