Search in sources :

Example 51 with ServerUserInfo

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

the class SetupEnvTestCase method setupDatabaseInfo831.

/**
	 * * Setup database 8.3.1
	 *
	 */
private void setupDatabaseInfo831() {
    /*Setting Cubrid 8.3.1*/
    serverInfo831 = new ServerInfo();
    serverInfo831.setHostAddress(host831);
    serverInfo831.setHostMonPort(monport831);
    serverInfo831.setHostJSPort(jpport831);
    serverInfo831.setUserName(userName831);
    serverInfo831.setUserPassword(passwd831);
    serverInfo831.setJdbcDriverVersion(serverVersion831);
    ServerManager.getInstance().addServer(host831, monport831, userName831, serverInfo831);
    MonitoringTask monTask = new MonitoringTask(serverInfo831);
    serverInfo831 = monTask.connectServer(serverVersion831, 1000);
    // get the latest token
    token831 = serverInfo831.getHostToken();
    //get evnInfo
    if (envInfo831 == null) {
        GetEnvInfoTask envTask = new GetEnvInfoTask(serverInfo831);
        envTask.loadEnvInfo();
        envTask.execute();
        envInfo831 = envTask.loadEnvInfo();
        serverInfo831.setEnvInfo(envInfo831);
    }
    assertNotNull(envInfo831);
    serverPath831 = envInfo831.getRootDir();
    dbRootDir831 = envInfo831.getDatabaseDir();
    //get server type
    GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo831);
    getCMConfParameterTask.execute();
    assertEquals(null, getCMConfParameterTask.getErrorMsg());
    Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
    ServerType serverType = ServerType.BOTH;
    if (confParameters != null) {
        String target = confParameters.get(ConfConstants.CM_TARGET);
        if (target != null) {
            if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
                serverType = ServerType.BOTH;
            } else if (target.indexOf("broker") >= 0) {
                serverType = ServerType.BROKER;
            } else if (target.indexOf("server") >= 0) {
                serverType = ServerType.DATABASE;
            }
        }
    }
    if (serverInfo831 != null) {
        serverInfo831.setServerType(serverType);
    }
    //Get database list task
    if (serverType == ServerType.DATABASE || serverType == ServerType.BOTH) {
        final GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo831);
        getDatabaseListTask.execute();
        assertEquals(null, getDatabaseListTask.getErrorMsg());
        List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
        for (DatabaseInfo dbInfo : databaseInfoList) {
            if (dbInfo.getDbName().equals(testDbName831)) {
                databaseInfo831 = dbInfo;
                break;
            }
        }
        if (databaseInfo831 == null) {
            return;
        }
    }
    //get CubridManager user list task
    GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo831);
    getUserInfoTask.execute();
    assertEquals(null, getUserInfoTask.getErrorMsg());
    List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
    for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
        ServerUserInfo userInfo = serverUserInfoList.get(i);
        if (userInfo != null && userInfo.getUserName().equals(serverInfo831.getUserName())) {
            serverInfo831.setLoginedUserInfo(userInfo);
            break;
        }
    }
    List<DatabaseInfo> databaseInfoList = serverInfo831.getLoginedUserInfo().getDatabaseInfoList();
    String dbDir = databaseInfo831.getDbDir();
    DbRunningType type = databaseInfo831.getRunningType();
    for (int i = 0; databaseInfoList != null && i < databaseInfoList.size(); i++) {
        if (testDbName831.equalsIgnoreCase(databaseInfoList.get(i).getDbName())) {
            databaseInfo831 = databaseInfoList.get(i);
            databaseInfo831.setDbDir(dbDir);
            databaseInfo831.setBrokerIP(host831);
            databaseInfo831.setBrokerPort(port831);
            databaseInfo831.setCharSet(charset831);
            databaseInfo831.setRunningType(type);
            break;
        }
    }
    //get CUBRID conf parameter
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo831);
    getCubridConfParameterTask.execute();
    assertEquals(null, getCubridConfParameterTask.getErrorMsg());
    Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
    if (serverInfo831 != null) {
        serverInfo831.setCubridConfParaMap(confParas);
    }
    //get broker Info
    GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo831);
    getBrokerConfParameterTask.execute();
    assertEquals(null, getBrokerConfParameterTask.getErrorMsg());
    confParas = getBrokerConfParameterTask.getConfParameters();
    if (serverInfo831 != null) {
        serverInfo831.setBrokerConfParaMap(confParas);
    }
    //Set JDBC driver
    String filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.0.1004-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo831.setJdbcDriverVersion(version);
        }
    }
    filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.1.0173-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo831.setJdbcDriverVersion(version);
        }
    }
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) DbRunningType(com.cubrid.cubridmanager.core.common.model.DbRunningType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 52 with ServerUserInfo

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

Example 53 with ServerUserInfo

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

the class QueryOptions method getBrokerPort.

/**
	 * get broker port for current user when admin login, use the item selected
	 * in host property page when un-admin user login, use the default broker
	 * port in database info.
	 * 
	 * @param databaseInfo
	 *            the DatabaseInfo object
	 * @return the ip
	 */
public static String getBrokerPort(DatabaseInfo databaseInfo) {
    ServerUserInfo userInfo = databaseInfo.getServerInfo().getLoginedUserInfo();
    String portInfo = null;
    if (userInfo != null && userInfo.isAdmin()) {
        String prefix = getPrefix(databaseInfo);
        String port = pref.get(prefix + QueryOptions.BROKER_PORT, "");
        if (port != null && !port.equals("")) {
            portInfo = port;
        }
    }
    if (portInfo == null) {
        portInfo = databaseInfo.getBrokerPort();
    }
    return portInfo;
}
Also used : ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 54 with ServerUserInfo

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

the class QueryOptions method getBrokerIp.

/**
	 * 
	 * Get broker IP of the database from preference
	 * 
	 * @param databaseInfo
	 *            the DatabaseInfo object
	 * @return the ip
	 */
public static String getBrokerIp(DatabaseInfo databaseInfo) {
    ServerUserInfo userInfo = databaseInfo.getServerInfo().getLoginedUserInfo();
    String brokerIP = null;
    if (userInfo != null && userInfo.isAdmin()) {
        String prefix = getPrefix(databaseInfo);
        String ip = pref.get(prefix + QueryOptions.BROKER_IP, "");
        if (ip != null && !ip.equals("")) {
            brokerIP = ip;
        }
        if (brokerIP == null) {
            brokerIP = databaseInfo.getServerInfo().getHostAddress();
        }
    }
    if (brokerIP == null) {
        brokerIP = databaseInfo.getBrokerIP();
    }
    return brokerIP;
}
Also used : ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 55 with ServerUserInfo

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

the class ActionSupportUtil method hasAdminPermission.

/**
	 * Whether having cubrid manager's administrative permissions
	 *
	 * @param obj ISchemaNode or ISchemaNode[]
	 * @return boolean
	 */
public static boolean hasAdminPermission(Object obj) {
    if (!(obj instanceof ISchemaNode)) {
        return false;
    }
    ISchemaNode node = (ISchemaNode) obj;
    CubridServer server = node.getServer();
    if (server == null) {
        return false;
    }
    ServerInfo serverInfo = server.getServerInfo();
    if (serverInfo == null) {
        return false;
    }
    if (!serverInfo.isConnected()) {
        return false;
    }
    ServerUserInfo serverUserInfo = serverInfo.getLoginedUserInfo();
    if (serverUserInfo == null) {
        return false;
    }
    if (serverUserInfo.getDbCreateAuthType() == DbCreateAuthType.AUTH_ADMIN) {
        return true;
    }
    CubridDatabase database = node.getDatabase();
    if (database == null) {
        return false;
    }
    DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    if (dbUserInfo != null && dbUserInfo.isDbaAuthority() && database.isLogined()) {
        return true;
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

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