blob: b1dd2ccc8a7b82667fa579b1faf3b93b856831f4 [file] [log] [blame]
<?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>LoginController.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> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.samples.spring.web</a> &gt; <span class="el_source">LoginController.java</span></div><h1>LoginController.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
* &quot;License&quot;); 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
* &quot;AS IS&quot; 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.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Spring MVC controller responsible for authenticating the user.
*
* @since 0.1
*/
<span class="nc" id="L38">public class LoginController extends SimpleFormController {</span>
<span class="nc" id="L40"> private static transient final Logger log = LoggerFactory.getLogger(LoginController.class);</span>
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object cmd, BindException errors) throws Exception {
<span class="nc" id="L44"> LoginCommand command = (LoginCommand) cmd;</span>
<span class="nc" id="L46"> UsernamePasswordToken token = new UsernamePasswordToken(command.getUsername(), command.getPassword());</span>
try {
<span class="nc" id="L49"> SecurityUtils.getSubject().login(token);</span>
<span class="nc" id="L50"> } catch (AuthenticationException e) {</span>
<span class="nc" id="L51"> log.debug(&quot;Error authenticating.&quot;, e);</span>
<span class="nc" id="L52"> errors.reject(&quot;error.invalidLogin&quot;, &quot;The username or password was not correct.&quot;);</span>
<span class="nc" id="L53"> }</span>
<span class="nc bnc" id="L55" title="All 2 branches missed."> if (errors.hasErrors()) {</span>
<span class="nc" id="L56"> return showForm(request, response, errors);</span>
} else {
<span class="nc" id="L58"> return new ModelAndView(getSuccessView());</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>