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);
}
}
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());
}
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();
}
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();
}
Aggregations