Search in sources :

Example 56 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class GetCMUserListTask method buildUserInfo.

/**
	 * 
	 * Build user info
	 * 
	 * @param serverUserInfoList List<ServerUserInfo> The given list that stored
	 *        some instance of ServerUserInfo
	 * @param node TreeNode
	 */
private void buildUserInfo(List<ServerUserInfo> serverUserInfoList, TreeNode node) {
    for (int j = 0; j < node.childrenSize(); j++) {
        TreeNode node1 = node.getChildren().get(j);
        if (node1.getValue("open") == null || !node1.getValue("open").trim().equals("user")) {
            continue;
        }
        String userId = node1.getValue("id");
        if (userId == null) {
            continue;
        }
        String password = node1.getValue("passwd");
        String casAuthInfo = node1.getValue("casauth");
        String dbCreater = node1.getValue("dbcreate");
        String statusMonitorAuthInfo = node1.getValue("statusmonitorauth");
        ServerUserInfo userInfo = new ServerUserInfo(userId, password);
        CasAuthType casAuthType = CasAuthType.AUTH_NONE;
        if (casAuthInfo != null && casAuthInfo.trim().equals(CasAuthType.AUTH_ADMIN.getText())) {
            casAuthType = CasAuthType.AUTH_ADMIN;
        } else if (casAuthInfo != null && casAuthInfo.trim().equals(CasAuthType.AUTH_MONITOR.getText())) {
            casAuthType = CasAuthType.AUTH_MONITOR;
        }
        userInfo.setCasAuth(casAuthType);
        StatusMonitorAuthType statusMonitorAuth = StatusMonitorAuthType.AUTH_NONE;
        if (statusMonitorAuthInfo != null && statusMonitorAuthInfo.trim().equals(StatusMonitorAuthType.AUTH_ADMIN.getText())) {
            statusMonitorAuth = StatusMonitorAuthType.AUTH_ADMIN;
        } else if (statusMonitorAuthInfo != null && statusMonitorAuthInfo.trim().equals(StatusMonitorAuthType.AUTH_MONITOR.getText())) {
            statusMonitorAuth = StatusMonitorAuthType.AUTH_MONITOR;
        }
        userInfo.setStatusMonitorAuth(statusMonitorAuth);
        if (userInfo.isAdmin()) {
            userInfo.setStatusMonitorAuth(StatusMonitorAuthType.AUTH_ADMIN);
        }
        if (dbCreater != null && dbCreater.equals(DbCreateAuthType.AUTH_ADMIN.getText())) {
            userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_ADMIN);
        } else {
            userInfo.setDbCreateAuthType(DbCreateAuthType.AUTH_NONE);
        }
        if (userInfo.getUserName().equals(serverInfo.getUserName())) {
            userInfo.setPassword(serverInfo.getUserPassword());
        }
        buildDbAuthInfo(node1, userInfo);
        serverUserInfoList.add(userInfo);
    }
}
Also used : CasAuthType(com.cubrid.cubridmanager.core.common.model.CasAuthType) StatusMonitorAuthType(com.cubrid.cubridmanager.core.common.model.StatusMonitorAuthType) TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 57 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class UserManagementTableViewerSorter method createDialogArea.

/**
	 * Create dialog area content
	 * 
	 * @param parent the parent composite
	 * @return the control
	 */
protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    Label tipLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
    tipLabel.setText(Messages.msgUserManagementList);
    tipLabel.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    // create CUBRID Manager user information table
    String[] columnNameArr = new String[] { Messages.tblColumnUserId, Messages.tblColumnDbAuth, Messages.tblColumnBrokerAuth, Messages.tblColumnMonitorAuth };
    final ServerType serverType = server.getServerInfo().getServerType();
    if (serverType == ServerType.DATABASE) {
        columnNameArr = new String[] { Messages.tblColumnUserId, Messages.tblColumnDbAuth, Messages.tblColumnMonitorAuth };
    } else if (serverType == ServerType.BROKER) {
        columnNameArr = new String[] { Messages.tblColumnUserId, Messages.tblColumnBrokerAuth, Messages.tblColumnMonitorAuth };
    }
    tableViewer = CommonUITool.createCommonTableViewer(composite, new UserManagementTableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 200));
    userManageTable = tableViewer.getTable();
    initialTableModel();
    tableViewer.setInput(serverUserInfoTableList);
    for (int i = 0; i < userManageTable.getColumnCount(); i++) {
        userManageTable.getColumn(i).pack();
    }
    userManageTable.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("rawtypes")
        public void widgetSelected(SelectionEvent event) {
            if (userManageTable.getSelectionCount() > 0) {
                StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
                boolean isHasAdmin = false;
                if (selection != null && !selection.isEmpty()) {
                    Iterator it = selection.iterator();
                    while (it.hasNext()) {
                        Map map = (Map) it.next();
                        if (map.get("0").equals("admin")) {
                            isHasAdmin = true;
                            break;
                        }
                    }
                }
                deleteButton.setEnabled(!isHasAdmin);
            } else {
                deleteButton.setEnabled(false);
            }
            if (userManageTable.getSelectionCount() == 1) {
                editButton.setEnabled(true);
            } else {
                editButton.setEnabled(false);
            }
        }
    });
    // create button
    Composite buttonComp = new Composite(composite, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.spacing = 5;
    buttonComp.setLayout(rowLayout);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalAlignment = GridData.END;
    buttonComp.setLayoutData(gridData);
    Button addButton = new Button(buttonComp, SWT.PUSH);
    addButton.setText(Messages.btnAdd);
    addButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            UserManagementWizard userManagementWizard = new UserManagementWizard(server, null, serverUserInfoList);
            CMWizardDialog dialog = new CMWizardDialog(getShell(), userManagementWizard);
            int returnCode = dialog.open();
            if (returnCode == IDialogConstants.OK_ID) {
                ServerUserInfo userInfo = userManagementWizard.getServerUserInfo();
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("0", userInfo.getUserName());
                if (serverType == ServerType.BOTH) {
                    map.put("1", userInfo.getDbCreateAuthType().getText());
                    map.put("2", userInfo.getCasAuth().getText());
                    map.put("3", userInfo.getStatusMonitorAuth().getText());
                    map.put("4", userInfo);
                }
                if (serverType == ServerType.DATABASE) {
                    map.put("1", userInfo.getDbCreateAuthType().getText());
                    map.put("2", userInfo.getStatusMonitorAuth().getText());
                    map.put("3", userInfo);
                } else if (serverType == ServerType.BROKER) {
                    map.put("1", userInfo.getCasAuth().getText());
                    map.put("2", userInfo.getStatusMonitorAuth().getText());
                    map.put("3", userInfo);
                }
                serverUserInfoTableList.add(map);
                serverUserInfoList.add(userInfo);
                tableViewer.refresh();
                for (int i = 0; i < userManageTable.getColumnCount(); i++) {
                    userManageTable.getColumn(i).pack();
                }
            }
        }
    });
    editButton = new Button(buttonComp, SWT.PUSH);
    editButton.setText(Messages.btnEdit);
    editButton.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings({ "rawtypes", "unchecked" })
        public void widgetSelected(SelectionEvent event) {
            StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
            ServerUserInfo serverUserInfo = null;
            if (selection != null && !selection.isEmpty()) {
                Map map = (Map) selection.getFirstElement();
                if (serverType == ServerType.BOTH) {
                    serverUserInfo = (ServerUserInfo) map.get("4");
                } else {
                    serverUserInfo = (ServerUserInfo) map.get("3");
                }
                UserManagementWizard userManagementWizard = new UserManagementWizard(server, serverUserInfo, serverUserInfoList);
                CMWizardDialog dialog = new CMWizardDialog(getShell(), userManagementWizard);
                int returnCode = dialog.open();
                if (returnCode == IDialogConstants.OK_ID) {
                    ServerUserInfo userInfo = userManagementWizard.getServerUserInfo();
                    map.put("0", userInfo.getUserName());
                    if (serverType == ServerType.BOTH) {
                        map.put("1", userInfo.getDbCreateAuthType().getText());
                        map.put("2", userInfo.getCasAuth().getText());
                        map.put("3", userInfo.getStatusMonitorAuth().getText());
                        map.put("4", userInfo);
                    }
                    if (serverType == ServerType.DATABASE) {
                        map.put("1", userInfo.getDbCreateAuthType().getText());
                        map.put("2", userInfo.getStatusMonitorAuth().getText());
                        map.put("3", userInfo);
                    } else if (serverType == ServerType.BROKER) {
                        map.put("1", userInfo.getCasAuth().getText());
                        map.put("2", userInfo.getStatusMonitorAuth().getText());
                        map.put("3", userInfo);
                    }
                    tableViewer.refresh();
                    for (int i = 0; i < userManageTable.getColumnCount(); i++) {
                        userManageTable.getColumn(i).pack();
                    }
                }
            }
        }
    });
    editButton.setEnabled(userManageTable.getSelectionCount() == 1);
    deleteButton = new Button(buttonComp, SWT.PUSH);
    deleteButton.setText(Messages.btnDelete);
    deleteButton.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("rawtypes")
        public void widgetSelected(SelectionEvent event) {
            boolean isDelete = CommonUITool.openConfirmBox(getShell(), Messages.msgDeleteUserConfirm);
            if (!isDelete) {
                return;
            }
            StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
            if (selection != null && !selection.isEmpty()) {
                Map[] userInfoMapArr = new Map[selection.size()];
                Iterator it = selection.iterator();
                int i = 0;
                while (it.hasNext()) {
                    Map map = (Map) it.next();
                    userInfoMapArr[i] = map;
                    i++;
                }
                deleteUser(userInfoMapArr);
            }
            tableViewer.refresh();
        }
    });
    deleteButton.setEnabled(userManageTable.getSelectionCount() == 1);
    setTitle(Messages.titleUserManagementDialog);
    setMessage(Messages.msgUserManagementDialog);
    return parentComp;
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) UserManagementWizard(com.cubrid.cubridmanager.ui.common.control.UserManagementWizard) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) HashMap(java.util.HashMap) Map(java.util.Map) CMWizardDialog(com.cubrid.common.ui.spi.dialog.CMWizardDialog)

Example 58 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class CreateDatabaseAction method isSupported.

public boolean isSupported(Object obj) {
    if (obj instanceof ICubridNode) {
        ICubridNode node = (ICubridNode) obj;
        if (node.getServer() == null) {
            return false;
        }
        ServerUserInfo userInfo = node.getServer().getServerInfo().getLoginedUserInfo();
        if (userInfo != null && userInfo.getDbCreateAuthType() == DbCreateAuthType.AUTH_ADMIN) {
            return true;
        }
    }
    return false;
}
Also used : ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 59 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class ChangeMasterDbAction method isSupported.

/**
	 * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
	 *      .lang.Object)
	 * @param obj Object
	 * @return boolean(whether to support)
	 */
public boolean isSupported(Object obj) {
    if (obj instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) obj;
        if (!database.isLogined()) {
            return false;
        }
        ServerUserInfo serverUserInfo = database.getServer().getServerInfo().getLoginedUserInfo();
        if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
            return false;
        }
        return database.isDistributorDb();
    }
    return false;
}
Also used : ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 60 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class ChangeReplicationSchemaAction method isSupported.

/**
	 * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
	 *      .lang.Object)
	 * @param obj Object
	 * @return boolean(whether to support)
	 */
public boolean isSupported(Object obj) {
    if (obj instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) obj;
        if (!database.isLogined()) {
            return false;
        }
        ServerUserInfo serverUserInfo = database.getServer().getServerInfo().getLoginedUserInfo();
        if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
            return false;
        }
        return database.isDistributorDb();
    }
    return false;
}
Also used : ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)101 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)33 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)23 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)21 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)19 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 ArrayList (java.util.ArrayList)16 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)12 ServerType (com.cubrid.cubridmanager.core.common.model.ServerType)10 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)9 GetCMUserListTask (com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)8 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)8 CubridBrokerFolder (com.cubrid.cubridmanager.ui.spi.model.CubridBrokerFolder)8 Map (java.util.Map)8 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)7 ITask (com.cubrid.common.core.task.ITask)6 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)6 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)6 GetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask)6