| <?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 :: Core</a> > <a href="index.source.html" class="el_package">org.apache.shiro.mgt</a> > <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 |
| * "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.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 <tt>Authenticator</tt> methods in the {@link SecurityManager SecurityManager} |
| * interface, but in reality, those methods are merely passthrough calls to the underlying 'real' |
| * <tt>Authenticator</tt> instance. |
| * |
| * <p>All other <tt>SecurityManager</tt> (authorization, session, etc) methods are left to be implemented by subclasses. |
| * |
| * <p>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 <code>Authenticator</code> delegate instance that this SecurityManager instance will use |
| * to perform all authentication operations. |
| */ |
| private Authenticator authenticator; |
| |
| /** |
| * Default no-arg constructor that initializes its internal |
| * <code>authenticator</code> 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 <code>Authenticator</code> 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 <code>Authenticator</code> instance that this SecurityManager uses to perform all |
| * authentication operations. |
| */ |
| public Authenticator getAuthenticator() { |
| <span class="fc" id="L71"> return authenticator;</span> |
| } |
| |
| /** |
| * Sets the delegate <code>Authenticator</code> 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 <code>Authenticator</code> instance that this SecurityManager will use to |
| * perform all authentication operations. |
| * @throws IllegalArgumentException if the argument is <code>null</code>. |
| */ |
| public void setAuthenticator(Authenticator authenticator) throws IllegalArgumentException { |
| <span class="nc bnc" id="L84" title="All 2 branches missed."> if (authenticator == null) {</span> |
| <span class="nc" id="L85"> String msg = "Authenticator argument cannot be null.";</span> |
| <span class="nc" id="L86"> throw new IllegalArgumentException(msg);</span> |
| } |
| <span class="nc" id="L88"> this.authenticator = authenticator;</span> |
| <span class="nc" id="L89"> }</span> |
| |
| /** |
| * Passes on the {@link #getRealms() realms} to the internal delegate <code>Authenticator</code> 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.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html> |