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

📄 pwizardpanel7.java

📁 一个完整的XACML工程,学习XACML技术的好例子!
💻 JAVA
字号:
/*
* Copyright (c) 2006, University of Kent
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without 
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this 
* list of conditions and the following disclaimer.
* 
* Redistributions in binary form must reproduce the above copyright notice, 
* this list of conditions and the following disclaimer in the documentation 
* and/or other materials provided with the distribution. 
*
* 1. Neither the name of the University of Kent nor the names of its 
* contributors may be used to endorse or promote products derived from this 
* software without specific prior written permission. 
*
* 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS  
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
* PURPOSE ARE DISCLAIMED. 
*
* 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
* POSSIBILITY OF SUCH DAMAGE.
*
* 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
* IN THE CIRCUMSTANCES.  IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
* SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
* SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
* GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
* TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
* IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
* SERIOUS FAULTS, IN THIS SOFTWARE.
*
* 5. This license is governed, except to the extent that local laws
* necessarily apply, by the laws of England and Wales.
*/

/*
 * PWizardPanel7.java - 04/08/2006
 */

package issrg.policywizard.slides;

import issrg.policywizard.PWizard;
import issrg.policywizard.PermisPolicyWizard_WestPanel;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ResourceBundle;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * This slide will display a list of resource Types that the user will select
 * what type of targets the wish to protect.
 *
 * @author Christian Azzopardi
 */
public class PWizardPanel7 extends JPanel implements ItemListener
{
    private JLabel titleLabel;
    private JLabel gridDescLabel;
    private JLabel servicesDescLabel;
    private JLabel webDescLabel;
    private JLabel campusDescLabel;
    
    public JCheckBox gridRbutton;
    public JCheckBox wsdlRbutton;
    public JCheckBox webRbutton;
    public JCheckBox campusRbutton;
    
    ResourceBundle rbl = ResourceBundle.getBundle("issrg/policywizard/PWApplication_i18n");
    String slideTitle = rbl.getString("Slide7_Title"); //contains What Type of Resources do you want to protect? <p> (Tick as many as apply.)
    String gridOption = rbl.getString("Slide7_Option_Grid"); //contains Grid Resources
    String webOption = rbl.getString("Slide7_Option_Web"); //contains Web Resources
    String campusOption = rbl.getString("Slide7_Option_Campus"); //contains Organisational Resources 
    String wsdlOption = rbl.getString("Slide7_Option_WSDL"); //contains Web Services
    
    String gridDesc = rbl.getString("Slide7_Option_Grid_Description"); //contains (With WSDD Files to describe them)
    String gridWSDL = rbl.getString("Slide7_Option_WSDL_Description"); //contains (Described by WSDL files)
    String gridWeb = rbl.getString("Slide7_Option_Web_Description"); //contains (Accessed via Web Browsers)
    String gridCampus = rbl.getString("Slide7_Option_Campus_Description"); //contains (Named by LDAP distinguished names)
    
    char firstGrid = rbl.getString("Slide7_Option_Grid").charAt(0);
    char firstWeb = rbl.getString("Slide7_Option_Web").charAt(0);
    char firstCampus = rbl.getString("Slide7_Option_Campus").charAt(0);
    char firstWSDL = rbl.getString("Slide7_Option_WSDL").charAt(0);
    
    /** 
     * Creates a new instance of PWizardPanel7 
     */
    public PWizardPanel7() 
    {
        titleLabel = new JLabel("<HTML><B>" + slideTitle + "</B></HTML>");
        gridDescLabel = new JLabel(gridDesc);
        servicesDescLabel = new JLabel(gridWSDL);
        webDescLabel = new JLabel(gridWeb);
        campusDescLabel = new JLabel(gridCampus);        
        
        gridRbutton = new JCheckBox(gridOption);
        gridRbutton.setBackground(PWizard.bgcolor);
        gridRbutton.setMnemonic(firstGrid);
        
        wsdlRbutton = new JCheckBox(wsdlOption);
        wsdlRbutton.setBackground(PWizard.bgcolor);
        wsdlRbutton.setMnemonic(firstWSDL);
        
        webRbutton = new JCheckBox(webOption);
        webRbutton.setBackground(PWizard.bgcolor);
        webRbutton.setMnemonic(firstWeb);
        webRbutton.addItemListener(this);
        
        campusRbutton = new JCheckBox(campusOption);
        campusRbutton.setBackground(PWizard.bgcolor);
        campusRbutton.setMnemonic(firstCampus);
     
        this.setLayout(new BorderLayout());
        this.add(new PermisPolicyWizard_WestPanel(), BorderLayout.WEST);
        this.add(getContentPanel(), BorderLayout.CENTER);
    }
    
    /**
     * Creates a panel with the main content this slide contains.
     *
     * @return  a JPanel with the GUI components that will be displayed when 
     *          this slide is shown
     */
    public JPanel getContentPanel()
    {
        JPanel slide7 = new JPanel(new GridBagLayout());
        slide7.setBackground(PWizard.bgcolor);
        
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx=0; constraints.gridy=0;
        constraints.gridwidth=2; constraints.gridheight=1;
        constraints.weightx=1; constraints.weighty=1;
        constraints.anchor = GridBagConstraints.LAST_LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(0,40,0,0);
        slide7.add(titleLabel, constraints);
        
        constraints.gridx=0; constraints.gridy=1;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(20,100,0,0);
        slide7.add(gridRbutton, constraints);
        
        constraints.gridx=0; constraints.gridy=2;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(0,120,0,0);
        slide7.add(gridDescLabel, constraints);
        
        constraints.gridx=0; constraints.gridy=3;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(20,100,0,0);
        slide7.add(wsdlRbutton, constraints);
        
        constraints.gridx=0; constraints.gridy=4;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(0,120,0,0);
        slide7.add(servicesDescLabel, constraints);
        
        constraints.gridx=0; constraints.gridy=5;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(20,100,0,0);
        slide7.add(webRbutton, constraints);
        
        constraints.gridx=0; constraints.gridy=6;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(0,120,0,0);
        slide7.add(webDescLabel, constraints);
        
        constraints.gridx=0; constraints.gridy=7;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(20,100,0,0);
        slide7.add(campusRbutton, constraints);
 
        constraints.gridx=0; constraints.gridy=8;
        constraints.gridwidth=1; constraints.gridheight=1;
        constraints.weightx=0; constraints.weighty=0;
        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.fill = GridBagConstraints.NONE;
        constraints.insets = new Insets(0,120,30,0);
        slide7.add(campusDescLabel, constraints);
        
        return slide7;
    }
    
    /**
     * When the Web Resources are selected, the appropriate Web Actions are 
     * added to the policy.
     */
    public void itemStateChanged(ItemEvent e) {
        if (e.getSource() == webRbutton ) {
            if (webRbutton.isSelected()) {
                this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                Element child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "OPTIONS");
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                
                child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "GET");
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                
                child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "HEAD");
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                
                child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "POST");
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                
                child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "PUT"); 
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                
                child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "DELETE");
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                
                child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "TRACE");
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                
                child = PWizard.finishWizard.policyDocument.DOM.createElement("Action");
                child.setAttribute("Name", "CONNECT");
                child.setAttribute("Target", "WebResources");
                PWizard.finishWizard.policyDocument.addItem(child, (Element)getParentNode());
                this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            } else {
                this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                NodeList nlist = ((Element)getParentNode()).getElementsByTagName("Action");
                for (int i=nlist.getLength()-1; i>=0; i--) {
                    if ((((Element)nlist.item(i)).getAttribute("Name").equals("OPTIONS")) ||
                        (((Element)nlist.item(i)).getAttribute("Name").equals("GET")) ||
                        (((Element)nlist.item(i)).getAttribute("Name").equals("HEAD")) ||
                        (((Element)nlist.item(i)).getAttribute("Name").equals("POST")) ||
                        (((Element)nlist.item(i)).getAttribute("Name").equals("PUT")) ||
                        (((Element)nlist.item(i)).getAttribute("Name").equals("DELETE")) ||
                        (((Element)nlist.item(i)).getAttribute("Name").equals("TRACE")) ||
                        (((Element)nlist.item(i)).getAttribute("Name").equals("CONNECT")))
                        PWizard.finishWizard.policyDocument.deleteItem((Element)nlist.item(i), (Element)getParentNode());
                }
                this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            }            
        }
    }
    
    /**
     * @return The ActionPolicy Node
     */
    public Node getParentNode()
    {
        return PWizard.finishWizard.policyDocument.DOM.getElementsByTagName("ActionPolicy").item(0);
    }    
}

⌨️ 快捷键说明

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