⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 permisrolehierarchypolicy.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        
        String roleId = roleIDTextField.getText().trim();
        //fixed a bug in the deleted item 
        PermisPolicyEditorMenu.permisXmlDom.deleteRole(roleId, selection);
        
        performRefresh();
        rolePolicyViewScrollPane.setViewportView(roleViewList);
        /*Object item = deleteItem.removeItemComboBox( hierarchyDeleteButton, 
                                                     roleListModel, 
                                                     roleValueList, 
                                                     roleComboBox);
        deleteItem.removeItem( hierarchyDeleteButton, 
                               avRoleListModel, 
                               availableRoleList, 
                               item);
       */
        //store the deleted item in a hashtable 
        deletedHastable.put(selection,  selection);
    }
        
    
    private void createPromoteButtonActionPerformed() 
    {
        deleteItemsFromDom();
         if (!roleListModel.isEmpty()){
            for (int i=0; i < roleListModel.size(); i++){
                //get object at the index
                String stringRole = roleListModel.getElementAt(i).toString();
                //check if role already exists
                if (!loader.isRole(ROLE_SPEC, stringRole)){
                //add the object to DOM
                PermisPolicyEditorMenu.permisXmlDom.addDomAttr( ROLE_SPEC, 
                                                                SUP_ROLE, 
                                                                VALUE, 
                                                                stringRole);
                }
        }
       
       
        
         if(parent.getPermisParent().getMenuItems().
                                                   getReadablePolicy() != null){
                    parent.getPermisParent().getMenuItems().getReadablePolicy().
                                                   comboBoxSetSelectedIndex(4);
            }
        
        //PermisPolicyEditorMenu.permisXmlDom.showMessage();
        roleListModel.clear();
        String button = "roleAssignmentButton";
        parent.controlButton(button, true);
       
        roleListModel.clear();
        
        performRefresh();
        deletedHastable.clear();
        roleHierarchyTabbedPane.setSelectedIndex(2);
        }
        promtePressed = true;
        
    }
        
    
    /**
     * Adds the selected role from the Document Object Model in memory and
     * refreshes the associated list, listmodel and combobox.
     *
     * @param evt   Add Role button operated.
     */
    
    private void addRoleButtonActionPerformed() 
    {
        boolean deleteText;
        PermisDataBox datalistener = new PermisDataBox();
        if (listBoxContains(roleTextField.getText().trim(),roleListModel )){
            PermisPolicyEditorMenu.dialog.showOkDialog(
                 getString(roleTextField.getText())+ " " +
                  ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
                  getString("rol_hie_err_msg_exist"));
            roleTextField.requestFocus();
            return;
        }
              
        deleteText = true;
        datalistener.addToList( hierarchyDeleteButton, 
                                roleTextField, 
                                roleListModel, 
                                roleValueList, 
                                deleteText);
        deleteText = false;
        
        /*datalistener.addToComboBoxList( hierarchyDeleteButton, 
                                        roleTextField, 
                                        avroleListModel, 
                                        avroleValueList, 
                                        roleComboBox, 
                                        deleteText);
         */
    }
       
    
    /** 
     * Adds the OID and Role Type attribute name-value pair to the Document
     * Object model in memory. 
     */
    private void createRoleSpec()
    {
        // dirty hack for the shitty code.
        // don't add RoleSpec node, if there is already one
        if (PermisPolicyEditorMenu.permisXmlDom.getDoc()==null || PermisPolicyEditorMenu.permisXmlDom.getDoc().getDocumentElement().getElementsByTagName(ROLE_SPEC).getLength()!=0) return;

        PermisPolicyEditorMenu.permisXmlDom.createDomElement(
                                                          ROLE_HIERARCHY_POLICY, 
                                                          ROLE_SPEC, 
                                                          null);
        PermisPolicyEditorMenu.permisXmlDom.addDomAttr( 
                                                     ROLE_SPEC, 
                                                     OID, 
                                                     roleIDTextField.getText());
        PermisPolicyEditorMenu.permisXmlDom.addDomAttr( 
                                                   ROLE_SPEC, 
                                                   TYPE, 
                                                   roleTypeTextField.getText());
    }
    
    private void roleComboBoxActionPerformed()
    {
        selectedSupRole = null;
        if(roleComboBox.getItemCount() != 0){
            if (roleComboBox.getSelectedIndex() != -1){
                String roleString = roleComboBox.getSelectedItem().toString();

                // this is how all the panels should have worked, but...alas, the guy had no idea how to program
                Document doc = PermisPolicyEditorMenu.permisXmlDom.getDoc();
                NodeList roleSpecs = doc.getDocumentElement().getElementsByTagName(ROLE_SPEC);
                String currentRoleType = roleTypeComboBox.getSelectedItem().toString(); // get the current role type we are building a hierarchy for
                Element roleSpec = null;
                //System.out.println("Changing the role view; now viewing: "+currentRoleType+" : "+roleString); //************
                for (int i=0; i<roleSpecs.getLength(); i++){
                  if (roleSpecs.item(i).getNodeType()==Node.ELEMENT_NODE){
                    roleSpec = (Element)roleSpecs.item(i);
                    String s = roleSpec.getAttribute("Type");
                    //System.out.println("* got RoleSpec with id: "+s); //************
                    if (s!=null && s.equals(currentRoleType)) break; // roleSpec is the one

                    roleSpec = null; // no, this is the wrong role spec
                  }
                }

                // ok, now role Spec != null, if the role type is in DOM
                // otherwise an error should be signalled, but we will not do this in this version - it always talks in terms of PermisRoles anyway
                if (roleSpec!=null){
                  NodeList supRoles = roleSpec.getElementsByTagName("SupRole");
                  // let's find the one that has roleString as a value

                  //System.out.println("* searching for suproles of "+roleSpec); //************
                  for (int i=0; i<supRoles.getLength(); i++){
                    if (supRoles.item(i).getNodeType()!=Node.ELEMENT_NODE) continue;

                    Element r = (Element)supRoles.item(i);
                    String s = r.getAttribute("Value");
                    //System.out.println("** got supRole with Value "+s); //************
                    if (s!=null && s.equals(roleString)){ // this the One
                      //System.out.println("** "+s+" is the role we are looking for"); //************
                      selectedSupRole = r;
                      break;
                    }
                  }
                }
                // now selectedSupRole is set, so roleSubAdd and roleSubRemove can act on DOM directly

                loader.populateRolesPolicy(subRoleListModel,ROLE_SPEC,roleString);
                roleHierarchySubordinateRolesScrollPane.setViewportView(subRoleList);
            }
        }
        //change state for the cancel button 
        promtePressed = false;
        
    }
    
    private boolean checkDuplication( DefaultListModel compare,
                                      DefaultListModel compareList)
                                         
    {
        if(!compareList.isEmpty()){
            for (int i = 0; i < compareList.size(); i++){
                if (compareList.elementAt(i).equals(compare)){
                    return true;
                }
            }
            
       
        }
        return false;
    }
     private boolean listBoxContains( String compare,
                                      DefaultListModel compareList)
     {
         if(!compareList.isEmpty()){
            for (int i = 0; i < compareList.size(); i++){
                if (compareList.elementAt(i).equals(compare.trim())){
                    return true;
                }
            }
            
       
        }
        return false;
    }
    
    /** 
     * Checks deleted object in the Hastable and deletes from Document
     * Object model in memory. 
     *
     */
    private void deleteItemsFromDom()
    {
        String roleId = roleIDTextField.getText().trim();
        if (!deletedHastable.isEmpty()){
            Enumeration deleted = this.deletedHastable.elements();
            while (deleted.hasMoreElements()){
                String s = deleted.nextElement().toString();
                PermisPolicyEditorMenu.permisXmlDom.deleteRole(roleId, s);
            }
       
       //return  this.deletedHastable.containsValue(idString); 
        }
        
    }
    
    /** 
     * Checks deleted object in the Hastable and deletes from Document
     * Object model in memory. 
     *
     */
    private void deleteSubRolesFromSupRole()
    {
         String parent=null;
         String roleId = roleIDTextField.getText().trim();
         if(roleComboBox.getItemCount() != 0){
            if (roleComboBox.getSelectedIndex() != -1){
         parent = roleComboBox.getSelectedItem().toString().trim();
            }
         }
        if (!deleteSubRolHastable.isEmpty()){
            Enumeration deleted = this.deleteSubRolHastable.elements();
            while (deleted.hasMoreElements()){
                String s = deleted.nextElement().toString();
                if(parent != null){
                PermisPolicyEditorMenu.permisXmlDom.
                                    deleteSubRoleFromSupRole(roleId, parent ,s);
                }
            }
        }
    }
    
     /** 
     * adds square brackets to a string and return the new string
     *
     *
     */
     private String getString(String string)
   {
       return "[" + string + "]";
   }

  public void actionPerformed(ActionEvent event){
    String command = event.getActionCommand().intern();
    if (command==ADD_ACTION){
      addRoleButtonActionPerformed();
    }else if (command==VIEW_OK_ACTION){
      createOkButtonActionPerformed();
    }else if (command==VIEW_PROMOTE_ACTION){
      createPromoteButtonActionPerformed();
    }else if (command==VIEW_CLOSE_ACTION){
      viewCloseButtonActionPerformed();
    }else if (command==CANCEL_ACTION){
      createCancelButtonActionPerformed();
    }else if (command==HIERARCHY_DELETE_ACTION){
      hierarchyDeleteButtonActionPerformed();
    }else if (command==ROLE_VIEW_ACTION){
      roleViewComboBoxActionPerformed();
    }else if (command==ROLE_EDIT_ACTION){
      roleEditButtonButtonActionPerformed();
    }else if (command==ROLE_DELETE_ACTION){
      roleDeleteButtonActionPerformed();
    }else if (command==CLOSE_ACTION){
      closeButtonActionPerformed();
    }else if (command==ROLE_SUB_ADD_ACTION){
      roleSubAddButtonActionPerformed();
    }else if (command==ROLE_SUB_REMOVE_ACTION){
      roleSubRemoveButtonActionPerformed();
    }else if (command==ROLE_ACTION){
      roleComboBoxActionPerformed();
    }else if (command==HIERARCHY_OK_ACTION){
      promteOkButtonActionPerformed();
    }else if (command==HIERARCHY_CANCEL_ACTION){
      promteCancelButtonActionPerformed();
    }else if (command==HIERARCHY_CLOSE_ACTION){
      promoteCloseButtonActionPerformed();
    }
  }

  public void intervalRemoved(ListDataEvent e){}

  public void contentsChanged(ListDataEvent e){
    promtePressed = true;

    roleSubAddButton.setEnabled(avRoleListModel.getSize()!=0); // this will always be so, because the Available Roles List doesn't diminish
    //System.out.println("contents of the sub role list changed. new role list size: "+subRoleListModel.getSize());//************
    roleSubRemoveButton.setEnabled(subRoleListModel.getSize()!=0);
    
  }

  public void intervalAdded(ListDataEvent e){}

  public void focusGained(FocusEvent e){
    int idx = roleHierarchyTabbedPane.indexOfComponent(e.getComponent());

    if (idx==1){
      roleEditButtonButtonActionPerformed();
    }

    if (idx==2){
      createPromoteButtonActionPerformed();
    }
  }

  public void focusLost(FocusEvent e){
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -