use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo 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();
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class LoginQueryEditDialog method buttonPressed.
/**
* @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
* @param buttonId the id of the button that was pressed (see
* <code>IDialogConstants.*_ID</code> constants)
*/
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID || buttonId == TEST_CONNECT_ID) {
String brokerIp = connectionComp.getBrokerIpText().getText();
CubridServer cubridServer = DatabaseNavigatorMenu.SELF_DATABASE.getServer();
ServerInfo serverInfo = new ServerInfo();
serverInfo.setServerName(DatabaseNavigatorMenu.SELF_DATABASE_ID);
serverInfo.setHostAddress(brokerIp);
cubridServer.setServerInfo(serverInfo);
String databaseName = connectionComp.getDatabaseCombo().getText();
DatabaseInfo dbInfo = new DatabaseInfo(databaseName, cubridServer.getServerInfo());
dbInfo.setBrokerIP(brokerIp);
dbInfo.setBrokerPort(connectionComp.getBrokerPortCombo().getText());
dbInfo.getServerInfo().setJdbcDriverVersion(connectionComp.getJdbcCombo().getText());
String userName = connectionComp.getUserNameText().getText();
String password = connectionComp.getPasswordText().getText();
DbUserInfo userInfo = new DbUserInfo();
userInfo.setDbName(databaseName);
userInfo.setName(userName);
userInfo.setNoEncryptPassword(password);
dbInfo.setAuthLoginedDbUserInfo(userInfo);
int currentShardId = connectionComp.getCurShardId();
dbInfo.setCurrentShardId(currentShardId);
String charset = connectionComp.getCharsetCombo().getText();
dbInfo.setCharSet(charset);
boolean isShard = connectionComp.getBtnShard().getSelection();
dbInfo.setShard(isShard);
boolean sureCharset = CommonUITool.openConfirmBox(Messages.bind(com.cubrid.cubridmanager.ui.host.Messages.msgConfirmCharset, charset));
if (!sureCharset) {
connectionComp.getCharsetCombo().setFocus();
return;
}
TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo);
new ExecTaskWithProgress(taskExcutor).exec();
if (!taskExcutor.isSuccess()) {
return;
}
if (buttonId == TEST_CONNECT_ID) {
CommonUITool.openInformationBox(com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, com.cubrid.cubridmanager.ui.host.Messages.msgTestConnSuccess);
return;
}
dbInfo.setLogined(true);
dbInfo.setRunningType(DbRunningType.CS);
DatabaseNavigatorMenu.SELF_DATABASE.setDatabaseInfo(dbInfo);
}
super.buttonPressed(buttonId);
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class LoadDatabaseAction method isSupported.
public boolean isSupported(Object obj) {
if (obj != null && obj instanceof CubridDatabase) {
/* TOOLS-3624 Database loading is performed in standalone mode with DBA authorization.*/
CubridDatabase database = (CubridDatabase) obj;
DatabaseInfo dbInfo = database.getDatabaseInfo();
DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
if (database.getRunningType() == DbRunningType.STANDALONE && dbUserInfo != null && dbUserInfo.isDbaAuthority() && dbInfo.isLogined()) {
return true;
}
}
return false;
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class CubridDatabaseLoader method loadReplication.
/**
*
* Load replication function
*
* @param parent the parent node
* @param monitor the monitor object
* @return <code>true</code> it can be loaded;<code>false</code> otherwise
*/
private boolean loadReplication(final ICubridNode parent, final IProgressMonitor monitor) {
CubridDatabase database = (CubridDatabase) parent;
ServerInfo serverInfo = parent.getServer().getServerInfo();
ServerUserInfo serverUserInfo = serverInfo.getLoginedUserInfo();
if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
return true;
}
DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
if (dbUserInfo == null || dbUserInfo.getName() == null || !dbUserInfo.getName().trim().equalsIgnoreCase("DBA")) {
return true;
}
String dbPassword = dbUserInfo.getNoEncryptPassword();
//add for replication support,only can be supported after version 8.2.2 and in linux OS
if (serverInfo.isSupportReplication() == 0) {
final CheckDistributorDbTask checkDistributorDbTask = new CheckDistributorDbTask(serverInfo);
checkDistributorDbTask.setDistDbName(database.getLabel());
checkDistributorDbTask.setDbaPassword(dbPassword);
checkDistributorDbTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplicationInfoTask getReplicationInfoTask = new GetReplicationInfoTask(serverInfo);
getReplicationInfoTask.setDistDbName(database.getLabel());
getReplicationInfoTask.setDbaPassword(dbPassword);
getReplicationInfoTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplicatedTablesTask getReplicatedTablesTask = new GetReplicatedTablesTask(serverInfo);
getReplicatedTablesTask.setDistdbName(database.getLabel());
getReplicatedTablesTask.setDistdbPassword(dbPassword);
getReplicatedTablesTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplicationParamTask getReplicationParamTask = new GetReplicationParamTask(serverInfo);
getReplicationParamTask.setDistDbName(database.getLabel());
getReplicationParamTask.setDistDbDbaPasswd(dbPassword);
getReplicationParamTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
final GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
getReplAgentStatusTask.setDbName(database.getLabel());
monitorCancel(monitor, new ITask[] { checkDistributorDbTask, getReplicationInfoTask, getReplicatedTablesTask, getReplicationParamTask, getReplAgentStatusTask });
checkDistributorDbTask.execute();
if (!checkResult(checkDistributorDbTask, monitor)) {
return false;
}
boolean isDistdb = checkDistributorDbTask.isDistributorDb();
database.getDatabaseInfo().setDistributorDb(isDistdb);
if (isDistdb) {
getReplicationInfoTask.execute();
if (!checkResult(getReplicationInfoTask, monitor)) {
return false;
}
ReplicationInfo replInfo = getReplicationInfoTask.getReplicationInfo();
database.getDatabaseInfo().setReplInfo(replInfo);
if (replInfo != null && replInfo.getDistInfo() != null) {
replInfo.getDistInfo().setDistDbPath(database.getDatabaseInfo().getDbDir());
}
if (replInfo != null && replInfo.getMasterList() != null && replInfo.getMasterList().size() > 0 && replInfo.getSlaveList() != null && replInfo.getSlaveList().size() > 0) {
MasterInfo masterInfo = replInfo.getMasterList().get(0);
SlaveInfo slaveInfo = replInfo.getSlaveList().get(0);
getReplicatedTablesTask.setMasterdbName(masterInfo.getMasterDbName());
getReplicatedTablesTask.setSlavedbName(slaveInfo.getSlaveDbName());
getReplicatedTablesTask.execute();
if (!checkResult(getReplicatedTablesTask, monitor)) {
return false;
}
String[] classNames = getReplicatedTablesTask.getReplicatedTables();
boolean isReplAll = getReplicatedTablesTask.isReplicateAll();
if (classNames != null && classNames.length > 0) {
masterInfo.setReplTableList(Arrays.asList(classNames));
}
masterInfo.setReplAllTable(isReplAll);
getReplicationParamTask.setMasterDbName(masterInfo.getMasterDbName());
getReplicationParamTask.setSlaveDbName(replInfo.getSlaveList().get(0).getSlaveDbName());
getReplicationParamTask.execute();
if (!checkResult(getReplicationParamTask, monitor)) {
return false;
}
ReplicationParamInfo paramInfo = getReplicationParamTask.getReplicationParams();
slaveInfo.setParamInfo(paramInfo);
}
getReplAgentStatusTask.execute();
if (!checkResult(getReplAgentStatusTask, monitor)) {
return false;
}
boolean isActive = getReplAgentStatusTask.isActive();
replInfo.getDistInfo().setAgentActive(isActive);
}
}
return true;
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class CubridDatabasesFolderLoader method filterDatabaseList.
/**
*
* Add or delete database for author database list
*
* @param serverInfo the server information
* @param databaseInfoList the database information list
* @param authorDatabaseList the authorize database list
* @return whether this authorDatabaseList is updated
*/
public static boolean filterDatabaseList(ServerInfo serverInfo, List<DatabaseInfo> databaseInfoList, List<DatabaseInfo> authorDatabaseList) {
if (databaseInfoList == null || authorDatabaseList == null) {
return false;
}
boolean isUpdated = false;
//Check the authorization database whether already deleted
List<DatabaseInfo> deletedDbList = new ArrayList<DatabaseInfo>();
for (int i = 0; i < authorDatabaseList.size(); i++) {
DatabaseInfo databaseInfo = authorDatabaseList.get(i);
if (databaseInfo == null) {
continue;
}
DatabaseInfo dbInfo = getDatabaseInfo(databaseInfoList, databaseInfo.getDbName());
if (dbInfo == null) {
deletedDbList.add(databaseInfo);
isUpdated = true;
} else {
databaseInfo.setDbDir(dbInfo.getDbDir());
databaseInfo.setRunningType(dbInfo.getRunningType());
}
}
List<DatabaseInfo> addedDbList = new ArrayList<DatabaseInfo>();
boolean isAdminLogin = serverInfo.getLoginedUserInfo().isAdmin();
//if user is admin,add all database to authorization database list
if (isAdminLogin) {
for (int i = 0; i < databaseInfoList.size(); i++) {
DatabaseInfo databaseInfo = databaseInfoList.get(i);
if (databaseInfo != null && getDatabaseInfo(authorDatabaseList, databaseInfo.getDbName()) == null) {
addedDbList.add(databaseInfo);
isUpdated = true;
}
}
}
authorDatabaseList.removeAll(deletedDbList);
authorDatabaseList.addAll(addedDbList);
// update the admin user the latest access broker port and IP
if (isAdminLogin) {
String defaultBrokerPort = getDefaultPort(serverInfo);
for (int i = 0; i < authorDatabaseList.size(); i++) {
DatabaseInfo databaseInfo = authorDatabaseList.get(i);
String serverBrokerPort = databaseInfo.getBrokerPort();
if (serverBrokerPort == null || serverBrokerPort.trim().length() == 0 || !isExistPort(serverInfo, serverBrokerPort)) {
serverBrokerPort = defaultBrokerPort;
isUpdated = true;
}
databaseInfo.setBrokerPort(serverBrokerPort);
String localBrokerPort = QueryOptions.getBrokerPort(databaseInfo);
if (localBrokerPort != null && localBrokerPort.trim().length() > 0 && !serverBrokerPort.equals(localBrokerPort) && isExistPort(serverInfo, localBrokerPort)) {
databaseInfo.setBrokerPort(localBrokerPort);
isUpdated = true;
}
String serverBrokerIp = databaseInfo.getBrokerIP();
String localBrokerIp = QueryOptions.getBrokerIp(databaseInfo);
if (!localBrokerIp.equals(serverBrokerIp)) {
databaseInfo.setBrokerIP(localBrokerIp);
isUpdated = true;
}
if (databaseInfo.getAuthLoginedDbUserInfo() == null) {
DbUserInfo userInfo = new DbUserInfo(databaseInfo.getDbName(), "dba", "", "", true);
databaseInfo.setAuthLoginedDbUserInfo(userInfo);
isUpdated = true;
}
}
}
//Set charset and database ip from local preference file
for (DatabaseInfo databaseInfo : authorDatabaseList) {
databaseInfo.setCharSet(QueryOptions.getCharset(databaseInfo));
DbUserInfo dbUserInfo = databaseInfo.getAuthLoginedDbUserInfo();
if (dbUserInfo != null) {
String password = CMDBNodePersistManager.getInstance().getDbPassword(serverInfo.getHostAddress(), String.valueOf(serverInfo.getHostMonPort()), databaseInfo.getDbName(), dbUserInfo.getName());
dbUserInfo.setNoEncryptPassword(password);
}
}
return isUpdated;
}
Aggregations