| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>WebStartView.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Shiro :: Samples :: Spring Client</a> > <a href="index.source.html" class="el_package">org.apache.shiro.samples.spring.ui</a> > <span class="el_source">WebStartView.java</span></div><h1>WebStartView.java</h1><pre class="source lang-java linenums">/* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.shiro.samples.spring.ui; |
| |
| import java.awt.*; |
| import java.awt.event.ActionEvent; |
| import java.awt.event.ActionListener; |
| import java.awt.event.WindowAdapter; |
| import java.awt.event.WindowEvent; |
| import javax.swing.*; |
| |
| import org.springframework.beans.factory.InitializingBean; |
| import org.springframework.core.io.ClassPathResource; |
| |
| import org.apache.shiro.authz.AuthorizationException; |
| import org.apache.shiro.samples.spring.SampleManager; |
| |
| |
| /** |
| * Simple web start application that helps to demo single sign-on and |
| * remoting authorization using Shiro. The injected <tt>SampleManager</tt> |
| * is hosted by the Spring sample web application and remotely invoked |
| * when the buttons in this view are clicked. |
| * |
| * @since 0.1 |
| */ |
| <span class="nc" id="L43">public class WebStartView implements ActionListener, InitializingBean {</span> |
| |
| /*-------------------------------------------- |
| | C O N S T A N T S | |
| ============================================*/ |
| |
| /*-------------------------------------------- |
| | I N S T A N C E V A R I A B L E S | |
| ============================================*/ |
| private SampleManager sampleManager; |
| private JTextField valueField; |
| private JButton saveButton; |
| private JButton refreshButton; |
| private JButton secureMethod1Button; |
| private JButton secureMethod2Button; |
| private JButton secureMethod3Button; |
| private JFrame frame; |
| |
| /*-------------------------------------------- |
| | C O N S T R U C T O R S | |
| ============================================*/ |
| |
| /*-------------------------------------------- |
| | A C C E S S O R S / M O D I F I E R S | |
| ============================================*/ |
| |
| public void setSampleManager(SampleManager sampleManager) { |
| <span class="nc" id="L70"> this.sampleManager = sampleManager;</span> |
| <span class="nc" id="L71"> }</span> |
| |
| /*-------------------------------------------- |
| | M E T H O D S | |
| ============================================*/ |
| public void afterPropertiesSet() throws Exception { |
| <span class="nc" id="L77"> ClassPathResource resource = new ClassPathResource("logo.png");</span> |
| <span class="nc" id="L78"> ImageIcon icon = new ImageIcon(resource.getURL());</span> |
| <span class="nc" id="L79"> JLabel logo = new JLabel(icon);</span> |
| |
| <span class="nc" id="L81"> valueField = new JTextField(20);</span> |
| <span class="nc" id="L82"> updateValueLabel();</span> |
| |
| <span class="nc" id="L84"> saveButton = new JButton("Save Value");</span> |
| <span class="nc" id="L85"> saveButton.addActionListener(this);</span> |
| |
| <span class="nc" id="L87"> refreshButton = new JButton("Refresh Value");</span> |
| <span class="nc" id="L88"> refreshButton.addActionListener(this);</span> |
| |
| <span class="nc" id="L90"> JPanel valuePanel = new JPanel(new FlowLayout(FlowLayout.CENTER));</span> |
| <span class="nc" id="L91"> valuePanel.add(valueField);</span> |
| <span class="nc" id="L92"> valuePanel.add(saveButton);</span> |
| <span class="nc" id="L93"> valuePanel.add(refreshButton);</span> |
| |
| <span class="nc" id="L95"> secureMethod1Button = new JButton("Method #1");</span> |
| <span class="nc" id="L96"> secureMethod1Button.addActionListener(this);</span> |
| |
| <span class="nc" id="L98"> secureMethod2Button = new JButton("Method #2");</span> |
| <span class="nc" id="L99"> secureMethod2Button.addActionListener(this);</span> |
| |
| <span class="nc" id="L101"> secureMethod3Button = new JButton("Method #3");</span> |
| <span class="nc" id="L102"> secureMethod3Button.addActionListener(this);</span> |
| |
| <span class="nc" id="L104"> JPanel methodPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));</span> |
| <span class="nc" id="L105"> methodPanel.add(secureMethod1Button);</span> |
| <span class="nc" id="L106"> methodPanel.add(secureMethod2Button);</span> |
| <span class="nc" id="L107"> methodPanel.add(secureMethod3Button);</span> |
| |
| <span class="nc" id="L109"> frame = new JFrame("Apache Shiro Sample Application");</span> |
| <span class="nc" id="L110"> frame.setSize(500, 200);</span> |
| |
| <span class="nc" id="L112"> Container panel = frame.getContentPane();</span> |
| <span class="nc" id="L113"> panel.setLayout(new BorderLayout());</span> |
| <span class="nc" id="L114"> panel.add(logo, BorderLayout.NORTH);</span> |
| <span class="nc" id="L115"> panel.add(valuePanel, BorderLayout.CENTER);</span> |
| <span class="nc" id="L116"> panel.add(methodPanel, BorderLayout.SOUTH);</span> |
| |
| <span class="nc" id="L118"> frame.setVisible(true);</span> |
| <span class="nc" id="L119"> frame.addWindowListener(new WindowAdapter() {</span> |
| public void windowClosing(WindowEvent e) { |
| <span class="nc" id="L121"> System.exit(0);</span> |
| <span class="nc" id="L122"> }</span> |
| }); |
| <span class="nc" id="L124"> }</span> |
| |
| private void updateValueLabel() { |
| <span class="nc" id="L127"> valueField.setText(sampleManager.getValue());</span> |
| <span class="nc" id="L128"> }</span> |
| |
| public void actionPerformed(ActionEvent e) { |
| try { |
| |
| <span class="nc bnc" id="L133" title="All 2 branches missed."> if (e.getSource() == saveButton) {</span> |
| <span class="nc" id="L134"> sampleManager.setValue(valueField.getText());</span> |
| |
| <span class="nc bnc" id="L136" title="All 2 branches missed."> } else if (e.getSource() == refreshButton) {</span> |
| <span class="nc" id="L137"> updateValueLabel();</span> |
| |
| <span class="nc bnc" id="L139" title="All 2 branches missed."> } else if (e.getSource() == secureMethod1Button) {</span> |
| <span class="nc" id="L140"> sampleManager.secureMethod1();</span> |
| <span class="nc" id="L141"> JOptionPane.showMessageDialog(frame, "Method #1 successfully called.", "Success", JOptionPane.INFORMATION_MESSAGE);</span> |
| |
| <span class="nc bnc" id="L143" title="All 2 branches missed."> } else if (e.getSource() == secureMethod2Button) {</span> |
| <span class="nc" id="L144"> sampleManager.secureMethod2();</span> |
| <span class="nc" id="L145"> JOptionPane.showMessageDialog(frame, "Method #2 successfully called.", "Success", JOptionPane.INFORMATION_MESSAGE);</span> |
| <span class="nc bnc" id="L146" title="All 2 branches missed."> } else if (e.getSource() == secureMethod3Button) {</span> |
| <span class="nc" id="L147"> sampleManager.secureMethod3();</span> |
| <span class="nc" id="L148"> JOptionPane.showMessageDialog(frame, "Method #3 successfully called.", "Success", JOptionPane.INFORMATION_MESSAGE);</span> |
| |
| } else { |
| <span class="nc" id="L151"> throw new RuntimeException("Unexpected action event from source: " + e.getSource());</span> |
| } |
| |
| <span class="nc" id="L154"> } catch (AuthorizationException ae) {</span> |
| <span class="nc" id="L155"> JOptionPane.showMessageDialog(frame, "Unauthorized to perform action: " + ae.getMessage(), "Unauthorized", JOptionPane.WARNING_MESSAGE);</span> |
| <span class="nc" id="L156"> }</span> |
| <span class="nc" id="L157"> }</span> |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html> |