Search in sources :

Example 61 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class EditUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    EditUserDialog dlg = new EditUserDialog(shell);
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(false);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        if (database.getServer() != null) {
            persisteManager.updateDBPassword(database.getServer().getServerName(), database.getServer().getHostAddress(), database.getServer().getMonPort(), database.getDatabaseInfo().getDbName(), database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName(), dlg.getInputtedPassword(), database.isAutoSavePassword());
        }
        CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
        if (navigationView != null) {
            TreeViewer treeViewer = navigationView.getViewer();
            if (treeViewer != null) {
                DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
                if (userInfo != null && userInfo.getName().equalsIgnoreCase(node.getName())) {
                    CommonUITool.openInformationBox(Messages.titleLogout, Messages.msgLogoutInfomation);
                    database.setLogined(false);
                    database.setAutoSavePassword(false);
                    CubridNodeChangedEvent event = new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_LOGOUT);
                    CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                    database.removeAllChild();
                    treeViewer.refresh(database, true);
                } else {
                    CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                    setEnabled(false);
                }
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
        persisteManager.savaAllServers();
        persisteManager.saveAllGroupNodes();
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 62 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class EditUserDialog method initial.

/**
	 * Initial data
	 */
private void initial() {
    if (!CubridDatabase.hasValidDatabaseInfo(database)) {
        LOGGER.error("The database is invalid.");
        return;
    }
    this.currentUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    currentUserAuthorizations = currentUserInfo.getUserAuthorizations();
    for (DbUserInfo userInfo : userListInfo.getUserList()) {
        if (userInfo.getName().equals(currentUserInfo.getName())) {
            currentUserInfo = userInfo;
            currentUserAuthorizations = currentUserInfo.getUserAuthorizations();
            break;
        }
    }
    List<String> groupList = null;
    if (newFlag) {
        userNameText.setEnabled(true);
        classGrantMap = new HashMap<String, ClassAuthorizations>();
        Map<String, String> map = new HashMap<String, String>();
        map.put("0", DB_DEFAULT_USERNAME);
        groupList = new ArrayList<String>();
        groupList.add(DB_DEFAULT_USERNAME);
    } else {
        for (DbUserInfo bean : userListInfo.getUserList()) {
            if (bean.getName().equalsIgnoreCase(userName)) {
                userInfo = bean;
            }
            List<String> groups = bean.getGroups().getGroup();
            if (groups != null) {
                for (String g : groups) {
                    if (userName != null && userName.equalsIgnoreCase(g)) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("0", bean.getName());
                        memberListData.add(map);
                    }
                }
            }
        }
        memberTableViewer.refresh();
        if (database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) || database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(DB_DBA_USERNAME)) {
            changePwdBtn.setEnabled(true);
        } else {
            changePwdBtn.setEnabled(false);
        }
        userNameText.setText(userInfo.getName());
        groupList = userInfo.getGroups().getGroup();
        classGrantMap = userInfo.getUserAuthorizations();
        oldLoginPassword = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword();
        if (oldLoginPassword == null) {
            oldLoginPassword = "";
        }
    }
    Map<String, String> groupMap = new HashMap<String, String>();
    Map<String, String> memberMap = new HashMap<String, String>();
    // set group map
    if (groupList == null) {
        groupList = new ArrayList<String>();
    }
    for (String group : groupList) {
        groupMap.put(group.toLowerCase(Locale.getDefault()), "");
    }
    if (memberListData != null) {
        for (Map<String, String> map : memberListData) {
            memberMap.put(map.get("0").toLowerCase(Locale.getDefault()), "");
        }
    }
    for (DbUserInfo user : userListInfo.getUserList()) {
        if (!groupMap.containsKey(user.getName().toLowerCase()) && !memberMap.containsKey(user.getName().toLowerCase()) && !user.getName().equalsIgnoreCase(userName)) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", user.getName().toLowerCase());
            allUserListData.add(map);
        }
    }
    for (String userName : groupList) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("0", userName.toLowerCase(Locale.getDefault()));
        groupListData.add(map);
    }
    allUserTableViewer.refresh();
    groupTableViewer.refresh();
    Iterator<String> authIter = classGrantMap.keySet().iterator();
    while (authIter.hasNext()) {
        String className = authIter.next();
        if (!partitionClassMap.containsKey(className)) {
            authListData.add(getItemAuthMap(classGrantMap.get(className)));
            authListDataOld.add(getItemAuthMap(classGrantMap.get(className)));
        }
    }
    if (!DB_DBA_USERNAME.equalsIgnoreCase(userName) && !isDBAGroup()) {
        authTableViewer.refresh();
        for (ClassInfo bean : allClassInfoList) {
            if (classGrantMap.containsKey(bean.getClassName()) || bean.isSystemClass() || bean.getOwnerName().equalsIgnoreCase(DB_DEFAULT_USERNAME)) {
                continue;
            }
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", bean.getClassName());
            map.put("1", Messages.msgUserSchema);
            map.put("2", bean.getOwnerName());
            map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
            classListData.add(map);
        }
        classTableViewer.refresh();
        packTable(classTable);
        packTable(authTable);
    }
    packTable(allUserTable);
    packTable(userGroupTable);
    packTable(memberTableViewer.getTable());
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) HashMap(java.util.HashMap) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 63 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class AddUserAction method doRun.

/**
	 * Perform do run
	 *
	 * @param node
	 */
public void doRun(ISchemaNode node) {
    // FIXME move this logic to core module
    CubridDatabase database = node.getDatabase();
    //		if (database.getDatabaseInfo().isHAMode()) {
    //			CommonUITool.openErrorBox(Messages.errNoSupportInHA);
    //			return;
    //		}
    String childId = database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridNodeLoader.USERS_FOLDER_ID;
    ICubridNode folderNode = database.getChild(childId);
    if (folderNode == null) {
        return;
    }
    EditUserDialog dlg = new EditUserDialog(getShell());
    Connection con = null;
    try {
        con = JDBCConnectionManager.getConnection(database.getDatabaseInfo(), false);
        final GetAllClassListTask classInfoTask = new GetAllClassListTask(database.getDatabaseInfo(), con);
        final GetAllPartitionClassTask partitionTask = new GetAllPartitionClassTask(database.getDatabaseInfo(), con);
        GetUserListTask task = new GetUserListTask(database.getDatabaseInfo(), con);
        DbUserInfoList userListInfo = null;
        try {
            userListInfo = task.getResultModel();
        } catch (Exception e) {
            LOGGER.error("load user failed", e);
            return;
        }
        boolean isSuccess = dlg.execTask(-1, new ITask[] { classInfoTask, partitionTask }, getShell());
        if (!isSuccess) {
            return;
        }
        dlg.setUserListInfo(userListInfo);
        dlg.setDatabase(database);
        dlg.setUserName(node.getName());
        dlg.setPartitionClassMap(partitionTask.getPartitionClassMap());
        dlg.setNewFlag(true);
        GetUserAuthorizationsTask privilegeTask = new GetUserAuthorizationsTask(database.getDatabaseInfo(), con);
        try {
            for (DbUserInfo userInfo : userListInfo.getUserList()) {
                if (userInfo.getName().equals(node.getName())) {
                    userInfo.setUserAuthorizations(privilegeTask.getUserAuthorizations(userInfo.getName()));
                }
            }
        } catch (Exception e) {
            LOGGER.error("get user failed", e);
            return;
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        QueryUtil.freeQuery(con);
    }
    if (dlg.open() == IDialogConstants.OK_ID) {
        //Don't count the child
        if (!folderNode.getLoader().isLoaded()) {
            return;
        }
        CubridNavigatorView navigatorView = CubridNavigatorView.findNavigationView();
        if (navigatorView != null) {
            TreeViewer treeViewer = navigatorView.getViewer();
            if (treeViewer != null) {
                CubridNodeChangedEvent event = new CubridNodeChangedEvent(folderNode, CubridNodeChangedEventType.NODE_REFRESH);
                CubridNodeManager.getInstance().fireCubridNodeChanged(event);
                CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
            } else {
                CommonUITool.refreshNavigatorTree(treeViewer, node.getParent());
                setEnabled(false);
            }
        }
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) Connection(java.sql.Connection) GetAllPartitionClassTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllPartitionClassTask) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) EditUserDialog(com.cubrid.common.ui.cubrid.user.dialog.EditUserDialog) GetUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) GetAllClassListTask(com.cubrid.cubridmanager.core.cubrid.table.task.GetAllClassListTask) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 64 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class LoginDatabaseTaskTest method testReceive.

public void testReceive() throws Exception {
    String filepath = this.getFilePathInPlugin("/com/cubrid/cubridmanager/core/cubrid/database/task/test.message/logindb_receive");
    String msg = Tool.getFileContent(filepath);
    TreeNode node = MessageUtil.parseResponse(msg);
    LoginDatabaseTask task = new LoginDatabaseTask(serverInfo);
    task.setResponse(node);
    DbUserInfo dbUserInfo = task.getLoginedDbUserInfo();
    assertEquals(dbUserInfo.getDbName(), "demodb");
    assertTrue(dbUserInfo.isDbaAuthority());
    //exception case1
    task.setResponse(null);
    assertTrue(task.getLoginedDbUserInfo() == null);
    //case 2
    filepath = this.getFilePathInPlugin("/com/cubrid/cubridmanager/core/cubrid/database/task/test.message/logindb_receive2");
    msg = Tool.getFileContent(filepath);
    node = MessageUtil.parseResponse(msg);
    LoginDatabaseTask task2 = new LoginDatabaseTask(serverInfo);
    task2.setResponse(node);
    task2.getLoginedDbUserInfo();
    //case 3
    filepath = this.getFilePathInPlugin("/com/cubrid/cubridmanager/core/cubrid/database/task/test.message/logindb_receive2");
    msg = Tool.getFileContent(filepath);
    node = MessageUtil.parseResponse(msg);
    LoginDatabaseTask task3 = new LoginDatabaseTask(serverInfo);
    task3.setResponse(node);
    task3.getLoginedDbUserInfo();
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode)

Example 65 with DbUserInfo

use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.

the class LoginDatabaseDialog method save.

private boolean save() {
    if (database == null) {
        return false;
    }
    database.setAutoSavePassword(isSavePassword);
    final String dbUser = userNameText.getText();
    final String dbPassword = passwordText.getText();
    if (database.getDatabaseInfo() != null) {
        database.getDatabaseInfo().setJdbcAttrs(attrText.getText());
        DbUserInfo info = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        if (info != null) {
            info.setName(dbUser);
            info.setNoEncryptPassword(dbPassword);
        }
        CMDBNodePersistManager.getInstance().updateDbPassword(database.getServer().getHostAddress(), database.getServer().getMonPort(), database.getDatabaseInfo().getDbName(), dbUser, dbPassword, isSavePassword);
        CMDBNodePersistManager.getInstance().setJdbcAttrs(database, attrText.getText());
        DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(database, true);
        if (editorConfig == null) {
            editorConfig = new DatabaseEditorConfig();
        }
        RGB selectedColor = selectColorCombo.getSelectedColor();
        editorConfig.setBackGround(selectedColor);
        editorConfig.setDatabaseComment(commentText.getText());
        QueryOptions.putEditorConfig(database, editorConfig, true);
        /* TOOLS-1222Edit database dialog can't save password */
        CMDBNodePersistManager.getInstance().addDatabase(database, editorConfig);
        saveBrokerInfo();
        boolean userChanged = !dbUser.equals(oldLoginUserName);
        return oldDatabaseIsLogin && userChanged;
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) RGB(org.eclipse.swt.graphics.RGB) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Aggregations

DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)80 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)36 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)30 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)22 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)16 ArrayList (java.util.ArrayList)14 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)10 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)9 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)8 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)7 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)6 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)6 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)6 IsDBAUserTask (com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask)6 CQBDbConnectionLoader (com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader)6 HashMap (java.util.HashMap)6 CubridNodeLoader (com.cubrid.common.ui.spi.model.CubridNodeLoader)5 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)5