Search in sources :

Example 1 with UpdateCMUserTask

use of com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask in project cubrid-manager by CUBRID.

the class SetupEnvTestCase method loginTestDatabase.

protected void loginTestDatabase() {
    if (databaseInfo.isLogined()) {
        return;
    }
    LoginDatabaseTask loginDatabaseTask = new LoginDatabaseTask(serverInfo);
    loginDatabaseTask.setCMUser(userName);
    loginDatabaseTask.setDbName(testDbName);
    loginDatabaseTask.setDbUser(dbaUserName);
    loginDatabaseTask.setDbPassword(dbaPassword);
    loginDatabaseTask.execute();
    assertEquals(null, loginDatabaseTask.getErrorMsg());
    DbUserInfo dbUserInfo = loginDatabaseTask.getLoginedDbUserInfo();
    dbUserInfo.setNoEncryptPassword(dbaPassword);
    databaseInfo.setLogined(true);
    databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
    UpdateCMUserTask updateCMUserTask = new UpdateCMUserTask(serverInfo);
    updateCMUserTask.setCmUserName(userName);
    ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
    updateCMUserTask.setCasAuth(userInfo.getCasAuth().getText());
    updateCMUserTask.setDbCreator(userInfo.getDbCreateAuthType().getText());
    updateCMUserTask.setStatusMonitorAuth(userInfo.getStatusMonitorAuth().getText());
    List<String> dbNameList = new ArrayList<String>();
    List<String> dbUserList = new ArrayList<String>();
    List<String> dbPasswordList = new ArrayList<String>();
    List<String> dbBrokerPortList = new ArrayList<String>();
    List<DatabaseInfo> authDatabaseList = userInfo.getDatabaseInfoList();
    if (authDatabaseList != null && !authDatabaseList.isEmpty()) {
        int size = authDatabaseList.size();
        for (int i = 0; i < size; i++) {
            DatabaseInfo databaseInfo = authDatabaseList.get(i);
            dbNameList.add(databaseInfo.getDbName());
            dbUserList.add(databaseInfo.getAuthLoginedDbUserInfo().getName());
            dbBrokerPortList.add(databaseInfo.getBrokerIP() + "," + databaseInfo.getBrokerPort());
            String password = databaseInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
            dbPasswordList.add(password == null ? "" : password);
        }
    }
    String[] dbNameArr = new String[dbNameList.size()];
    String[] dbUserArr = new String[dbUserList.size()];
    String[] dbPasswordArr = new String[dbPasswordList.size()];
    String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
    updateCMUserTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
    updateCMUserTask.execute();
    assertEquals(null, updateCMUserTask.getErrorMsg());
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) LoginDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) ArrayList(java.util.ArrayList) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 2 with UpdateCMUserTask

use of com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask in project cubrid-manager by CUBRID.

the class LoginDatabaseTaskExecutor method exec.

/**
	 * Execute to login database
	 * 
	 * @param monitor the IProgressMonitor
	 * @return <code>true</code> if successful;<code>false</code>otherwise;
	 */
public boolean exec(final IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return false;
    }
    String taskName = Messages.bind(Messages.loginDbTaskName, dbName);
    monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
    DbUserInfo dbUserInfo = null;
    DatabaseInfo dbInfo = serverInfo.getLoginedUserInfo().getDatabaseInfo(dbName);
    DbUserInfo preDbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
    boolean isOldLogined = dbInfo.isLogined();
    for (ITask task : taskList) {
        if (task instanceof UpdateCMUserTask) {
            UpdateCMUserTask updateCMUserTask = (UpdateCMUserTask) task;
            ServerInfo serverInfo = dbInfo.getServerInfo();
            if (serverInfo != null && serverInfo.isConnected()) {
                ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
                updateCMUserTask.setCasAuth(userInfo.getCasAuth().getText());
                updateCMUserTask.setDbCreator(userInfo.getDbCreateAuthType().getText());
                updateCMUserTask.setStatusMonitorAuth(userInfo.getStatusMonitorAuth().getText());
                List<String> dbNameList = new ArrayList<String>();
                List<String> dbUserList = new ArrayList<String>();
                List<String> dbPasswordList = new ArrayList<String>();
                List<String> dbBrokerPortList = new ArrayList<String>();
                List<DatabaseInfo> authDatabaseList = userInfo.getDatabaseInfoList();
                for (int i = 0; authDatabaseList != null && i < authDatabaseList.size(); i++) {
                    DatabaseInfo databaseInfo = authDatabaseList.get(i);
                    dbNameList.add(databaseInfo.getDbName());
                    dbUserList.add(databaseInfo.getAuthLoginedDbUserInfo().getName());
                    dbBrokerPortList.add(QueryOptions.getBrokerIp(databaseInfo) + "," + databaseInfo.getBrokerPort());
                    String password = databaseInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
                    dbPasswordList.add(password == null ? "" : password);
                }
                String[] dbNameArr = new String[dbNameList.size()];
                String[] dbUserArr = new String[dbUserList.size()];
                String[] dbPasswordArr = new String[dbPasswordList.size()];
                String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
                updateCMUserTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
            }
        }
        task.execute();
        final String msg = task.getErrorMsg();
        if (showErrMsg) {
            if (openErrorBox(shell, msg, monitor)) {
                dbInfo.setLogined(isOldLogined);
                dbInfo.setAuthLoginedDbUserInfo(preDbUserInfo);
                //					LOGGER.error("loggin failed task : " + infoMessage);
                return false;
            }
        } else if (!monitor.isCanceled()) {
            setErrMsg(msg);
            dbInfo.setLogined(isOldLogined);
            dbInfo.setAuthLoginedDbUserInfo(preDbUserInfo);
            return false;
        }
        if (monitor.isCanceled()) {
            return false;
        }
        if (task instanceof LoginDatabaseTask) {
            dbUserInfo = ((LoginDatabaseTask) task).getLoginedDbUserInfo();
            dbInfo.setLogined(true);
            dbUserInfo.setNoEncryptPassword(dbPassword);
            dbInfo.setAuthLoginedDbUserInfo(dbUserInfo);
        }
    }
    return true;
}
Also used : ITask(com.cubrid.common.core.task.ITask) LoginDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 3 with UpdateCMUserTask

use of com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask in project cubrid-manager by CUBRID.

the class UserManagementWizard method performFinish.

/**
	 * Called when user clicks Finish
	 * 
	 * @return boolean
	 */
public boolean performFinish() {
    final String userId = generalInfoPage.getUserId();
    final String password = generalInfoPage.getPassword();
    final String dbCreationAuth = generalInfoPage.getDbCreationAuth();
    final String brokerAuth = generalInfoPage.getBrokerAuth();
    final String statusMonitorAuth = generalInfoPage.getStatusMonitorAuth();
    final List<DatabaseInfo> authDatabaselist = new ArrayList<DatabaseInfo>();
    final Shell shell = getShell();
    final String taskName = Messages.bind(Messages.updateUserTaskName, userId);
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(shell, msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
            }
            ServerUserInfo loginedUserInfo = server.getServerInfo().getLoginedUserInfo();
            if (userInfo == null) {
                userInfo = new ServerUserInfo(userId, password);
            } else {
                userInfo.setPassword(password);
            }
            if (userInfo.getUserName().equals(loginedUserInfo.getUserName())) {
                loginedUserInfo.setPassword(password);
            }
            if (!userInfo.isAdmin()) {
                if (dbCreationAuth.equals(DbCreateAuthType.AUTH_NONE.getText())) {
                    userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_NONE);
                } else if (dbCreationAuth.equals(DbCreateAuthType.AUTH_ADMIN.getText())) {
                    userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_ADMIN);
                }
                if (brokerAuth.equals(CasAuthType.AUTH_NONE.getText())) {
                    userInfo.setCasAuth(CasAuthType.AUTH_NONE);
                } else if (brokerAuth.equals(CasAuthType.AUTH_ADMIN.getText())) {
                    userInfo.setCasAuth(CasAuthType.AUTH_ADMIN);
                } else if (brokerAuth.equals(CasAuthType.AUTH_MONITOR.getText())) {
                    userInfo.setCasAuth(CasAuthType.AUTH_MONITOR);
                }
                if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_NONE.getText())) {
                    userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_NONE);
                } else if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_ADMIN.getText())) {
                    userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_ADMIN);
                } else if (statusMonitorAuth.equals(StatusMonitorAuthType.AUTH_MONITOR.getText())) {
                    userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_MONITOR);
                }
                userInfo.removeAllDatabaseInfo();
                userInfo.setDatabaseInfoList(authDatabaselist);
            }
            return true;
        }
    };
    if (userInfo != null && userInfo.isAdmin()) {
        ChangeCMUserPasswordTask changeCMUserPasswordTask = new ChangeCMUserPasswordTask(server.getServerInfo());
        changeCMUserPasswordTask.setUserName(userId);
        changeCMUserPasswordTask.setPassword(password);
        taskExcutor.addTask(changeCMUserPasswordTask);
    } else if (userInfo != null && !userInfo.isAdmin()) {
        DeleteCMUserTask deleteCMUserTask = new DeleteCMUserTask(server.getServerInfo());
        deleteCMUserTask.setUserId(userId);
        taskExcutor.addTask(deleteCMUserTask);
    }
    if (userInfo == null || !userInfo.isAdmin()) {
        AddCMUserTask addCMUserTask = new AddCMUserTask(server.getServerInfo());
        addCMUserTask.setUserId(userId);
        addCMUserTask.setPassword(password);
        addCMUserTask.setDbcreate(dbCreationAuth);
        addCMUserTask.setCasAuth(brokerAuth);
        addCMUserTask.setStautsMonitorAuth(statusMonitorAuth);
        taskExcutor.addTask(addCMUserTask);
    }
    ServerType serverType = server.getServerInfo().getServerType();
    if ((userInfo == null || !userInfo.isAdmin()) && (serverType == ServerType.BOTH || serverType == ServerType.DATABASE)) {
        List<Map<String, Object>> dbAuthInfoList = authDbInfoPage.getDbAuthInfoList();
        List<String> dbNameList = new ArrayList<String>();
        List<String> dbUserList = new ArrayList<String>();
        List<String> dbPasswordList = new ArrayList<String>();
        List<String> dbBrokerPortList = new ArrayList<String>();
        if (dbAuthInfoList != null && !dbAuthInfoList.isEmpty()) {
            int size = dbAuthInfoList.size();
            for (int i = 0; i < size; i++) {
                Map<String, Object> map = dbAuthInfoList.get(i);
                String allowConnectedStr = (String) map.get("1");
                if ("Yes".equals(allowConnectedStr)) {
                    String dbName = (String) map.get("0");
                    dbNameList.add(dbName);
                    String dbUser = (String) map.get("2");
                    dbUserList.add(dbUser);
                    String brokerIP = (String) map.get("3");
                    String brokerPort = (String) map.get("4");
                    String port = "";
                    if (brokerPort.matches("^\\d+$")) {
                        port = brokerPort;
                    } else {
                        port = brokerPort.substring(brokerPort.indexOf("[") + 1, brokerPort.indexOf("/"));
                    }
                    dbBrokerPortList.add(brokerIP + "," + port);
                    dbPasswordList.add("");
                    DatabaseInfo databaseInfo = new DatabaseInfo(dbName, server.getServerInfo());
                    databaseInfo.setBrokerPort(brokerPort);
                    databaseInfo.setBrokerIP(brokerIP);
                    DbUserInfo dbUserInfo = new DbUserInfo();
                    dbUserInfo.setName(dbUser);
                    databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
                    authDatabaselist.add(databaseInfo);
                }
            }
        }
        String[] dbNameArr = new String[dbNameList.size()];
        String[] dbUserArr = new String[dbUserList.size()];
        String[] dbPasswordArr = new String[dbPasswordList.size()];
        String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
        UpdateCMUserTask updateTask = new UpdateCMUserTask(server.getServerInfo());
        updateTask.setCmUserName(userId);
        updateTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
        updateTask.setCasAuth(brokerAuth);
        updateTask.setDbCreator(dbCreationAuth);
        updateTask.setStatusMonitorAuth(statusMonitorAuth);
        taskExcutor.addTask(updateTask);
    }
    new ExecTaskWithProgress(taskExcutor).exec(true, true);
    return taskExcutor.isSuccess();
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ChangeCMUserPasswordTask(com.cubrid.cubridmanager.core.common.task.ChangeCMUserPasswordTask) ArrayList(java.util.ArrayList) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DeleteCMUserTask(com.cubrid.cubridmanager.core.common.task.DeleteCMUserTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) Map(java.util.Map) AddCMUserTask(com.cubrid.cubridmanager.core.common.task.AddCMUserTask)

Example 4 with UpdateCMUserTask

use of com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask in project cubrid-manager by CUBRID.

the class FinishTask method initTask.

public void initTask(ServerInfo serverInfo) {
    MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
    GetEnvInfoTask getEnvInfoTask = new GetEnvInfoTask(serverInfo);
    GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
    GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo);
    CommonQueryTask<BrokerInfos> getBrokerTask = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), new BrokerInfos());
    GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo);
    UpdateCMUserTask updateTask = new UpdateCMUserTask(serverInfo);
    updateTask.setCmUserName(serverInfo.getUserName());
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
    addTask(monitoringTask);
    addTask(getEnvInfoTask);
    addTask(getDatabaseListTask);
    addTask(getCMConfParameterTask);
    addTask(getBrokerTask);
    addTask(getUserInfoTask);
    addTask(updateTask);
    addTask(getCubridConfParameterTask);
    addTask(getBrokerConfParameterTask);
    addTask(new FinishTask());
}
Also used : GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask)

Example 5 with UpdateCMUserTask

use of com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask in project cubrid-manager by CUBRID.

the class ConnectHostExecutor method initTasks.

private void initTasks() {
    MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
    addTask(monitoringTask);
    GetEnvInfoTask getEnvInfoTask = new GetEnvInfoTask(serverInfo);
    addTask(getEnvInfoTask);
    GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
    addTask(getDatabaseListTask);
    GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo);
    addTask(getCMConfParameterTask);
    CommonQueryTask<BrokerInfos> getBrokerTask = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), new BrokerInfos());
    addTask(getBrokerTask);
    GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo);
    addTask(getUserInfoTask);
    UpdateCMUserTask updateTask = new UpdateCMUserTask(serverInfo);
    updateTask.setCmUserName(serverInfo.getUserName());
    addTask(updateTask);
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    addTask(getCubridConfParameterTask);
    GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
    addTask(getBrokerConfParameterTask);
}
Also used : GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask)

Aggregations

UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)15 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)13 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)12 ArrayList (java.util.ArrayList)12 GetCMUserListTask (com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)7 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)7 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)7 ITask (com.cubrid.common.core.task.ITask)6 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)5 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)5 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)5 GetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask)5 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)5 GetEnvInfoTask (com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask)5 LoginDatabaseTask (com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask)5 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)5 ServerType (com.cubrid.cubridmanager.core.common.model.ServerType)4 List (java.util.List)4 Map (java.util.Map)4 EnvInfo (com.cubrid.cubridmanager.core.common.model.EnvInfo)3