use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.
the class EditUserDialog method createAuthComposite.
/**
* Create auth composite
*
* @return the composite
*/
private Composite createAuthComposite() {
final Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout();
composite.setLayout(layout);
Label classTableDescLabel = new Label(composite, SWT.NONE);
classTableDescLabel.setText(Messages.lblUnAuthorizedTable);
final String[] columnNameArr = new String[] { Messages.tblColClassName, Messages.tblColClassSchematype, Messages.tblColClassOwner, Messages.tblColClassType };
classTableViewer = CommonUITool.createCommonTableViewer(composite, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
classTableViewer.setInput(classListData);
classTable = classTableViewer.getTable();
classTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
final Composite cmpControl = new Composite(composite, SWT.NONE);
final GridData gdCmpControl = new GridData(SWT.CENTER, SWT.FILL, false, false);
cmpControl.setLayoutData(gdCmpControl);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
cmpControl.setLayout(gridLayout);
grantButton = new Button(cmpControl, SWT.LEFT);
grantButton.setEnabled(false);
grantButton.setText(Messages.addClassButtonName);
grantButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = classTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int i : idx) {
String className = classTable.getItem(i).getText(0);
for (Map<String, String> map : classListData) {
if (map.get("0").equals(className)) {
classListData.remove(map);
break;
}
}
ClassAuthorizations classAuthorizations = classGrantMap.get(className);
if (classAuthorizations == null) {
classAuthorizations = new ClassAuthorizations();
classAuthorizations.setClassName(className);
classAuthorizations.setSelectPriv(true);
}
authListData.add(getItemAuthMap(classAuthorizations));
}
classTableViewer.refresh();
authTableViewer.refresh();
if (authTableViewer.getTable().getColumn(0) != null) {
authTableViewer.getTable().getColumn(0).pack();
}
setAuthBtnEnableDisable();
}
});
revokeButton = new Button(cmpControl, SWT.NONE);
revokeButton.setEnabled(false);
revokeButton.setText(Messages.deleteClassButtonName);
revokeButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
int[] idx = authTable.getSelectionIndices();
if (idx.length < 0) {
return;
}
for (int id : idx) {
String tableName = authTable.getItem(id).getText(0);
for (ClassInfo bean : allClassInfoList) {
if (tableName.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
CommonUITool.openErrorBox(parentComp.getShell(), Messages.errRemoveSysClass);
return;
} else {
Map<String, String> map = new HashMap<String, String>();
map.put("0", bean.getClassName());
map.put("1", bean.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
map.put("2", bean.getOwnerName());
map.put("3", bean.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
classListData.add(map);
}
}
}
for (Map<String, Object> map : authListData) {
String className = (String) map.get("0");
if (tableName.equals(className)) {
authListData.remove(map);
break;
}
}
}
authTableViewer.refresh();
classTableViewer.refresh();
setAuthBtnEnableDisable();
}
});
Label authTableDescLabel = new Label(composite, SWT.NONE);
authTableDescLabel.setText(Messages.lblAuthorizedTable);
final String[] authColumnNameArr = new String[] { Messages.tblColAuthTable, Messages.tblColAuthSelect, Messages.tblColAuthInsert, Messages.tblColAuthUpdate, Messages.tblColAuthDelete, Messages.tblColAuthAlter, Messages.tblColAuthIndex, Messages.tblColAuthExecute, Messages.tblColAuthGrantselect, Messages.tblColAuthGrantinsert, Messages.tblColAuthGrantupdate, Messages.tblColAuthGrantdelete, Messages.tblColAuthGrantalter, Messages.tblColAuthGrantindex, Messages.tblColAuthGrantexecute };
authTableViewer = createCommonTableViewer(composite, authColumnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
authTableViewer.setLabelProvider(new AuthTableLabelProvider());
authTableViewer.setInput(authListData);
authTable = authTableViewer.getTable();
CellEditor[] editors = new CellEditor[15];
editors[0] = null;
for (int i = 1; i < 15; i++) {
editors[i] = new CheckboxCellEditor(authTable, SWT.READ_ONLY);
}
authTableViewer.setColumnProperties(authColumnNameArr);
authTableViewer.setCellEditors(editors);
authTableViewer.setCellModifier(new ICellModifier() {
@SuppressWarnings("unchecked")
public boolean canModify(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
boolean isDbaAuthority = database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority();
if (isDbaAuthority) {
return true;
}
/*Can't grant/revoke for current login user*/
if (StringUtil.isEqual(userName, currentUserInfo.getName())) {
return false;
}
String name = (String) map.get("0");
for (ClassInfo bean : allClassInfoList) {
if (name.equals(bean.getClassName())) {
if (bean.isSystemClass()) {
return false;
} else if (currentUserInfo.getName().equalsIgnoreCase(bean.getOwnerName())) {
return true;
}
}
}
ClassAuthorizations authorizations = currentUserAuthorizations.get(name);
if (authorizations == null || authorizations.isAllPriv() || authorizations.isPriv(property)) {
return true;
} else {
return false;
}
}
@SuppressWarnings("unchecked")
public Object getValue(Object element, String property) {
Map<String, Object> map = (Map<String, Object>) element;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
return Boolean.valueOf((Boolean) map.get("" + i));
}
}
return null;
}
@SuppressWarnings("unchecked")
public void modify(Object element, String property, Object value) {
Object elementData;
elementData = element;
if (element instanceof Item) {
elementData = ((Item) element).getData();
}
String key = "";
Map<String, Object> map = (Map<String, Object>) elementData;
for (int i = 1; i < 15; i++) {
if (property.equals(authColumnNameArr[i])) {
key = "" + i;
break;
}
}
if (value instanceof Boolean) {
map.put(key, ((Boolean) value).booleanValue());
}
authTableViewer.refresh();
}
});
authTable.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {
}
public void widgetSelected(SelectionEvent event) {
setAuthBtnEnableDisable();
}
});
authTable.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
setAuthBtnEnableDisable();
}
});
return composite;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.
the class GetUserAuthorizationsTask method getViewAuthorizationsByViewName.
/**
*
* get view privilege information
* @param viewName owner
* @param viewName String
* @throws SQLException The exception
*/
public Map<String, ClassAuthorizations> getViewAuthorizationsByViewName(String userName, String viewName) throws SQLException {
if (viewName == null || userName == null) {
return null;
}
Map<String, ClassAuthorizations> userAuthMap = new HashMap<String, ClassAuthorizations>();
String sql = "SELECT a.auth_type, a.grantee_name, a.class_name, a.is_grantable" + " FROM db_auth a, db_vclass v" + " WHERE a.class_name=v.vclass_name" + " AND a.grantee_name<>UPPER('" + userName + "')" + " AND a.class_name='" + viewName + "'";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String type = rs.getString("auth_type");
String grantable = rs.getString("is_grantable");
String granteeName = rs.getString("grantee_name");
String className = rs.getString("class_name");
if (granteeName == null || granteeName.trim().length() == 0) {
continue;
}
ClassAuthorizations auth = userAuthMap.get(granteeName);
if (auth == null) {
auth = new ClassAuthorizations();
auth.setClassName(className);
userAuthMap.put(granteeName, auth);
}
makeAuthorizations(type, grantable, auth);
}
} finally {
finish();
}
return userAuthMap;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.
the class CQBUserEditor method initial.
/**
* Initial the data
*/
private void initial() {
if (ownerClassTableViewer == null || ownerClassTableViewer.getControl() == null || ownerClassTableViewer.getControl().isDisposed()) {
return;
}
if (memberList == null) {
memberList = new ArrayList<String>();
}
while (!memberList.isEmpty()) {
memberList.remove(0);
}
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)) {
memberList.add(bean.getName());
break;
}
}
}
}
List<String> groupList = userInfo.getGroups().getGroup();
while (!ownerClassListData.isEmpty()) {
ownerClassListData.remove(0);
}
if (allClassInfoList != null) {
for (ClassInfo c : allClassInfoList) {
if (!c.getOwnerName().equalsIgnoreCase(userInfo.getName())) {
continue;
}
Map<String, String> map = new HashMap<String, String>();
map.put("0", c.getClassName());
map.put("1", c.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
map.put("2", c.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
ownerClassListData.add(map);
}
}
while (!authListData.isEmpty()) {
authListData.remove(0);
}
Map<String, ClassAuthorizations> classGrantMap = userInfo.getUserAuthorizations();
Iterator<String> authIter = classGrantMap.keySet().iterator();
while (authIter.hasNext()) {
String className = authIter.next();
if (!partitionClassMap.containsKey(className)) {
authListData.add(getItemAuthMap(classGrantMap.get(className)));
}
}
ownerClassTableViewer.refresh();
if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
authTableViewer.refresh();
}
for (int i = 0; i < ownerClassTableViewer.getTable().getColumnCount(); i++) {
ownerClassTableViewer.getTable().getColumn(i).pack();
}
if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
for (int i = 0; i < authTableViewer.getTable().getColumnCount(); i++) {
authTableViewer.getTable().getColumn(i).pack();
}
}
StringBuffer sb = new StringBuffer();
if (groupList != null) {
for (int i = 0, n = groupList.size(); i < n; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(groupList.get(i));
}
}
lblUserGroup.setText(Messages.bind(Messages.lblGroupList, sb.length() < 1 ? Messages.lblGroupNotExist : sb.toString()));
sb = new StringBuffer();
if (memberList != null) {
for (int i = 0, n = memberList.size(); i < n; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(memberList.get(i));
}
}
lblUserMember.setText(Messages.bind(Messages.lblMemberList, sb.length() < 1 ? Messages.lblMemberNotExist : sb.toString()));
if (checkIsDba()) {
authTableViewer.getTable().setVisible(false);
GridData tableGd = (GridData) authTableViewer.getTable().getLayoutData();
tableGd.exclude = true;
CLabel clbl = new CLabel(authComp, SWT.NONE);
clbl.setBackground(topComp.getBackground());
clbl.setText(Messages.lblDbaAllAuth);
}
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.
the class GetUserAuthorizationsTask method getUserAuthorizations.
/**
* get privilege information
*
* @param userName String
* @throws SQLException The exception
*/
public Map<String, ClassAuthorizations> getUserAuthorizations(String userName) throws SQLException {
Map<String, ClassAuthorizations> userAuthMap = new HashMap<String, ClassAuthorizations>();
if (userName == null) {
return userAuthMap;
}
String sql = "SELECT a.class_name, a.auth_type, a.is_grantable" + " FROM db_auth a" + " WHERE a.grantee_name=UPPER('" + userName + "')" + " AND NOT EXISTS (SELECT 1 FROM db_partition p" + " WHERE a.class_name=LOWER(p.partition_class_name))";
// [TOOLS-2425]Support shard broker
sql = databaseInfo.wrapShardQuery(sql);
try {
stmt = connection.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
String className = rs.getString("class_name");
String type = rs.getString("auth_type");
String grantable = rs.getString("is_grantable");
if (className == null || className.trim().length() == 0) {
continue;
}
ClassAuthorizations auth = userAuthMap.get(className);
if (auth == null) {
auth = new ClassAuthorizations();
auth.setClassName(className);
userAuthMap.put(className, auth);
}
makeAuthorizations(type, grantable, auth);
}
} finally {
finish();
}
return userAuthMap;
}
use of com.cubrid.cubridmanager.core.cubrid.table.model.ClassAuthorizations in project cubrid-manager by CUBRID.
the class UserEditor method initial.
/**
*
* Initial the data
*
*/
private void initial() {
if (ownerClassTableViewer == null || ownerClassTableViewer.getControl() == null || ownerClassTableViewer.getControl().isDisposed()) {
return;
}
if (memberList == null) {
memberList = new ArrayList<String>();
}
while (!memberList.isEmpty()) {
memberList.remove(0);
}
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)) {
memberList.add(bean.getName());
break;
}
}
}
}
List<String> groupList = userInfo.getGroups().getGroup();
while (!ownerClassListData.isEmpty()) {
ownerClassListData.remove(0);
}
if (allClassInfoList != null) {
for (ClassInfo c : allClassInfoList) {
if (c.getOwnerName().equalsIgnoreCase(userInfo.getName())) {
Map<String, String> map = new HashMap<String, String>();
map.put("0", c.getClassName());
map.put("1", c.isSystemClass() ? Messages.msgSystemSchema : Messages.msgUserSchema);
map.put("2", c.getClassType() == ClassType.VIEW ? Messages.msgVirtualClass : Messages.msgClass);
ownerClassListData.add(map);
}
}
}
while (!authListData.isEmpty()) {
authListData.remove(0);
}
Map<String, String> classGrantMap = userInfo.getAuthorization();
Iterator<Map.Entry<String, String>> it = classGrantMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
String className = entry.getKey();
if (!partitionClassMap.containsKey(className)) {
String authNum = entry.getValue();
authListData.add(getItemAuthMap(new ClassAuthorizations(className, CommonUITool.str2Int(authNum))));
}
}
ownerClassTableViewer.refresh();
if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
authTableViewer.refresh();
}
for (int i = 0; i < ownerClassTableViewer.getTable().getColumnCount(); i++) {
ownerClassTableViewer.getTable().getColumn(i).pack();
}
if (!DB_DBA_USERNAME.equalsIgnoreCase(userName)) {
for (int i = 0; i < authTableViewer.getTable().getColumnCount(); i++) {
authTableViewer.getTable().getColumn(i).pack();
}
}
StringBuffer sb = new StringBuffer();
if (groupList != null) {
for (int i = 0, n = groupList.size(); i < n; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(groupList.get(i));
}
}
lblUserGroup.setText(Messages.bind(Messages.lblGroupList, sb.length() < 1 ? Messages.lblGroupNotExist : sb.toString()));
sb = new StringBuffer();
if (memberList != null) {
for (int i = 0, n = memberList.size(); i < n; i++) {
if (i > 0) {
sb.append(", ");
}
sb.append(memberList.get(i));
}
}
lblUserMember.setText(Messages.bind(Messages.lblMemberList, sb.length() < 1 ? Messages.lblMemberNotExist : sb.toString()));
}
Aggregations