Search in sources :

Example 56 with DbUserInfo

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

the class CubridWorkbenchContrItem method connectDatabase.

/**
	 * Connect the database
	 *
	 * @param dbInfo DatabaseInfo
	 * @param showErrMsg boolean
	 * @return boolean
	 */
public static boolean connectDatabase(DatabaseInfo dbInfo, boolean showErrMsg) {
    if (dbInfo == null || dbInfo.getServerInfo() == null || dbInfo.getAuthLoginedDbUserInfo() == null) {
        return false;
    }
    final String USER_DBA = "dba";
    DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
    String dbUser = dbUserInfo.getName();
    String dbPassword = dbUserInfo.getNoEncryptPassword();
    if (dbUser == null || dbUser.trim().length() == 0 || dbPassword == null) {
        return false;
    }
    TaskExecutor taskExcutor = new LoginDatabaseTaskExecutor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dbInfo.getServerInfo(), dbInfo.getDbName(), dbUser, dbPassword, showErrMsg);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    boolean isSuccess = taskExcutor.isSuccess();
    if (!isSuccess) {
        LOGGER.error("login database failed");
    }
    /*For [TOOLS-3516]*/
    if (dbInfo.getAuthLoginedDbUserInfo() != null && CompatibleUtil.isNeedCheckDbaAuthorityByJDBC(dbInfo)) {
        IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
        checkTask.execute();
        if (checkTask.isSuccess()) {
            dbInfo.getAuthLoginedDbUserInfo().setDbaAuthority(checkTask.isDBAUser());
        } else {
            dbInfo.getAuthLoginedDbUserInfo().setDbaAuthority(USER_DBA.equals(dbUser.toLowerCase()));
        }
    }
    /*Modify*/
    CMDBNodePersistManager.getInstance().fireModifyDatabase(dbInfo, dbInfo);
    return taskExcutor.isSuccess();
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) LoginDatabaseTaskExecutor(com.cubrid.cubridmanager.ui.cubrid.database.dialog.LoginDatabaseTaskExecutor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) LoginDatabaseTaskExecutor(com.cubrid.cubridmanager.ui.cubrid.database.dialog.LoginDatabaseTaskExecutor)

Example 57 with DbUserInfo

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
	 * @param showErrMsg boolean
	 * @return string error messages
	 */
public static String connectDatabaseWithErrMsg(DatabaseInfo dbInfo, boolean showErrMsg) {
    if (dbInfo == null || dbInfo.getServerInfo() == null || dbInfo.getAuthLoginedDbUserInfo() == null) {
        return "";
    }
    final String USER_DBA = "dba";
    DbUserInfo dbUserInfo = dbInfo.getAuthLoginedDbUserInfo();
    String dbUser = dbUserInfo.getName();
    String dbPassword = dbUserInfo.getNoEncryptPassword();
    if (dbUser == null || dbUser.trim().length() == 0 || dbPassword == null) {
        return Messages.errMultiDatabaseLoginNoUsername;
    }
    LoginDatabaseTaskExecutor taskExcutor = new LoginDatabaseTaskExecutor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dbInfo.getServerInfo(), dbInfo.getDbName(), dbUser, dbPassword, showErrMsg);
    new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
    /*For [TOOLS-3516]*/
    if (dbInfo.getAuthLoginedDbUserInfo() != null && CompatibleUtil.isNeedCheckDbaAuthorityByJDBC(dbInfo)) {
        IsDBAUserTask checkTask = new IsDBAUserTask(dbInfo);
        checkTask.execute();
        if (checkTask.isSuccess()) {
            dbInfo.getAuthLoginedDbUserInfo().setDbaAuthority(checkTask.isDBAUser());
        } else {
            dbInfo.getAuthLoginedDbUserInfo().setDbaAuthority(USER_DBA.equals(dbUser.toLowerCase()));
        }
    }
    /*Modify*/
    CMDBNodePersistManager.getInstance().fireModifyDatabase(dbInfo, dbInfo);
    return taskExcutor.getErrMsg();
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) IsDBAUserTask(com.cubrid.cubridmanager.core.cubrid.user.task.IsDBAUserTask) LoginDatabaseTaskExecutor(com.cubrid.cubridmanager.ui.cubrid.database.dialog.LoginDatabaseTaskExecutor)

Example 58 with DbUserInfo

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

the class EditUserDialog method setAuthBtnEnableDisable.

/**
	 * Set the auth button disable
	 * 
	 */
@SuppressWarnings("unchecked")
private void setAuthBtnEnableDisable() {
    grantButton.setEnabled(false);
    revokeButton.setEnabled(false);
    /*Can't grant/revoke for  current login user*/
    if (StringUtil.isEqual(this.userName, currentUserInfo.getName())) {
        return;
    }
    DbUserInfo currentUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    boolean isDbaAuthority = currentUserInfo.isDbaAuthority();
    if (classTable.getSelectionCount() > 0 && classTable.isFocusControl()) {
        boolean tag = true;
        if (!isDbaAuthority) {
            for (TableItem item : classTable.getSelection()) {
                ClassAuthorizations authorizations = currentUserAuthorizations.get(item.getText());
                boolean ownertag = false;
                for (ClassInfo bean : allClassInfoList) {
                    if (item.getText().equals(bean.getClassName())) {
                        if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
                            ownertag = true;
                        }
                        break;
                    }
                }
                tag = tag && (ownertag || authorizations == null || authorizations.isGrantPriv());
                if (!tag) {
                    break;
                }
            }
        }
        grantButton.setEnabled(tag);
    } else if (authTable.getSelectionCount() > 0 && authTable.isFocusControl()) {
        boolean tag = true;
        if (!isDbaAuthority) {
            for (TableItem item : authTable.getSelection()) {
                ClassAuthorizations authorizations = currentUserAuthorizations.get(item.getText());
                boolean ownertag = false;
                for (ClassInfo bean : allClassInfoList) {
                    if (item.getText().equals(bean.getClassName())) {
                        if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
                            ownertag = true;
                        }
                        break;
                    }
                }
                tag = tag && (ownertag || authorizations == null || (authorizations.isAllPriv() || authorizations.isRevokePriv((Map<String, Object>) item.getData())));
                if (!tag) {
                    break;
                }
            }
        }
        revokeButton.setEnabled(tag);
    }
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) TableItem(org.eclipse.swt.widgets.TableItem) Map(java.util.Map) HashMap(java.util.HashMap) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 59 with DbUserInfo

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

the class DBAuthComparator method loadData.

/**
	 * Load the data
	 */
private void loadData() {
    final GetUserListTask getUserTask = new GetUserListTask(database.getDatabaseInfo());
    final GetAllUserAuthorizationsTask getUserAuthTask = new GetAllUserAuthorizationsTask(database.getDatabaseInfo());
    TaskJobExecutor taskExec = new CommonTaskJobExec(new ITaskExecutorInterceptor() {

        public void completeAll() {
            final List<UserDetailInfo> userDetailList = new ArrayList<UserDetailInfo>();
            DbUserInfoList userListInfo = getUserTask.getResultModel();
            Map<String, UserDetailInfo> allUserAuthMap = getUserAuthTask.getAllAuthMap();
            if (userListInfo != null) {
                for (DbUserInfo userInfo : userListInfo.getUserList()) {
                    UserDetailInfo userDetailInfo = allUserAuthMap.get(userInfo.getName());
                    if (userDetailInfo == null) {
                        userDetailInfo = new UserDetailInfo();
                        userDetailInfo.setUserName(userInfo.getName());
                    }
                    userDetailList.add(userDetailInfo);
                }
            }
            setTableData(userDetailList);
        }

        public IStatus postTaskFinished(ITask task) {
            return Status.OK_STATUS;
        }
    });
    taskExec.addTask(getUserTask);
    taskExec.addTask(getUserAuthTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.jobLoadUserData + " - " + "@" + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, false, Job.SHORT);
}
Also used : TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITaskExecutorInterceptor(com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor) ITask(com.cubrid.common.core.task.ITask) IStatus(org.eclipse.core.runtime.IStatus) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) GetAllUserAuthorizationsTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetAllUserAuthorizationsTask) GetUserListTask(com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) CommonTaskJobExec(com.cubrid.common.ui.spi.progress.CommonTaskJobExec) List(java.util.List) ArrayList(java.util.ArrayList) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) DbUserInfoList(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList) Map(java.util.Map) UserDetailInfo(com.cubrid.cubridmanager.core.cubrid.user.model.UserDetailInfo)

Example 60 with DbUserInfo

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

the class DeleteUserAction method isSupported.

/**
	 *
	 * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
	 *      .lang.Object)
	 * @param obj the Object
	 * @return <code>true</code> if support this obj;<code>false</code>
	 *         otherwise
	 */
public boolean isSupported(Object obj) {
    if (!(obj instanceof ISchemaNode)) {
        return false;
    }
    ISchemaNode node = (ISchemaNode) obj;
    CubridDatabase database = node.getDatabase();
    if (database != null && database.getRunningType() == DbRunningType.CS && database.isLogined()) {
        DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
        if (dbUserInfo == null) {
            return false;
        }
        if (EditUserDialog.DB_DEFAULT_USERNAME.equalsIgnoreCase(node.getName()) || EditUserDialog.DB_DBA_USERNAME.equalsIgnoreCase(node.getName())) {
            return false;
        }
        if (dbUserInfo.getName() != null && dbUserInfo.getName().equalsIgnoreCase(node.getName())) {
            return false;
        }
        if (dbUserInfo != null && dbUserInfo.isDbaAuthority()) {
            return true;
        }
    }
    return false;
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) 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