Search in sources :

Example 1 with UserDetailInfo

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

the class DBAuthComparator method dropUser.

/**
	 * drop User
	 */
public void dropUser() {
    TableItem[] items = userTableViewer.getTable().getSelection();
    if (items.length == 1) {
        TableItem item = items[0];
        UserDetailInfo userInfo = (UserDetailInfo) item.getData();
        String msg = Messages.bind(Messages.msgDoYouWantToDeleteUser, userInfo.getUserName());
        if (!CommonUITool.openConfirmBox(msg)) {
            return;
        }
        Set<String> typeSet = new HashSet<String>();
        typeSet.add(NodeType.USER);
        ICubridNode userNode = CommonUITool.findNode(database, typeSet, userInfo.getUserName());
        if (userNode != null) {
            DeleteUserAction action = (DeleteUserAction) ActionManager.getInstance().getAction(DeleteUserAction.ID);
            action.doRun((ISchemaNode) userNode);
            refresh();
        }
    } else {
        CommonUITool.openWarningBox(Messages.errNoUserSelected);
    }
}
Also used : DeleteUserAction(com.cubrid.common.ui.cubrid.user.action.DeleteUserAction) TableItem(org.eclipse.swt.widgets.TableItem) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) UserDetailInfo(com.cubrid.cubridmanager.core.cubrid.user.model.UserDetailInfo) HashSet(java.util.HashSet)

Example 2 with UserDetailInfo

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

the class GetAllUserAuthorizationsTask method execute.

public void execute() {
    String sql = "SELECT grantor_name, grantee_name, class_name, auth_type, is_grantable FROM db_auth";
    sql = databaseInfo.wrapShardQuery(sql);
    try {
        stmt = connection.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            //String grantorName = rs.getString("grantor_name");
            String granteeName = rs.getString("grantee_name");
            String className = rs.getString("class_name");
            String authType = rs.getString("auth_type");
            boolean isGrantable = StringUtil.booleanValueWithYN(rs.getString("is_grantable"));
            //				}
            if (StringUtil.isEmpty(className)) {
                continue;
            }
            if (granteeName != null) {
                granteeName = granteeName.toLowerCase(Locale.getDefault());
            }
            UserDetailInfo userInfo = allAuthMap.get(granteeName);
            if (userInfo == null) {
                userInfo = new UserDetailInfo();
                userInfo.setUserName(granteeName);
                allAuthMap.put(granteeName, userInfo);
            }
            AuthType type = AuthType.getAuthType(authType, isGrantable);
            userInfo.addAuth(className, type);
        }
    } catch (SQLException e) {
        errorMsg = e.getMessage();
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    loadDetailInfo();
    finish();
}
Also used : SQLException(java.sql.SQLException) AuthType(com.cubrid.cubridmanager.core.cubrid.user.model.AuthType) UserDetailInfo(com.cubrid.cubridmanager.core.cubrid.user.model.UserDetailInfo)

Example 3 with UserDetailInfo

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

the class GetAllUserAuthorizationsTask method loadDetailInfo.

private void loadDetailInfo() {
    String sql = "SELECT class_name, owner_name, class_type " + "FROM db_class " + "WHERE is_system_class = 'NO' AND partitioned = 'NO' ";
    sql = databaseInfo.wrapShardQuery(sql);
    Statement stmt = null;
    /*Add dba user first*/
    UserDetailInfo dbaUserInfo = allAuthMap.get("dba");
    if (dbaUserInfo == null) {
        dbaUserInfo = new UserDetailInfo();
        dbaUserInfo.setUserName("dba");
    }
    try {
        stmt = connection.createStatement();
        rs = stmt.executeQuery(sql);
        while (rs.next()) {
            String className = rs.getString("class_name");
            String ownerName = rs.getString("owner_name");
            String classType = rs.getString("class_type");
            boolean isTable = "CLASS".equals(classType);
            if (ConstantsUtil.isExtensionalSystemTable(className)) {
                continue;
            }
            if (ownerName != null) {
                ownerName = ownerName.toLowerCase(Locale.getDefault());
            }
            UserDetailInfo userDetailInfo = allAuthMap.get(ownerName);
            if (!allAuthMap.containsKey(ownerName)) {
                userDetailInfo = new UserDetailInfo();
                userDetailInfo.setUserName(ownerName);
                allAuthMap.put(ownerName, userDetailInfo);
            }
            /*Add auth to dba*/
            DBAuth dbaAuth = dbaUserInfo.getAuth(className);
            if (dbaAuth == null) {
                dbaAuth = new DBAuth(className, AuthType.ALL);
                dbaAuth.setOwner(ownerName);
                dbaAuth.setTable(isTable);
                dbaUserInfo.addAuth(dbaAuth);
            } else {
                dbaAuth.setOwner(ownerName);
                dbaAuth.setTable(isTable);
                dbaUserInfo.addAuth(className, AuthType.ALL);
            }
            /*add auth to public user*/
            for (UserDetailInfo userInfo : allAuthMap.values()) {
                DBAuth dbAuth = userInfo.getAuth(className);
                if (dbAuth == null) {
                    if (StringUtil.isEqual(ownerName, userInfo.getUserName())) {
                        dbAuth = new DBAuth(className, AuthType.ALL);
                        dbAuth.setOwner(ownerName);
                        dbAuth.setTable(isTable);
                        userInfo.addAuth(dbAuth);
                    } else {
                        continue;
                    }
                } else {
                    dbAuth.setOwner(ownerName);
                    dbAuth.setTable(isTable);
                }
            }
        }
    } catch (SQLException e) {
        errorMsg = e.getMessage();
    } finally {
        QueryUtil.freeQuery(stmt, rs);
    }
    allAuthMap.put(dbaUserInfo.getUserName(), dbaUserInfo);
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) DBAuth(com.cubrid.cubridmanager.core.cubrid.user.model.DBAuth) UserDetailInfo(com.cubrid.cubridmanager.core.cubrid.user.model.UserDetailInfo)

Example 4 with UserDetailInfo

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

the class DBAuthComparator method createUsersTable.

/**
	 * create user table
	 * 
	 * @param parent
	 */
public void createUsersTable(Composite parent) {
    userTableViewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    userTableViewer.getTable().setHeaderVisible(false);
    userTableViewer.getTable().setLinesVisible(false);
    userTableViewer.getTable().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    final TableViewerColumn nameColumn = new TableViewerColumn(userTableViewer, SWT.LEFT);
    nameColumn.getColumn().setWidth(200);
    userTableViewer.setContentProvider(new UserContentProvider());
    userTableViewer.setLabelProvider(new UserLabelProvider());
    registerContextMenu();
    userTableViewer.getTable().addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            TableItem[] items = userTableViewer.getTable().getSelection();
            if (items.length == 1) {
                UserDetailInfo userInfo = (UserDetailInfo) items[0].getData();
                setAuthDetailInfoTableViewer(userInfo);
            }
        }
    });
}
Also used : SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) SelectionListener(org.eclipse.swt.events.SelectionListener) UserDetailInfo(com.cubrid.cubridmanager.core.cubrid.user.model.UserDetailInfo)

Example 5 with UserDetailInfo

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

Aggregations

UserDetailInfo (com.cubrid.cubridmanager.core.cubrid.user.model.UserDetailInfo)6 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 SQLException (java.sql.SQLException)2 HashSet (java.util.HashSet)2 TableItem (org.eclipse.swt.widgets.TableItem)2 ITask (com.cubrid.common.core.task.ITask)1 DeleteUserAction (com.cubrid.common.ui.cubrid.user.action.DeleteUserAction)1 EditUserAction (com.cubrid.common.ui.cubrid.user.action.EditUserAction)1 CommonTaskJobExec (com.cubrid.common.ui.spi.progress.CommonTaskJobExec)1 ITaskExecutorInterceptor (com.cubrid.common.ui.spi.progress.ITaskExecutorInterceptor)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskJobExecutor (com.cubrid.common.ui.spi.progress.TaskJobExecutor)1 AuthType (com.cubrid.cubridmanager.core.cubrid.user.model.AuthType)1 DBAuth (com.cubrid.cubridmanager.core.cubrid.user.model.DBAuth)1 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)1 DbUserInfoList (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfoList)1 GetAllUserAuthorizationsTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetAllUserAuthorizationsTask)1 GetUserListTask (com.cubrid.cubridmanager.core.cubrid.user.task.GetUserListTask)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1