| <?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>IndexController.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">IndexController.java</span></div><h1>IndexController.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 org.apache.shiro.SecurityUtils; |
| import org.apache.shiro.samples.spring.SampleManager; |
| import org.apache.shiro.session.Session; |
| import org.apache.shiro.subject.Subject; |
| import org.springframework.validation.BindException; |
| import org.springframework.validation.Errors; |
| import org.springframework.web.servlet.ModelAndView; |
| import org.springframework.web.servlet.mvc.SimpleFormController; |
| |
| import javax.servlet.http.HttpServletRequest; |
| import javax.servlet.http.HttpServletResponse; |
| import java.util.HashMap; |
| import java.util.LinkedHashMap; |
| import java.util.Map; |
| |
| /** |
| * Spring MVC controller responsible for rendering the Shiro Spring sample |
| * application index page. |
| * |
| * @since 0.1 |
| */ |
| <span class="nc" id="L42">public class IndexController extends SimpleFormController {</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; |
| |
| /*-------------------------------------------- |
| | 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="L63"> this.sampleManager = sampleManager;</span> |
| <span class="nc" id="L64"> }</span> |
| |
| /*-------------------------------------------- |
| | M E T H O D S | |
| ============================================*/ |
| |
| protected Object formBackingObject(HttpServletRequest request) throws Exception { |
| <span class="nc" id="L71"> SessionValueCommand command = (SessionValueCommand) createCommand();</span> |
| |
| <span class="nc" id="L73"> command.setValue(sampleManager.getValue());</span> |
| <span class="nc" id="L74"> return command;</span> |
| } |
| |
| protected Map<String, Object> referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { |
| <span class="nc" id="L78"> Subject subject = SecurityUtils.getSubject();</span> |
| <span class="nc" id="L79"> boolean hasRole1 = subject.hasRole("role1");</span> |
| <span class="nc" id="L80"> boolean hasRole2 = subject.hasRole("role2");</span> |
| |
| <span class="nc" id="L82"> Map<String, Object> refData = new HashMap<String, Object>();</span> |
| <span class="nc" id="L83"> refData.put("hasRole1", hasRole1);</span> |
| <span class="nc" id="L84"> refData.put("hasRole2", hasRole2);</span> |
| |
| <span class="nc" id="L86"> Session session = subject.getSession();</span> |
| <span class="nc" id="L87"> Map<Object, Object> sessionAttributes = new LinkedHashMap<Object, Object>();</span> |
| <span class="nc bnc" id="L88" title="All 2 branches missed."> for (Object key : session.getAttributeKeys()) {</span> |
| <span class="nc" id="L89"> sessionAttributes.put(key, session.getAttribute(key));</span> |
| <span class="nc" id="L90"> }</span> |
| <span class="nc" id="L91"> refData.put("sessionAttributes", sessionAttributes);</span> |
| |
| <span class="nc" id="L93"> refData.put("subjectSession", subject.getSession());</span> |
| <span class="nc" id="L94"> return refData;</span> |
| } |
| |
| protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { |
| <span class="nc" id="L98"> SessionValueCommand command = (SessionValueCommand) obj;</span> |
| |
| <span class="nc" id="L100"> sampleManager.setValue(command.getValue());</span> |
| |
| <span class="nc" id="L102"> return showForm(request, response, errors);</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> |