Search in sources :

Example 76 with DbUserInfo

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

the class LoginDatabaseTask method getLoginedDbUserInfo.

/**
	 * 
	 * Get logined database user information
	 * 
	 * @return DbUserInfo a instance of DbUserInfo
	 */
public DbUserInfo getLoginedDbUserInfo() {
    TreeNode response = getResponse();
    if (response == null || response.getValue("dbname") == null) {
        setErrorMsg(Messages.error_invalidUser);
        return null;
    }
    // String cmUser = response.getValue("targetid");
    String dbName = response.getValue("dbname");
    String isDbaStr = response.getValue("authority");
    boolean isDba = isDbaStr != null && isDbaStr.equals("isdba");
    DbUserInfo userInfo = new DbUserInfo(dbName, dbUser, "", dbPassword, isDba);
    return userInfo;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode)

Example 77 with DbUserInfo

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

the class CQBDatabaseFactory method createDatabase.

/**
	 * Create database object
	 * @param connInfo
	 * @return
	 */
public static CubridDatabase createDatabase(IJDBCConnecInfo connInfo) {
    if (connInfo == null || StringUtil.isEmpty(connInfo.getConName())) {
        return null;
    }
    /*Create a new object*/
    String connName = getUniqueName(connInfo.getConName());
    String dbId = connName + ICubridNodeLoader.NODE_SEPARATOR + connName;
    ServerInfo serverInfo = new ServerInfo();
    serverInfo.setServerName(connName);
    serverInfo.setHostAddress(connInfo.getHost());
    serverInfo.setUserName(connInfo.getDbName() + "@" + connInfo.getHost());
    if (!StringUtil.isEmpty(connInfo.getVersion())) {
        serverInfo.setJdbcDriverVersion(connInfo.getVersion());
    } else if (!StringUtil.isEmpty(connInfo.getDriverFileName())) {
        serverInfo.setServerVersion(CubridJdbcManager.getInstance().getDriverFileByVersion(connInfo.getDriverFileName()));
    } else {
        serverInfo.setServerVersion("");
    }
    CubridServer server = new CubridServer(connName, connName, null, null);
    server.setServerInfo(serverInfo);
    server.setType(NodeType.SERVER);
    DatabaseInfo dbInfo = new DatabaseInfo(connInfo.getDbName(), serverInfo);
    dbInfo.setBrokerIP(connInfo.getHost());
    dbInfo.setBrokerPort(String.valueOf(connInfo.getPort()));
    dbInfo.setCharSet(connInfo.getCharset());
    dbInfo.setJdbcAttrs(connInfo.getJDBCAttrs());
    DbUserInfo userInfo = new DbUserInfo();
    userInfo.setDbName(connInfo.getDbName());
    userInfo.setName(connInfo.getConUser());
    userInfo.setNoEncryptPassword(connInfo.getConPassword());
    dbInfo.setAuthLoginedDbUserInfo(userInfo);
    CubridDatabase database = new CubridDatabase(dbId, connName);
    database.setDatabaseInfo(dbInfo);
    database.setServer(server);
    database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
    database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
    CubridNodeLoader loader = new CQBDbConnectionLoader();
    loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
    database.setLoader(loader);
    return database;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CQBDbConnectionLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader) CubridNodeLoader(com.cubrid.common.ui.spi.model.CubridNodeLoader) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 78 with DbUserInfo

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

the class CQBDBNodePersistManager method parseDatabaseFromXML.

public List<CubridDatabase> parseDatabaseFromXML(File file) {
    // FIXME extract?
    List<CubridDatabase> list = new ArrayList<CubridDatabase>();
    FileInputStream fis = null;
    try {
        fis = new FileInputStream(file);
        IXMLMemento xmlContent = XMLMemento.loadMemento(fis);
        IXMLMemento[] children = xmlContent == null ? null : xmlContent.getChildren("database");
        for (int i = 0; children != null && i < children.length; i++) {
            String name = children[i].getString("name");
            String dbName = children[i].getString("dbName");
            String brokerIp = children[i].getString("brokerIp");
            String brokerPort = children[i].getString("brokerPort");
            String charset = children[i].getString("charset");
            String jdbcAttrs = children[i].getString("jdbcAttrs");
            String dbUser = children[i].getString("dbUser");
            String dbPassword = children[i].getString("dbPassword");
            boolean savePassword = children[i].getBoolean("savePassword");
            String jdbcDriver = children[i].getString("jdbcDriver");
            // [TOOLS-2425]Support shard broker
            Boolean isShardObj = children[i].getBoolean("isShard");
            boolean isShard = isShardObj == null ? false : isShardObj;
            String shardQueryTypeStr = children[i].getString("shardQueryType");
            int shardQueryType = StringUtil.intValue(shardQueryTypeStr, 0);
            ServerInfo serverInfo = new ServerInfo();
            serverInfo.setServerName(name);
            serverInfo.setHostAddress(brokerIp);
            serverInfo.setHostMonPort(Integer.parseInt(brokerPort));
            serverInfo.setHostJSPort(Integer.parseInt(brokerPort) + 1);
            serverInfo.setUserName(dbName + "@" + brokerIp);
            serverInfo.setJdbcDriverVersion(jdbcDriver);
            CubridServer server = new CubridServer(name, name, null, null);
            server.setServerInfo(serverInfo);
            server.setType(NodeType.SERVER);
            DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
            dbInfo.setBrokerIP(brokerIp);
            dbInfo.setBrokerPort(brokerPort);
            dbInfo.setCharSet(charset);
            dbInfo.setJdbcAttrs(jdbcAttrs);
            dbInfo.setRunningType(DbRunningType.CS);
            // [TOOLS-2425]Support shard broker
            dbInfo.setShard(isShard);
            dbInfo.setShardQueryType(shardQueryType);
            String decDbPassword = null;
            if (dbPassword != null && dbPassword.trim().length() > 0) {
                decDbPassword = CipherUtils.decrypt(dbPassword);
            }
            DbUserInfo dbUserInfo = new DbUserInfo(dbName, dbUser, dbPassword, decDbPassword, false);
            dbInfo.setAuthLoginedDbUserInfo(dbUserInfo);
            String dbId = name + ICubridNodeLoader.NODE_SEPARATOR + name;
            DatabaseEditorConfig editorConfig = null;
            IXMLMemento editorConfigElement = children[i].getChild("editorConfig");
            if (editorConfigElement != null) {
                editorConfig = new DatabaseEditorConfig();
                String strBGPos = editorConfigElement.getString("purpose-code");
                if (strBGPos == null) {
                    strBGPos = "0";
                }
                int bgPos = StringUtil.intValue(strBGPos, 0);
                RGB background = EditorConstance.getRGBByPos(bgPos);
                editorConfig.setBackGround(background);
                editorConfig.setDatabaseComment(editorConfigElement.getString("database-comment"));
            }
            CubridDatabase database = new CubridDatabase(dbId, name);
            database.setServer(server);
            database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
            database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
            database.setDatabaseInfo(dbInfo);
            CubridNodeLoader loader = new CQBDbConnectionLoader();
            loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
            database.setLoader(loader);
            database.setAutoSavePassword(savePassword);
            /*Save DatabaseEditorConfig to database object*/
            if (editorConfig != null) {
                database.setData(CubridDatabase.DATA_KEY_EDITOR_CONFIG, editorConfig);
            }
            list.add(database);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    } finally {
        FileUtil.close(fis);
    }
    return list;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CQBDbConnectionLoader(com.cubrid.cubridmanager.ui.spi.model.loader.CQBDbConnectionLoader) ArrayList(java.util.ArrayList) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CubridNodeLoader(com.cubrid.common.ui.spi.model.CubridNodeLoader) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) RGB(org.eclipse.swt.graphics.RGB) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) DatabaseEditorConfig(com.cubrid.common.ui.spi.model.DatabaseEditorConfig)

Example 79 with DbUserInfo

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

the class SetupEnvTestCase method loginTestDatabase930.

protected void loginTestDatabase930() {
    if (databaseInfo930.isLogined()) {
        return;
    }
    LoginDatabaseTask loginDatabaseTask = new LoginDatabaseTask(serverInfo930);
    loginDatabaseTask.setCMUser(userName930);
    loginDatabaseTask.setDbName(testDbName930);
    loginDatabaseTask.setDbUser(dbaUserName930);
    loginDatabaseTask.setDbPassword(dbaPassword930);
    loginDatabaseTask.execute();
    assertEquals(null, loginDatabaseTask.getErrorMsg());
    DbUserInfo dbUserInfo = loginDatabaseTask.getLoginedDbUserInfo();
    dbUserInfo.setNoEncryptPassword(dbaPassword930);
    databaseInfo930.setLogined(true);
    databaseInfo930.setAuthLoginedDbUserInfo(dbUserInfo);
    UpdateCMUserTask updateCMUserTask = new UpdateCMUserTask(serverInfo930);
    updateCMUserTask.setCmUserName(userName930);
    ServerUserInfo userInfo = serverInfo930.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 80 with DbUserInfo

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

the class SetupEnvTestCase method loginTestDatabase831.

protected void loginTestDatabase831() {
    if (databaseInfo831.isLogined()) {
        return;
    }
    LoginDatabaseTask loginDatabaseTask = new LoginDatabaseTask(serverInfo831);
    loginDatabaseTask.setCMUser(userName831);
    loginDatabaseTask.setDbName(testDbName831);
    loginDatabaseTask.setDbUser(dbaUserName831);
    loginDatabaseTask.setDbPassword(dbaPassword831);
    loginDatabaseTask.execute();
    assertEquals(null, loginDatabaseTask.getErrorMsg());
    DbUserInfo dbUserInfo = loginDatabaseTask.getLoginedDbUserInfo();
    dbUserInfo.setNoEncryptPassword(dbaPassword831);
    databaseInfo831.setLogined(true);
    databaseInfo831.setAuthLoginedDbUserInfo(dbUserInfo);
    UpdateCMUserTask updateCMUserTask = new UpdateCMUserTask(serverInfo831);
    updateCMUserTask.setCmUserName(userName831);
    ServerUserInfo userInfo = serverInfo831.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)

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