blob: e879738ce840d20d4d867423f7c1ddbd287c20d6 [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>AuthenticatingSecurityManager.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 :: Test Coverage</a> &gt; <a href="../index.html" class="el_bundle">shiro-core</a> &gt; <a href="index.source.html" class="el_package">org.apache.shiro.mgt</a> &gt; <span class="el_source">AuthenticatingSecurityManager.java</span></div><h1>AuthenticatingSecurityManager.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.mgt;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.Authenticator;
import org.apache.shiro.authc.pam.ModularRealmAuthenticator;
import org.apache.shiro.util.LifecycleUtils;
/**
* Shiro support of a {@link SecurityManager} class hierarchy that delegates all
* authentication operations to a wrapped {@link Authenticator Authenticator} instance. That is, this class
* implements all the &lt;tt&gt;Authenticator&lt;/tt&gt; methods in the {@link SecurityManager SecurityManager}
* interface, but in reality, those methods are merely passthrough calls to the underlying 'real'
* &lt;tt&gt;Authenticator&lt;/tt&gt; instance.
*
* &lt;p&gt;All other &lt;tt&gt;SecurityManager&lt;/tt&gt; (authorization, session, etc) methods are left to be implemented by subclasses.
*
* &lt;p&gt;In keeping with the other classes in this hierarchy and Shiro's desire to minimize configuration whenever
* possible, suitable default instances for all dependencies are created upon instantiation.
*
* @since 0.9
*/
public abstract class AuthenticatingSecurityManager extends RealmSecurityManager {
/**
* The internal &lt;code&gt;Authenticator&lt;/code&gt; delegate instance that this SecurityManager instance will use
* to perform all authentication operations.
*/
private Authenticator authenticator;
/**
* Default no-arg constructor that initializes its internal
* &lt;code&gt;authenticator&lt;/code&gt; instance to a
* {@link org.apache.shiro.authc.pam.ModularRealmAuthenticator ModularRealmAuthenticator}.
*/
public AuthenticatingSecurityManager() {
<span class="fc" id="L57"> super();</span>
<span class="fc" id="L58"> this.authenticator = new ModularRealmAuthenticator();</span>
<span class="fc" id="L59"> }</span>
/**
* Returns the delegate &lt;code&gt;Authenticator&lt;/code&gt; instance that this SecurityManager uses to perform all
* authentication operations. Unless overridden by the
* {@link #setAuthenticator(org.apache.shiro.authc.Authenticator) setAuthenticator}, the default instance is a
* {@link org.apache.shiro.authc.pam.ModularRealmAuthenticator ModularRealmAuthenticator}.
*
* @return the delegate &lt;code&gt;Authenticator&lt;/code&gt; instance that this SecurityManager uses to perform all
* authentication operations.
*/
public Authenticator getAuthenticator() {
<span class="fc" id="L71"> return authenticator;</span>
}
/**
* Sets the delegate &lt;code&gt;Authenticator&lt;/code&gt; instance that this SecurityManager uses to perform all
* authentication operations. Unless overridden by this method, the default instance is a
* {@link org.apache.shiro.authc.pam.ModularRealmAuthenticator ModularRealmAuthenticator}.
*
* @param authenticator the delegate &lt;code&gt;Authenticator&lt;/code&gt; instance that this SecurityManager will use to
* perform all authentication operations.
* @throws IllegalArgumentException if the argument is &lt;code&gt;null&lt;/code&gt;.
*/
public void setAuthenticator(Authenticator authenticator) throws IllegalArgumentException {
<span class="pc bpc" id="L84" title="1 of 2 branches missed."> if (authenticator == null) {</span>
<span class="nc" id="L85"> String msg = &quot;Authenticator argument cannot be null.&quot;;</span>
<span class="nc" id="L86"> throw new IllegalArgumentException(msg);</span>
}
<span class="fc" id="L88"> this.authenticator = authenticator;</span>
<span class="fc" id="L89"> }</span>
/**
* Passes on the {@link #getRealms() realms} to the internal delegate &lt;code&gt;Authenticator&lt;/code&gt; instance so
* that it may use them during authentication attempts.
*/
protected void afterRealmsSet() {
<span class="fc" id="L96"> super.afterRealmsSet();</span>
<span class="pc bpc" id="L97" title="1 of 2 branches missed."> if (this.authenticator instanceof ModularRealmAuthenticator) {</span>
<span class="fc" id="L98"> ((ModularRealmAuthenticator) this.authenticator).setRealms(getRealms());</span>
}
<span class="fc" id="L100"> }</span>
/**
* Delegates to the wrapped {@link org.apache.shiro.authc.Authenticator Authenticator} for authentication.
*/
public AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {
<span class="fc" id="L106"> return this.authenticator.authenticate(token);</span>
}
public void destroy() {
<span class="fc" id="L110"> LifecycleUtils.destroy(getAuthenticator());</span>
<span class="fc" id="L111"> this.authenticator = null;</span>
<span class="fc" id="L112"> super.destroy();</span>
<span class="fc" id="L113"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.3.201901230119</span></div></body></html>