| <?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>JnlpController.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</a> > <a href="index.source.html" class="el_package">org.apache.shiro.samples.spring.web</a> > <span class="el_source">JnlpController.java</span></div><h1>JnlpController.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.web; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| import javax.servlet.http.HttpServletRequest; |
| import javax.servlet.http.HttpServletResponse; |
| |
| import org.springframework.web.servlet.ModelAndView; |
| import org.springframework.web.servlet.mvc.AbstractController; |
| |
| import org.apache.shiro.SecurityUtils; |
| import org.apache.shiro.session.Session; |
| import org.apache.shiro.subject.Subject; |
| |
| /** |
| * Controller used to dynamically build a JNLP file used to launch the Shiro |
| * Spring WebStart sample application. |
| * |
| * @since 0.1 |
| */ |
| <span class="nc" id="L39">public class JnlpController extends AbstractController {</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 String jnlpView; |
| |
| /*-------------------------------------------- |
| | 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 setJnlpView(String jnlpView) { |
| <span class="nc" id="L59"> this.jnlpView = jnlpView;</span> |
| <span class="nc" id="L60"> }</span> |
| |
| /*-------------------------------------------- |
| | M E T H O D S | |
| ============================================*/ |
| |
| protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { |
| |
| <span class="nc" id="L68"> Subject subject = SecurityUtils.getSubject();</span> |
| <span class="nc" id="L69"> Session session = null;</span> |
| |
| <span class="nc bnc" id="L71" title="All 2 branches missed."> if (subject != null) {</span> |
| <span class="nc" id="L72"> session = subject.getSession();</span> |
| } |
| <span class="nc bnc" id="L74" title="All 2 branches missed."> if (session == null) {</span> |
| <span class="nc" id="L75"> String msg = "Expected a non-null Shiro session.";</span> |
| <span class="nc" id="L76"> throw new IllegalArgumentException(msg);</span> |
| } |
| |
| <span class="nc" id="L79"> StringBuilder sb = new StringBuilder();</span> |
| <span class="nc" id="L80"> sb.append("http://");</span> |
| <span class="nc" id="L81"> sb.append(request.getServerName());</span> |
| <span class="nc bnc" id="L82" title="All 2 branches missed."> if (request.getServerPort() != 80) {</span> |
| <span class="nc" id="L83"> sb.append(":");</span> |
| <span class="nc" id="L84"> sb.append(request.getServerPort());</span> |
| } |
| <span class="nc" id="L86"> sb.append(request.getContextPath());</span> |
| |
| // prevent JNLP caching by setting response headers |
| <span class="nc" id="L89"> response.setHeader("cache-control", "no-cache");</span> |
| <span class="nc" id="L90"> response.setHeader("pragma", "no-cache");</span> |
| |
| <span class="nc" id="L92"> Map<String, Object> model = new HashMap<String, Object>();</span> |
| <span class="nc" id="L93"> model.put("codebaseUrl", sb.toString());</span> |
| <span class="nc" id="L94"> model.put("sessionId", session.getId());</span> |
| <span class="nc" id="L95"> return new ModelAndView(jnlpView, model);</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> |