Search in sources :

Example 46 with DbUserInfo

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

the class GetCMUserListTask method buildDatabaseInfo.

/**
	 * 
	 * Create database information
	 * 
	 * @param dbNameArr the database name array
	 * @param dbUserIdArr the database user array
	 * @param dbPasswordArr the database user password array
	 * @param dbBrokerAddressArr the broker address array
	 * @param userInfo the ServerUserInfo
	 */
private void buildDatabaseInfo(String[] dbNameArr, String[] dbUserIdArr, String[] dbPasswordArr, String[] dbBrokerAddressArr, ServerUserInfo userInfo) {
    for (int n = 0; dbNameArr != null && n < dbNameArr.length; n++) {
        DatabaseInfo databaseInfo = new DatabaseInfo(dbNameArr[n], serverInfo);
        DbUserInfo databaseUserInfo = new DbUserInfo();
        if (dbUserIdArr != null && dbUserIdArr.length > n) {
            databaseUserInfo.setName(dbUserIdArr[n]);
            if (dbUserIdArr[n].equals("dba")) {
                databaseUserInfo.setDbaAuthority(true);
            }
        }
        if (dbPasswordArr != null && dbPasswordArr.length > n) {
            databaseUserInfo.setNoEncryptPassword(dbPasswordArr[n]);
        }
        if (dbBrokerAddressArr != null && dbBrokerAddressArr.length > n) {
            String dbBroker = dbBrokerAddressArr[n];
            String brokerIp = "";
            String brokerPort = "";
            String[] dbBrokerArr = dbBroker.split(",");
            if (dbBrokerArr != null && dbBrokerArr.length == 2) {
                brokerIp = dbBrokerArr[0];
                brokerPort = dbBrokerArr[1];
            }
            databaseInfo.setBrokerIP(brokerIp);
            databaseInfo.setBrokerPort(brokerPort);
        }
        databaseInfo.setAuthLoginedDbUserInfo(databaseUserInfo);
        userInfo.addDatabaseInfo(databaseInfo);
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)

Example 47 with DbUserInfo

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

the class GetUserListTask method buildUserInfo.

/**
	 * 
	 * Build the database user information
	 * 
	 * @param dbUserInfoList DbUserInfoList
	 * @throws SQLException The exception
	 */
private void buildUserInfo(DbUserInfoList dbUserInfoList) {
    Map<String, String> oidMap = new HashMap<String, String>();
    Map<String, List<String>> groupMap = new HashMap<String, List<String>>();
    String sql = "SELECT db_user, name, groups FROM db_user";
    // [TOOLS-2425]Support shard broker
    sql = databaseInfo.wrapShardQuery(sql);
    try {
        stmt = connection.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            String oidStr = rs.getString(1);
            String name = rs.getString(2);
            CUBRIDResultSetProxy cubridRS = (CUBRIDResultSetProxy) rs;
            Object[] objs = (Object[]) cubridRS.getCollection(3);
            List<String> groups = new ArrayList<String>();
            for (Object obj : objs) {
                if (obj != null && obj.getClass() == CUBRIDOIDProxy.getCUBRIDOIDClass(cubridRS.getJdbcVersion())) {
                    groups.add((new CUBRIDOIDProxy(obj)).getOidString());
                }
            }
            if (name != null) {
                name = name.toLowerCase(Locale.getDefault());
            }
            oidMap.put(oidStr, name);
            groupMap.put(name, groups);
            DbUserInfo dbUserInfo = new DbUserInfo();
            dbUserInfo.setDbName(databaseInfo.getDbName());
            dbUserInfo.setName(name);
            dbUserInfo.addAuthorization(new HashMap<String, String>());
            dbUserInfoList.addUser(dbUserInfo);
        }
    } catch (SQLException ex) {
        errorMsg = ex.getMessage();
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    // get the group user
    if (dbUserInfoList.getUserList() != null) {
        for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
            UserGroup userGroup = userInfo.getGroups();
            if (userGroup == null) {
                userGroup = new UserGroup();
                userInfo.addGroups(userGroup);
            }
            List<String> groupOIDList = groupMap.get(userInfo.getName());
            for (String groupOID : groupOIDList) {
                String groupUser = oidMap.get(groupOID);
                if (groupUser != null) {
                    userInfo.getGroups().addGroup(groupUser);
                }
            }
        }
    }
//get the member user
//		for (DbUserInfo userInfo : dbUserInfoList.getUserList()) {
//			List<String> groupNameList = userInfo.getGroupList();
//			for (String groupName : groupNameList) {
//				User groupUser = catalog.getUserByName(groupName);
//				if (groupUser != null) {
//					((CUBRIDUser) groupUser).addMember(user.getName());
//				}
//			}
//		}
}
Also used : CUBRIDResultSetProxy(com.cubrid.jdbc.proxy.driver.CUBRIDResultSetProxy) CUBRIDOIDProxy(com.cubrid.jdbc.proxy.driver.CUBRIDOIDProxy) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) UserGroup(com.cubrid.cubridmanager.core.cubrid.user.model.UserGroup) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ArrayList(java.util.ArrayList) List(java.util.List) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)

Example 48 with DbUserInfo

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

the class UserEditor method initial.

/**
	 * 
	 * Initial the data
	 * 
	 */
private void initial() {
    if (ownerClassTableViewer == null || ownerClassTableViewer.getControl() == null || ownerClassTableViewer.getControl().isDisposed()) {
        return;
    }
    if (memberList == null) {
        memberList = new ArrayList<String>();
    }
    while (!memberList.isEmpty()) {
        memberList.remove(0);
    }
    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)) {
                    memberList.add(bean.getName());
                    break;
                }
            }
        }
    }
    List<String> groupList = userInfo.getGroups().getGroup();
    while (!ownerClassListData.isEmpty()) {
        ownerClassListData.remove(0);
    }
    if (allClassInfoList != null) {
        for (ClassInfo c : allClassInfoList) {
            if (c.getOwnerName().equalsIgnoreCase(userInfo.getName())) {
                Map<String, String> map = new HashMap<String, String>();
                map.put("0", c.getClassName());
                map.put("1", c.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
                map.put("2", c.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
                ownerClassListData.add(map);
            }
        }
    }
    while (!authListData.isEmpty()) {
        authListData.remove(0);
    }
    Map<String, String> classGrantMap = userInfo.getAuthorization();
    Iterator<Map.Entry<String, String>> it = classGrantMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        String className = entry.getKey();
        if (!partitionClassMap.containsKey(className)) {
            String authNum = entry.getValue();
            authListData.add(getItemAuthMap(new ClassAuthorizations(className, CommonUITool.str2Int(authNum))));
        }
    }
    ownerClassTableViewer.refresh();
    if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
        authTableViewer.refresh();
    }
    for (int i = 0; i < ownerClassTableViewer.getTable().getColumnCount(); i++) {
        ownerClassTableViewer.getTable().getColumn(i).pack();
    }
    if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
        for (int i = 0; i < authTableViewer.getTable().getColumnCount(); i++) {
            authTableViewer.getTable().getColumn(i).pack();
        }
    }
    StringBuffer sb = new StringBuffer();
    if (groupList != null) {
        for (int i = 0, n = groupList.size(); i < n; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(groupList.get(i));
        }
    }
    lblUserGroup.setText(Messages.bind(Messages.lblGroupList, sb.length() < 1 ? Messages.lblGroupNotExist : sb.toString()));
    sb = new StringBuffer();
    if (memberList != null) {
        for (int i = 0, n = memberList.size(); i < n; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(memberList.get(i));
        }
    }
    lblUserMember.setText(Messages.bind(Messages.lblMemberList, sb.length() < 1 ? Messages.lblMemberNotExist : sb.toString()));
}
Also used : ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) HashMap(java.util.HashMap) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) Map(java.util.Map) HashMap(java.util.HashMap) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 49 with DbUserInfo

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

the class LoginQueryEditDialog method changeSelection.

/**
	 * Change the selection
	 * 
	 */
private void changeSelection() {
    connectionComp.changeData(null);
    allHostCombo.setText(selServerName);
    String serverName = allHostCombo.getText();
    CubridServer cubridServer = serverMap.get(serverName);
    String charset = "";
    if (cubridServer != null && cubridServer.getHostAddress() != null) {
        connectionComp.getBrokerIpText().setText(cubridServer.getHostAddress());
    }
    fillDatabaseCombo(databaseMap.get(serverName));
    boolean isAdminLogin = (cubridServer == null || cubridServer.getServerInfo() == null || cubridServer.getServerInfo().getLoginedUserInfo() == null) ? false : cubridServer.getServerInfo().getLoginedUserInfo().isAdmin();
    if (isAdminLogin) {
        fillBrokerPortCombo(serverName);
    }
    DatabaseInfo dbInfo = selectDatabase == null ? null : selectDatabase.getDatabaseInfo();
    if (dbInfo != null) {
        connectionComp.getBrokerIpText().setText(QueryOptions.getBrokerIp(dbInfo));
        if (connectionComp.getBrokerPortCombo().getItemCount() > 0) {
            connectionComp.getBrokerPortCombo().setText(QueryOptions.getBrokerPort(dbInfo));
        } else {
            connectionComp.getBrokerPortCombo().add(QueryOptions.getBrokerPort(dbInfo));
            connectionComp.getBrokerPortCombo().select(0);
        }
        DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
        if (dbUserInfo != null) {
            connectionComp.getUserNameText().setText(dbUserInfo.getName() == null ? "" : dbUserInfo.getName());
            connectionComp.getPasswordText().setText(dbUserInfo.getNoEncryptPassword() == null ? "" : dbUserInfo.getNoEncryptPassword());
        }
        charset = dbInfo.getCharSet();
    }
    String jdbcDriverVersion = cubridServer == null ? null : cubridServer.getJdbcDriverVersion();
    if (jdbcDriverVersion == null || "".equals(jdbcDriverVersion) || ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcDriverVersion)) {
        if (connectionComp.getJdbcCombo().getItemCount() > 0) {
            connectionComp.getJdbcCombo().select(0);
        }
    } else {
        connectionComp.getJdbcCombo().setText(cubridServer.getJdbcDriverVersion());
    }
    connectionComp.getCharsetCombo().setItems(QueryOptions.getAllCharset(charset));
    if (charset != null && charset.trim().length() > 0) {
        connectionComp.getCharsetCombo().setText(charset);
    } else {
        connectionComp.getCharsetCombo().select(0);
    }
    if (dbInfo != null) {
        connectionComp.getBtnShard().setSelection(dbInfo.isShard());
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 50 with DbUserInfo

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

the class CubridStatusLineContrItem method updateStatusLine.

/**
	 *
	 * Update the status line information
	 *
	 * @param statusLineManager StatusLineManager
	 * @param cubridNode The selected ICubridNode object
	 */
protected void updateStatusLine(StatusLineManager statusLineManager, ICubridNode cubridNode) {
    clearStatusLine();
    updateStatusLineForRestoreQueryEditor();
    if (!(cubridNode instanceof ISchemaNode)) {
        return;
    }
    StringBuffer dbInfoStrBuffer = new StringBuffer();
    ISchemaNode schemaNode = (ISchemaNode) cubridNode;
    CubridDatabase database = schemaNode.getDatabase();
    if (database == null || database.getDatabaseInfo() == null) {
        return;
    }
    DatabaseInfo dbInfo = database.getDatabaseInfo();
    DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
    if (dbUserInfo == null || dbUserInfo.getName() == null || dbUserInfo.getName().trim().length() == 0) {
        dbInfoStrBuffer.append(dbInfo.getDbName());
    } else {
        dbInfoStrBuffer.append(dbUserInfo.getName() + "@" + dbInfo.getDbName());
    }
    String brokerPort = database.getDatabaseInfo().getBrokerPort();
    if (brokerPort != null && brokerPort.trim().length() > 0) {
        dbInfoStrBuffer.append(":").append(brokerPort);
    }
    String charset = database.getDatabaseInfo().getCharSet();
    if (charset != null && charset.trim().length() > 0) {
        dbInfoStrBuffer.append(":charset=").append(charset);
    }
    String numberStr = getChilderenNumStr(cubridNode);
    int addWidth = 30;
    if (numberStr != null && numberStr.length() > 0) {
        StatusLineContributionItem item = new StatusLineContributionItem(OBJ_NUM_INFO_CONTR_ID, numberStr.length() + 3);
        statusLineManager.add(item);
        item.setText(numberStr);
        addWidth = 10;
    }
    StatusLineContributionItem item = new StatusLineContributionItem(DB_INFO_CONTR_ID, dbInfoStrBuffer.length() + addWidth);
    statusLineManager.add(item);
    item.setText(dbInfoStrBuffer.toString());
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) StatusLineContributionItem(org.eclipse.jface.action.StatusLineContributionItem) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

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