Search in sources :

Example 6 with ClassAuthorizations

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations 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 7 with ClassAuthorizations

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.

the class EditUserDialog method initial.

/**
	 * Initial data
	 */
private void initial() {
    if (!CubridDatabase.hasValidDatabaseInfo(database)) {
        LOGGER.error("The database is invalid.");
        return;
    }
    this.currentUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    currentUserAuthorizations = currentUserInfo.getUserAuthorizations();
    for (DbUserInfo userInfo : userListInfo.getUserList()) {
        if (userInfo.getName().equals(currentUserInfo.getName())) {
            currentUserInfo = userInfo;
            currentUserAuthorizations = currentUserInfo.getUserAuthorizations();
            break;
        }
    }
    List<String> groupList = null;
    if (newFlag) {
        userNameText.setEnabled(true);
        classGrantMap = new HashMap<String, ClassAuthorizations>();
        Map<String, String> map = new HashMap<String, String>();
        map.put("0", DB_DEFAULT_USERNAME);
        groupList = new ArrayList<String>();
        groupList.add(DB_DEFAULT_USERNAME);
    } else {
        for (DbUserInfo bean : userListInfo.getUserList()) {
            if (bean.getName().equalsIgnoreCase(userName)) {
                userInfo = bean;
            }
            List<String> groups = bean.getGroups().getGroup();
            if (groups != null) {
                for (String g : groups) {
                    if (userName != null && userName.equalsIgnoreCase(g)) {
                        Map<String, String> map = new HashMap<String, String>();
                        map.put("0", bean.getName());
                        memberListData.add(map);
                    }
                }
            }
        }
        memberTableViewer.refresh();
        if (database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(userName) || database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName().equalsIgnoreCase(DB_DBA_USERNAME)) {
            changePwdBtn.setEnabled(true);
        } else {
            changePwdBtn.setEnabled(false);
        }
        userNameText.setText(userInfo.getName());
        groupList = userInfo.getGroups().getGroup();
        classGrantMap = userInfo.getUserAuthorizations();
        oldLoginPassword = database.getDatabaseInfo().getAuthLoginedDbUserInfo().getNoEncryptPassword();
        if (oldLoginPassword == null) {
            oldLoginPassword = "";
        }
    }
    Map<String, String> groupMap = new HashMap<String, String>();
    Map<String, String> memberMap = new HashMap<String, String>();
    // set group map
    if (groupList == null) {
        groupList = new ArrayList<String>();
    }
    for (String group : groupList) {
        groupMap.put(group.toLowerCase(Locale.getDefault()), "");
    }
    if (memberListData != null) {
        for (Map<String, String> map : memberListData) {
            memberMap.put(map.get("0").toLowerCase(Locale.getDefault()), "");
        }
    }
    for (DbUserInfo user : userListInfo.getUserList()) {
        if (!groupMap.containsKey(user.getName().toLowerCase()) && !memberMap.containsKey(user.getName().toLowerCase()) && !user.getName().equalsIgnoreCase(userName)) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", user.getName().toLowerCase());
            allUserListData.add(map);
        }
    }
    for (String userName : groupList) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("0", userName.toLowerCase(Locale.getDefault()));
        groupListData.add(map);
    }
    allUserTableViewer.refresh();
    groupTableViewer.refresh();
    Iterator<String> authIter = classGrantMap.keySet().iterator();
    while (authIter.hasNext()) {
        String className = authIter.next();
        if (!partitionClassMap.containsKey(className)) {
            authListData.add(getItemAuthMap(classGrantMap.get(className)));
            authListDataOld.add(getItemAuthMap(classGrantMap.get(className)));
        }
    }
    if (!DB_DBA_USERNAME.equalsIgnoreCase(userName) && !isDBAGroup()) {
        authTableViewer.refresh();
        for (ClassInfo bean : allClassInfoList) {
            if (classGrantMap.containsKey(bean.getClassName()) || bean.isSystemClass() || bean.getOwnerName().equalsIgnoreCase(DB_DEFAULT_USERNAME)) {
                continue;
            }
            Map<String, String> map = new HashMap<String, String>();
            map.put("0", bean.getClassName());
            map.put("1", Messages.msgUserSchema);
            map.put("2", bean.getOwnerName());
            map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
            classListData.add(map);
        }
        classTableViewer.refresh();
        packTable(classTable);
        packTable(authTable);
    }
    packTable(allUserTable);
    packTable(userGroupTable);
    packTable(memberTableViewer.getTable());
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) HashMap(java.util.HashMap) ClassInfo(com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)

Example 8 with ClassAuthorizations

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.

the class TableModelTest method testModelClassAuthorizations.

public void testModelClassAuthorizations() {
    ClassAuthorizations bean = new ClassAuthorizations("name", 1);
    bean.setClassName("className");
    assertEquals(bean.getClassName(), "className");
    bean.setSelectPriv(false);
    assertEquals(bean.isSelectPriv(), false);
    bean.setInsertPriv(false);
    assertEquals(bean.isInsertPriv(), false);
    bean.setUpdatePriv(false);
    assertEquals(bean.isUpdatePriv(), false);
    bean.setAlterPriv(false);
    assertEquals(bean.isAlterPriv(), false);
    bean.setDeletePriv(false);
    assertEquals(bean.isDeletePriv(), false);
    bean.setIndexPriv(false);
    assertEquals(bean.isIndexPriv(), false);
    bean.setExecutePriv(false);
    assertEquals(bean.isExecutePriv(), false);
    bean.setGrantSelectPriv(false);
    assertEquals(bean.isGrantSelectPriv(), false);
    bean.setGrantInsertPriv(false);
    assertEquals(bean.isGrantInsertPriv(), false);
    bean.setGrantUpdatePriv(false);
    assertEquals(bean.isGrantUpdatePriv(), false);
    bean.setGrantAlterPriv(false);
    assertEquals(bean.isGrantAlterPriv(), false);
    bean.setGrantDeletePriv(false);
    assertEquals(bean.isGrantDeletePriv(), false);
    bean.setGrantIndexPriv(false);
    assertEquals(bean.isGrantIndexPriv(), false);
    bean.setGrantExecutePriv(false);
    assertEquals(bean.isGrantExecutePriv(), false);
    bean.setAllPriv(false);
    assertEquals(bean.isAllPriv(), false);
    bean.isSelectPriv();
    bean.isInsertPriv();
    bean.isUpdatePriv();
    bean.isAlterPriv();
    bean.isDeletePriv();
    bean.isIndexPriv();
    bean.isExecutePriv();
    bean.isGrantSelectPriv();
    bean.isGrantInsertPriv();
    bean.isGrantUpdatePriv();
    bean.isGrantAlterPriv();
    bean.isGrantDeletePriv();
    bean.isGrantIndexPriv();
    bean.isGrantExecutePriv();
    bean.isAllPriv();
}
Also used : ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations)

Example 9 with ClassAuthorizations

use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.

the class UpdateAddUserJdbcTaskTest method testUpdateUserAuthorizations.

public void testUpdateUserAuthorizations() {
    Map<String, ClassAuthorizations> authorizationsMap = new HashMap<String, ClassAuthorizations>();
    authorizationsMap.put("test_a1", new ClassAuthorizations());
    Map<String, Object> authMap = new HashMap<String, Object>();
    authMap.put("0", "test_a1");
    authMap.put("1", true);
    authMap.put("8", false);
    authMap.put("2", true);
    authMap.put("9", false);
    authMap.put("3", true);
    authMap.put("10", false);
    authMap.put("4", true);
    authMap.put("11", false);
    authMap.put("5", true);
    authMap.put("12", false);
    authMap.put("6", true);
    authMap.put("13", false);
    authMap.put("7", true);
    authMap.put("14", false);
    ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    list.add(authMap);
    UpdateAddUserJdbcTask task = new UpdateAddUserJdbcTask(databaseInfo, "testuser", authorizationsMap, list, false, false);
    task.setDba(false);
    task.isDba();
    task.execute();
    authMap = new HashMap<String, Object>();
    authMap.put("0", "test_a1");
    authMap.put("1", false);
    authMap.put("8", true);
    authMap.put("2", false);
    authMap.put("9", true);
    authMap.put("3", false);
    authMap.put("10", true);
    authMap.put("4", false);
    authMap.put("11", true);
    authMap.put("5", false);
    authMap.put("12", true);
    authMap.put("6", false);
    authMap.put("13", true);
    authMap.put("7", false);
    authMap.put("14", true);
    list.clear();
    list.add(authMap);
    task = new UpdateAddUserJdbcTask(databaseInfo, "testuser", authorizationsMap, list, false, false);
    task.execute();
    authMap = new HashMap<String, Object>();
    authMap.put("0", "test_a1");
    authMap.put("1", false);
    authMap.put("2", false);
    authMap.put("3", false);
    authMap.put("4", false);
    authMap.put("5", false);
    authMap.put("6", false);
    authMap.put("7", false);
    authMap.put("8", false);
    authMap.put("9", false);
    authMap.put("10", false);
    authMap.put("11", false);
    authMap.put("12", false);
    authMap.put("13", false);
    authMap.put("14", false);
    Map<String, Object> grantMap = new HashMap<String, Object>();
    grantMap.put("0", "test_a1");
    grantMap.put("1", true);
    grantMap.put("2", true);
    grantMap.put("3", true);
    grantMap.put("4", true);
    grantMap.put("5", true);
    grantMap.put("6", true);
    grantMap.put("7", true);
    grantMap.put("8", true);
    grantMap.put("9", true);
    grantMap.put("10", true);
    grantMap.put("11", true);
    grantMap.put("12", true);
    grantMap.put("13", true);
    grantMap.put("14", true);
    list.clear();
    list.add(authMap);
    ArrayList<Map<String, Object>> listOld = new ArrayList<Map<String, Object>>();
    listOld.add(grantMap);
    task = new UpdateAddUserJdbcTask(databaseInfo, "testuser", authorizationsMap, list, listOld, false, false);
    task.execute();
}
Also used : ClassAuthorizations(com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ClassAuthorizations (com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations)9 HashMap (java.util.HashMap)8 ClassInfo (com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo)5 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)4 Map (java.util.Map)4 GridData (org.eclipse.swt.layout.GridData)2 TableItem (org.eclipse.swt.widgets.TableItem)2 TableViewerSorter (com.cubrid.common.ui.spi.TableViewerSorter)1 ArrayList (java.util.ArrayList)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 CheckboxCellEditor (org.eclipse.jface.viewers.CheckboxCellEditor)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 CLabel (org.eclipse.swt.custom.CLabel)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 FocusAdapter (org.eclipse.swt.events.FocusAdapter)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridLayout (org.eclipse.swt.layout.GridLayout)1