use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class TableLabelProvider method parseURL.
/**
* Parse the databases from the url
*
* @return
*/
private CubridDatabase parseURL(String url) {
// FIXME extract
CubridDatabase database = null;
String mainParams = null;
String otherParams = null;
/*Split the parameter by ?*/
int questionIndex = url.indexOf("?");
if (questionIndex > 0) {
mainParams = url.substring(0, questionIndex);
if (questionIndex + 1 < url.length()) {
otherParams = url.substring(questionIndex + 1);
}
} else {
mainParams = url;
}
String[] colonParams = mainParams.split(":");
if (colonParams.length >= 5) {
String host = colonParams[2];
String port = colonParams[3];
String dbName = colonParams[4];
String dbUser = "", dbPassword = "";
if (colonParams.length >= 6) {
dbUser = colonParams[5];
}
if (colonParams.length >= 7) {
dbPassword = colonParams[6];
}
String charset = null;
StringBuilder jdbcAttrSB = new StringBuilder();
/*Parse the connection parameters*/
if (otherParams != null) {
/*find the charset parameter*/
String[] propertyArray = otherParams.split("&");
for (int i = 0; i < propertyArray.length; i++) {
String str = propertyArray[i];
if (str.toLowerCase().indexOf("charset") >= 0) {
int index = str.indexOf("=");
if (index >= 0 && index + 1 < str.length()) {
charset = str.substring(index + 1);
propertyArray[i] = null;
}
}
}
/*find other parameters*/
for (int i = 0; i < propertyArray.length; i++) {
if (propertyArray[i] != null) {
jdbcAttrSB.append(propertyArray[i]);
}
if (i + 1 < propertyArray.length && propertyArray[i + 1] != null) {
jdbcAttrSB.append("&");
}
}
}
String connenctionName = host + ":" + port + ":" + dbName + ":" + dbUser;
ServerInfo serverInfo = new ServerInfo();
serverInfo.setServerName(connenctionName);
serverInfo.setHostAddress(host);
serverInfo.setHostMonPort(Integer.parseInt(port));
serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
serverInfo.setUserName(dbName + "@" + host);
DatabaseInfo dbInfo = new DatabaseInfo(dbName, serverInfo);
dbInfo.setBrokerIP(host);
dbInfo.setBrokerPort(port);
if (charset != null) {
dbInfo.setCharSet(charset);
}
dbInfo.setJdbcAttrs(jdbcAttrSB.toString());
DbUserInfo userInfo = new DbUserInfo();
userInfo.setDbName(dbName);
userInfo.setName(dbUser);
userInfo.setNoEncryptPassword(dbPassword);
dbInfo.setAuthLoginedDbUserInfo(userInfo);
CubridServer server = new CubridServer(connenctionName, connenctionName, null, null);
server.setServerInfo(serverInfo);
server.setType(NodeType.SERVER);
String dbId = connenctionName + ICubridNodeLoader.NODE_SEPARATOR + connenctionName;
database = new CubridDatabase(dbId, dbName);
database.setDatabaseInfo(dbInfo);
database.setServer(server);
database.setStartAndLoginIconPath("icons/navigator/database_start_connected.png");
database.setStartAndLogoutIconPath("icons/navigator/database_start_disconnected.png");
database.setAutoSavePassword(true);
database.setLabel(connenctionName);
CubridNodeLoader loader = new CQBDbConnectionLoader();
loader.setLevel(ICubridNodeLoader.FIRST_LEVEL);
database.setLoader(loader);
}
return database;
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method connectDatabaseWithErrMsg.
/**
*
* Connect the database
*
* @param dbInfo DatabaseInfo
* @return error messages String
*/
public static String connectDatabaseWithErrMsg(DatabaseInfo dbInfo) {
// FIXME extract
if (dbInfo == null || dbInfo.getServerInfo() == null) {
return "";
}
Map<String, String> jdbcVersionMap = CubridJdbcManager.getInstance().getLoadedJdbc();
if (jdbcVersionMap == null || jdbcVersionMap.get(dbInfo.getServerInfo().getJdbcDriverVersion()) == null) {
return Messages.errNoSupportDriver;
}
CUBRIDConnectionProxy connection = null;
try {
connection = (CUBRIDConnectionProxy) JDBCConnectionManager.getConnection(dbInfo, false);
DbUserInfo userInfo = dbInfo.getAuthLoginedDbUserInfo();
IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
checkTask.execute();
userInfo.setDbaAuthority(checkTask.isDBAUser());
dbInfo.setLogined(true);
dbInfo.setRunningType(DbRunningType.CS);
dbInfo.getServerInfo().setConnected(true);
dbInfo.setLogined(true);
return null;
} catch (SQLException e) {
return Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage());
} catch (Exception e) {
return e.getMessage();
} finally {
if (connection != null) {
try {
connection.close();
connection = null;
} catch (SQLException e) {
connection = null;
}
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class AddProcedureAction method run.
/**
* Open AddProcedureDialog
*/
public void run() {
// FIXME logic code move to core module
Shell shell = getShell();
Object[] obj = this.getSelectedObj();
if (!isSupported(obj)) {
setEnabled(false);
return;
}
ISchemaNode node = (ISchemaNode) obj[0];
CubridDatabase database = node.getDatabase();
EditProcedureDialog dlg = new EditProcedureDialog(shell);
dlg.setDatabase(database);
dlg.setNewFlag(true);
ISelectionProvider provider = getSelectionProvider();
if (dlg.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.SP_FOLDER_ID);
folderNode = folderNode.getChild(folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSPFolderLoader.PROCEDURE_FOLDER_ID);
TreeViewer treeViewer = (TreeViewer) provider;
if (folderNode == null || !folderNode.getLoader().isLoaded()) {
return;
}
String procedureName = dlg.getProcedureName().toLowerCase(Locale.getDefault());
String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + procedureName;
DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
SPInfo spInfo = new SPInfo(procedureName);
spInfo.setOwner(userInfo.getName());
ICubridNode newNode = CubridProcedureFolderLoader.createProcedureNode(id, spInfo);
CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
}
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo in project cubrid-manager by CUBRID.
the class CreateSerialAction method run.
/**
* run create serial
* @param database
*/
public void run(CubridDatabase database) {
CreateOrEditSerialDialog dialog = new CreateOrEditSerialDialog(getShell(), true);
dialog.setDatabase(database);
ISelectionProvider provider = getSelectionProvider();
if (dialog.open() == IDialogConstants.OK_ID && (provider instanceof TreeViewer)) {
TreeViewer treeViewer = (TreeViewer) provider;
ICubridNode folderNode = database.getChild(database.getId() + ICubridNodeLoader.NODE_SEPARATOR + CubridSerialFolderLoader.SERIAL_FOLDER_ID);
if (folderNode == null || !folderNode.getLoader().isLoaded()) {
return;
}
// FIXME move this logic to core module
String serialName = dialog.getSerialName().toLowerCase(Locale.getDefault());
DbUserInfo userInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + serialName;
SerialInfo serialInfo = new SerialInfo();
serialInfo.setName(serialName);
serialInfo.setOwner(userInfo.getName());
ICubridNode newNode = CubridSerialFolderLoader.createSerialNode(id, serialInfo);
CommonUITool.addNodeToTree(treeViewer, folderNode, newNode);
CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode);
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD));
}
}
use of com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo 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;
}
Aggregations