Search in sources :

Example 21 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class LoginDatabaseTaskTest method testCancel.

public void testCancel() {
    ServerInfo serverInfo = new ServerInfo();
    DatabaseInfo dbInfo = new DatabaseInfo("dbname", serverInfo);
    ServerUserInfo serverUserInfo = new ServerUserInfo();
    List<DatabaseInfo> dbInfoList = new ArrayList<DatabaseInfo>();
    dbInfoList.add(dbInfo);
    serverUserInfo.setDatabaseInfoList(dbInfoList);
    serverInfo.setLoginedUserInfo(serverUserInfo);
    LoginDatabaseTask task = new LoginDatabaseTask(serverInfo);
    task.setDbName("dbname");
    task.cancel();
    assertFalse(serverInfo.getLoginedUserInfo().getDatabaseInfo("dbname").isLogined());
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 22 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class GetCMUserListTask method getServerUserInfoList.

/**
	 * 
	 * Get server user information list
	 * 
	 * @return List<ServerUserInfo> A list stored some instance of
	 *         ServerUserInfo
	 */
public List<ServerUserInfo> getServerUserInfoList() {
    TreeNode response = getResponse();
    if (response == null || (this.getErrorMsg() != null && getErrorMsg().trim().length() > 0)) {
        return null;
    }
    List<ServerUserInfo> serverUserInfoList = new ArrayList<ServerUserInfo>();
    for (int i = 0; i < response.childrenSize(); i++) {
        TreeNode node1 = response.getChildren().get(i);
        if (node1.getValue("open") == null) {
            continue;
        }
        if (node1.getValue("open").trim().equals("dblist")) {
            serverInfo.removeAllDatabase();
            String[] dbNames = node1.getValues("dbname");
            // start
            if (null == dbNames) {
                int length = node1.childrenSize();
                dbNames = new String[length];
                for (int j = 0; j < length; j++) {
                    TreeNode subNode2 = node1.getChildren().get(j);
                    if (subNode2.getValue("open") == null || !subNode2.getValue("open").trim().equals("dbs")) {
                        continue;
                    }
                    dbNames[j] = subNode2.getValue("dbname");
                }
            }
            for (int m = 0; dbNames != null && m < dbNames.length; m++) {
                serverInfo.addDatabase(dbNames[m]);
            }
        } else if (node1.getValue("open").trim().equals("userlist")) {
            buildUserInfo(serverUserInfoList, node1);
        }
    }
    return serverUserInfoList;
}
Also used : TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode) ArrayList(java.util.ArrayList) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 23 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class UserAuthGeneralInfoPage method modifyText.

/**
	 * When modify the page content,check the validation
	 * 
	 * @param event the modify event
	 */
public void modifyText(ModifyEvent event) {
    setErrorMessage(null);
    String userId = userIdText.getText();
    String password = passwordText.getText();
    String passwordConfirm = passwordConfirmText.getText();
    /*For TOOLS-3200: make CM has same verify condition with CMS in CUBRID 9.2*/
    Pattern pattern = Pattern.compile("\\b[a-zA-Z][a-z0-9A-Z_]*\\b");
    Matcher match = pattern.matcher(userId);
    boolean isValidUserId = match.matches();
    if (!isValidUserId) {
        setErrorMessage(Messages.errUserId);
        setPageComplete(false);
        return;
    }
    //For the message limit, We verify it alone
    if (userId.length() < 4 || userId.length() > 32) {
        setErrorMessage(Messages.errUserIdLength);
        setPageComplete(false);
        return;
    }
    boolean isUserExist = false;
    if (userInfo == null && serverUserInfoList != null) {
        for (int i = 0; i < serverUserInfoList.size(); i++) {
            ServerUserInfo user = serverUserInfoList.get(i);
            if (user.getUserName().equals(userId)) {
                isUserExist = true;
                break;
            }
        }
    }
    if (isUserExist) {
        setErrorMessage(Messages.errUserExist);
        setPageComplete(false);
        return;
    }
    boolean isValidPassword = password.indexOf(" ") < 0 && !"admin".equals(password) && password.trim().length() >= 4 && password.trim().length() <= 32;
    if (!isValidPassword) {
        setErrorMessage(Messages.errPassword);
        setPageComplete(false);
        return;
    }
    boolean isEqualPassword = password.equals(passwordConfirm);
    if (!isEqualPassword) {
        setErrorMessage(com.cubrid.cubridmanager.ui.host.Messages.errNotEqualPassword);
        setPageComplete(false);
        return;
    }
    setErrorMessage(null);
    setPageComplete(true);
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 24 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo 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 25 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class UserManagementTableViewerSorter method initialTableModel.

/**
	 * 
	 * Initial the table model of user list table
	 * 
	 */
private void initialTableModel() {
    ServerType serverType = server.getServerInfo().getServerType();
    for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
        ServerUserInfo userInfo = serverUserInfoList.get(i);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("0", userInfo.getUserName());
        if (serverType == ServerType.BOTH) {
            map.put("1", userInfo.getDbCreateAuthType().getText());
            map.put("2", userInfo.getCasAuth().getText());
            map.put("3", userInfo.getStatusMonitorAuth().getText());
            map.put("4", userInfo);
        }
        if (serverType == ServerType.DATABASE) {
            map.put("1", userInfo.getDbCreateAuthType().getText());
            map.put("2", userInfo.getStatusMonitorAuth().getText());
            map.put("3", userInfo);
        } else if (serverType == ServerType.BROKER) {
            map.put("1", userInfo.getCasAuth().getText());
            map.put("2", userInfo.getStatusMonitorAuth().getText());
            map.put("3", userInfo);
        }
        serverUserInfoTableList.add(map);
    }
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) HashMap(java.util.HashMap) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Aggregations

ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)101 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)33 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)23 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)21 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)19 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 ArrayList (java.util.ArrayList)16 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)12 ServerType (com.cubrid.cubridmanager.core.common.model.ServerType)10 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)9 GetCMUserListTask (com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)8 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)8 CubridBrokerFolder (com.cubrid.cubridmanager.ui.spi.model.CubridBrokerFolder)8 Map (java.util.Map)8 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)7 ITask (com.cubrid.common.core.task.ITask)6 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)6 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)6 GetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask)6