Search in sources :

Example 11 with IUIUser

use of org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser in project pentaho-kettle by pentaho.

the class EESecurityController method createBindings.

@Override
protected void createBindings() {
    super.createBindings();
    // User Role Binding
    // $NON-NLS-1$
    systemRoleRadioButton = (XulRadio) document.getElementById("system-role-radio-button");
    // $NON-NLS-1$
    roleRadioButton = (XulRadio) document.getElementById("role-radio-button");
    // $NON-NLS-1$
    userRadioButton = (XulRadio) document.getElementById("user-radio-button");
    // $NON-NLS-1$
    roleAddButton = (XulButton) document.getElementById("role-add");
    // $NON-NLS-1$
    roleEditButton = (XulButton) document.getElementById("role-edit");
    // $NON-NLS-1$
    roleRemoveButton = (XulButton) document.getElementById("role-remove");
    // $NON-NLS-1$
    addUserToRoleButton = (XulButton) document.getElementById("add-user-to-role");
    // $NON-NLS-1$
    removeUserFromRoleButton = (XulButton) document.getElementById("remove-user-from-role");
    // $NON-NLS-1$
    addRoleToUserButton = (XulButton) document.getElementById("add-role-to-user");
    // $NON-NLS-1$
    removeRoleFromUserButton = (XulButton) document.getElementById("remove-role-from-user");
    // $NON-NLS-1$
    roleDialog = (XulDialog) document.getElementById("add-role-dialog");
    // $NON-NLS-1$
    userRoleDeck = (XulDeck) document.getElementById("user-role-deck");
    // $NON-NLS-1$
    roleListBox = (XulListbox) document.getElementById("roles-list");
    // $NON-NLS-1$
    roleDetailTable = (XulTree) document.getElementById("role-detail-table");
    // Add User Binding
    // $NON-NLS-1$
    userListBox = (XulListbox) document.getElementById("users-list");
    // $NON-NLS-1$
    userDetailTable = (XulTree) document.getElementById("user-detail-table");
    // $NON-NLS-1$
    availableRoles = (XulListbox) document.getElementById("available-roles-list");
    // $NON-NLS-1$
    assignedRoles = (XulListbox) document.getElementById("selected-roles-list");
    // $NON-NLS-1$
    assignRoleToUserButton = (XulButton) document.getElementById("assign-role-to-user");
    // $NON-NLS-1$
    unassignRoleFromUserButton = (XulButton) document.getElementById("unassign-role-from-user");
    // $NON-NLS-1$
    systemRoleListBox = (XulListbox) document.getElementById("system-roles-list");
    // $NON-NLS-1$
    innerRoleVbox = (XulVbox) document.getElementById("inner-role-vbox");
    // $NON-NLS-1$
    roleVboxNonManaged = (XulVbox) document.getElementById("role-vbox-nonmanaged");
    // $NON-NLS-1$
    roleHbox = (XulHbox) document.getElementById("role-hbox");
    // $NON-NLS-1$
    instructionalTextLabel = (XulLabel) document.getElementById("instructional-text-label");
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "assignedRoles", assignedRoles, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "availableRoles", availableRoles, "elements");
    // Binding to convert role array to a role list object and vice versa
    BindingConvertor<List<IUIRole>, Object[]> arrayToListRoleConverter = new BindingConvertor<List<IUIRole>, Object[]>() {

        @Override
        public Object[] sourceToTarget(List<IUIRole> roles) {
            if (roles != null) {
                Object[] retVal = new Object[roles.size()];
                int i = 0;
                for (IUIRole role : roles) {
                    retVal[i++] = role;
                }
                return retVal;
            }
            return null;
        }

        @Override
        public List<IUIRole> targetToSource(Object[] roles) {
            if (roles != null) {
                List<IUIRole> retVal = new ArrayList<IUIRole>();
                for (int i = 0; i < roles.length; i++) {
                    retVal.add((IUIRole) roles[i]);
                }
                return retVal;
            }
            return null;
        }
    };
    // Binding to convert user array to a user list object and vice versa
    BindingConvertor<List<IUIUser>, Object[]> arrayToListUserConverter = new BindingConvertor<List<IUIUser>, Object[]>() {

        @Override
        public Object[] sourceToTarget(List<IUIUser> users) {
            if (users != null) {
                Object[] retVal = new Object[users.size()];
                int i = 0;
                for (IUIUser user : users) {
                    retVal[i++] = user;
                }
                return retVal;
            }
            return null;
        }

        @Override
        public List<IUIUser> targetToSource(Object[] users) {
            if (users != null) {
                List<IUIUser> retVal = new ArrayList<IUIUser>();
                for (int i = 0; i < users.length; i++) {
                    retVal.add((IUIUser) users[i]);
                }
                return retVal;
            }
            return null;
        }
    };
    bf.createBinding(eeSecurityUser, "availableSelectedRoles", availableRoles, "selectedItems", // $NON-NLS-1$ //$NON-NLS-2$
    arrayToListRoleConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "assignedSelectedRoles", assignedRoles, "selectedItems", arrayToListRoleConverter);
    BindingConvertor<Integer, Boolean> accumulatorButtonConverter = new BindingConvertor<Integer, Boolean>() {

        @Override
        public Boolean sourceToTarget(Integer value) {
            if (value != null && value >= 0) {
                return true;
            }
            return false;
        }

        @Override
        public Integer targetToSource(Boolean value) {
            return null;
        }
    };
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(assignedRoles, "selectedIndex", eeSecurityUser, "roleUnassignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    bf.createBinding(availableRoles, "selectedIndex", eeSecurityUser, "roleAssignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "roleUnassignmentPossible", unassignRoleFromUserButton, "!disabled");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "roleAssignmentPossible", assignRoleToUserButton, "!disabled");
    // Add Role Binding
    // $NON-NLS-1$
    rolename = (XulTextbox) document.getElementById("role-name");
    // $NON-NLS-1$
    roleDescription = (XulTextbox) document.getElementById("role-description");
    // $NON-NLS-1$
    availableUsers = (XulListbox) document.getElementById("available-users-list");
    // $NON-NLS-1$
    assignedUsers = (XulListbox) document.getElementById("selected-users-list");
    // $NON-NLS-1$
    assignUserToRoleButton = (XulButton) document.getElementById("assign-user-to-role");
    // $NON-NLS-1$
    unassignUserFromRoleButton = (XulButton) document.getElementById("unassign-user-from-role");
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "name", rolename, "value");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "description", roleDescription, "value");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "assignedUsers", assignedUsers, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "availableUsers", availableUsers, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "availableSelectedUsers", availableUsers, "selectedItems", arrayToListUserConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "assignedSelectedUsers", assignedUsers, "selectedItems", arrayToListUserConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurity, "selectedRoleIndex", roleListBox, "selectedIndex");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurity, "selectedSystemRoleIndex", systemRoleListBox, "selectedIndex");
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(assignedUsers, "selectedIndex", securityRole, "userUnassignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    bf.createBinding(availableUsers, "selectedIndex", securityRole, "userAssignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "userUnassignmentPossible", unassignUserFromRoleButton, "!disabled");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "userAssignmentPossible", assignUserToRoleButton, "!disabled");
    try {
        bf.setBindingType(Binding.Type.ONE_WAY);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(roleListBox, "selectedIndex", this, "enableButtons");
        bf.setBindingType(Binding.Type.ONE_WAY);
        // Action based security permissions
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(roleListBox, "selectedItem", eeSecurity, "selectedRole");
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(eeSecurity, "roleList", roleListBox, "elements").fireSourceChanged();
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(roleListBox, "selectedItem", eeSecurity, "selectedRole");
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(systemRoleListBox, "selectedItem", eeSecurity, "selectedSystemRole");
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(eeSecurity, "systemRoleList", systemRoleListBox, "elements").fireSourceChanged();
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(systemRoleListBox, "selectedItem", eeSecurity, "selectedSystemRole");
        if (managed) {
            userDetailBinding = // $NON-NLS-1$ //$NON-NLS-2$
            bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
            eeSecurity, // $NON-NLS-1$ //$NON-NLS-2$
            "selectedUser", // $NON-NLS-1$ //$NON-NLS-2$
            userDetailTable, // $NON-NLS-1$ //$NON-NLS-2$
            "elements", new BindingConvertor<IUIUser, List<IUIRole>>() {

                @Override
                public List<IUIRole> sourceToTarget(IUIUser ru) {
                    if (ru instanceof IUIEEUser) {
                        return new ArrayList<IUIRole>(((IUIEEUser) ru).getRoles());
                    } else {
                        return null;
                    }
                }

                @Override
                public IUIUser targetToSource(List<IUIRole> arg0) {
                    // TODO Auto-generated method stub
                    return null;
                }
            });
            roleDetailBinding = // $NON-NLS-1$ //$NON-NLS-2$
            bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
            eeSecurity, // $NON-NLS-1$ //$NON-NLS-2$
            "selectedRole", // $NON-NLS-1$ //$NON-NLS-2$
            roleDetailTable, // $NON-NLS-1$ //$NON-NLS-2$
            "elements", new BindingConvertor<IUIRole, List<IUIUser>>() {

                @Override
                public List<IUIUser> sourceToTarget(IUIRole rr) {
                    return new ArrayList<IUIUser>(rr.getUsers());
                }

                @Override
                public IUIRole targetToSource(List<IUIUser> arg0) {
                    // TODO Auto-generated method stub
                    return null;
                }
            });
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
        eeSecurity, // $NON-NLS-1$ //$NON-NLS-2$
        "selectedDeck", // $NON-NLS-1$ //$NON-NLS-2$
        userRoleDeck, // $NON-NLS-1$ //$NON-NLS-2$
        "selectedIndex", new BindingConvertor<ObjectRecipient.Type, Integer>() {

            @Override
            public Integer sourceToTarget(Type arg0) {
                if (arg0 == Type.ROLE) {
                    userRadioButton.setSelected(false);
                    roleRadioButton.setSelected(true);
                    systemRoleRadioButton.setSelected(false);
                    return 1;
                } else if (arg0 == Type.USER) {
                    userRadioButton.setSelected(true);
                    roleRadioButton.setSelected(false);
                    systemRoleRadioButton.setSelected(false);
                    return 0;
                } else if (arg0 == Type.SYSTEM_ROLE) {
                    userRadioButton.setSelected(false);
                    roleRadioButton.setSelected(false);
                    systemRoleRadioButton.setSelected(true);
                    return 2;
                } else {
                    return -1;
                }
            }

            @Override
            public Type targetToSource(Integer arg0) {
                return null;
            }
        });
        BindingConvertor<Mode, Boolean> modeBindingConverter = new BindingConvertor<Mode, Boolean>() {

            @Override
            public Boolean sourceToTarget(Mode arg0) {
                if (arg0.equals(Mode.ADD)) {
                    return false;
                }
                return true;
            }

            @Override
            public Mode targetToSource(Boolean arg0) {
                // TODO Auto-generated method stub
                return null;
            }
        };
        BindingConvertor<Mode, Boolean> anotherModeBindingConverter = new BindingConvertor<Mode, Boolean>() {

            @Override
            public Boolean sourceToTarget(Mode arg0) {
                if (arg0.equals(Mode.EDIT_MEMBER)) {
                    return true;
                } else {
                    return false;
                }
            }

            @Override
            public Mode targetToSource(Boolean arg0) {
                // TODO Auto-generated method stub
                return null;
            }
        };
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityRole, "mode", rolename, "disabled", modeBindingConverter);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityRole, "mode", roleDescription, "disabled", anotherModeBindingConverter);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityUser, "mode", userPassword, "disabled", anotherModeBindingConverter);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityUser, "mode", userDescription, "disabled", anotherModeBindingConverter);
    } catch (Exception e) {
        // convert to runtime exception so it bubbles up through the UI
        throw new RuntimeException(e);
    }
}
Also used : Mode(org.pentaho.di.ui.repository.repositoryexplorer.model.UISecurity.Mode) ArrayList(java.util.ArrayList) IUIEEUser(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIEEUser) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) KettleException(org.pentaho.di.core.exception.KettleException) UIObjectCreationException(org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException) Type(org.pentaho.di.repository.ObjectRecipient.Type) IUIUser(org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with IUIUser

use of org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser in project pentaho-kettle by pentaho.

the class EESecurityController method updateRole.

/**
 * updateRole method is called when user has click ok on a edit role dialog. The method updates the role
 *
 * @throws Exception
 */
private void updateRole() {
    if (service != null) {
        try {
            IUIRole uiRole = eeSecurity.getSelectedRole();
            Set<IUIUser> previousUserList = new HashSet<IUIUser>();
            previousUserList.addAll(uiRole.getUsers());
            uiRole.setDescription(securityRole.getDescription());
            uiRole.setUsers(new HashSet<IUIUser>(securityRole.getAssignedUsers()));
            ((IRoleSupportSecurityManager) service).updateRole(uiRole.getRole());
            eeSecurity.updateRole(uiRole, previousUserList);
            roleDialog.hide();
        } catch (Throwable th) {
            // $NON-NLS-1$
            messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
            // $NON-NLS-1$
            messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
            messageBox.setMessage(// $NON-NLS-1$
            BaseMessages.getString(PKG, "UpdateRole.UnableToUpdateRole", th.getLocalizedMessage()));
            messageBox.open();
        }
    }
}
Also used : IRoleSupportSecurityManager(org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager) IUIUser(org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser) IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) HashSet(java.util.HashSet)

Example 13 with IUIUser

use of org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser in project pentaho-kettle by pentaho.

the class UIEESecurity method addRole.

public void addRole(IUIRole roleToAdd) {
    roleList.add(roleToAdd);
    Collections.sort(roleList);
    // $NON-NLS-1$
    this.firePropertyChange("roleList", null, roleList);
    // We need to make sure this new role is added to all users as well
    for (IUIUser userInfo : roleToAdd.getUsers()) {
        assignRoleToUser(userInfo, roleToAdd);
    }
    setSelectedRole(roleToAdd);
}
Also used : IUIUser(org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)

Example 14 with IUIUser

use of org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser in project pentaho-kettle by pentaho.

the class UIEESecurity method removeUserFromSelectedRole.

private void removeUserFromSelectedRole(String userName) {
    IUIUser user = findUserInSelectedRole(userName);
    selectedRole.removeUser(user);
    unassignRoleFromUser(user, selectedRole);
}
Also used : IUIUser(org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)

Example 15 with IUIUser

use of org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser in project pentaho-kettle by pentaho.

the class UISecurityRole method getRole.

public IRole getRole(IRoleSupportSecurityManager rsm) {
    IRole roleInfo = null;
    try {
        roleInfo = rsm.constructRole();
    } catch (KettleException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    roleInfo.setDescription(description);
    roleInfo.setName(name);
    for (IUIUser user : getAssignedUsers()) {
        roleInfo.addUser(user.getUserInfo());
    }
    return roleInfo;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) IRole(org.pentaho.di.repository.pur.model.IRole) IUIUser(org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)

Aggregations

IUIUser (org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)16 IUIRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 UIRepositoryRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryRole)4 UIRepositoryUser (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryUser)4 ArrayList (java.util.ArrayList)3 IUIEEUser (org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIEEUser)3 UIEERepositoryUser (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEERepositoryUser)3 KettleException (org.pentaho.di.core.exception.KettleException)2 IUser (org.pentaho.di.repository.IUser)2 UserInfo (org.pentaho.di.repository.UserInfo)2 EEUserInfo (org.pentaho.di.repository.pur.model.EEUserInfo)2 IRole (org.pentaho.di.repository.pur.model.IRole)2 UISecurityRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UISecurityRole)2 List (java.util.List)1 Before (org.junit.Before)1 Type (org.pentaho.di.repository.ObjectRecipient.Type)1 EERoleInfo (org.pentaho.di.repository.pur.model.EERoleInfo)1 IRoleSupportSecurityManager (org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager)1