blob: 9782669ecee67c11599e56169b0e279bf5b7a7a9 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body>
<main role="main">
<div class="sourceContainer">
<pre><span class="sourceLineNo">001</span><a id="line.1">/*</a>
<span class="sourceLineNo">002</span><a id="line.2"> * Licensed to the Apache Software Foundation (ASF) under one</a>
<span class="sourceLineNo">003</span><a id="line.3"> * or more contributor license agreements. See the NOTICE file</a>
<span class="sourceLineNo">004</span><a id="line.4"> * distributed with this work for additional information</a>
<span class="sourceLineNo">005</span><a id="line.5"> * regarding copyright ownership. The ASF licenses this file</a>
<span class="sourceLineNo">006</span><a id="line.6"> * to you under the Apache License, Version 2.0 (the</a>
<span class="sourceLineNo">007</span><a id="line.7"> * "License"); you may not use this file except in compliance</a>
<span class="sourceLineNo">008</span><a id="line.8"> * with the License. You may obtain a copy of the License at</a>
<span class="sourceLineNo">009</span><a id="line.9"> *</a>
<span class="sourceLineNo">010</span><a id="line.10"> * http://www.apache.org/licenses/LICENSE-2.0</a>
<span class="sourceLineNo">011</span><a id="line.11"> *</a>
<span class="sourceLineNo">012</span><a id="line.12"> * Unless required by applicable law or agreed to in writing,</a>
<span class="sourceLineNo">013</span><a id="line.13"> * software distributed under the License is distributed on an</a>
<span class="sourceLineNo">014</span><a id="line.14"> * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY</a>
<span class="sourceLineNo">015</span><a id="line.15"> * KIND, either express or implied. See the License for the</a>
<span class="sourceLineNo">016</span><a id="line.16"> * specific language governing permissions and limitations</a>
<span class="sourceLineNo">017</span><a id="line.17"> * under the License.</a>
<span class="sourceLineNo">018</span><a id="line.18"> */</a>
<span class="sourceLineNo">019</span><a id="line.19">package org.apache.shiro.authc.pam;</a>
<span class="sourceLineNo">020</span><a id="line.20"></a>
<span class="sourceLineNo">021</span><a id="line.21">import org.apache.shiro.authc.AuthenticationException;</a>
<span class="sourceLineNo">022</span><a id="line.22">import org.apache.shiro.authc.AuthenticationInfo;</a>
<span class="sourceLineNo">023</span><a id="line.23">import org.apache.shiro.authc.AuthenticationToken;</a>
<span class="sourceLineNo">024</span><a id="line.24">import org.apache.shiro.realm.Realm;</a>
<span class="sourceLineNo">025</span><a id="line.25"></a>
<span class="sourceLineNo">026</span><a id="line.26">import java.util.Collection;</a>
<span class="sourceLineNo">027</span><a id="line.27"></a>
<span class="sourceLineNo">028</span><a id="line.28"></a>
<span class="sourceLineNo">029</span><a id="line.29">/**</a>
<span class="sourceLineNo">030</span><a id="line.30"> * A {@code AuthenticationStrategy} implementation assists the {@link ModularRealmAuthenticator} during the</a>
<span class="sourceLineNo">031</span><a id="line.31"> * log-in process in a pluggable realm (PAM) environment.</a>
<span class="sourceLineNo">032</span><a id="line.32"> *</a>
<span class="sourceLineNo">033</span><a id="line.33"> * &lt;p&gt;The {@code ModularRealmAuthenticator} will consult implementations of this interface on what to do during each</a>
<span class="sourceLineNo">034</span><a id="line.34"> * interaction with the configured Realms. This allows a pluggable strategy of whether or not an authentication</a>
<span class="sourceLineNo">035</span><a id="line.35"> * attempt must be successful for all realms, only 1 or more realms, no realms, etc.</a>
<span class="sourceLineNo">036</span><a id="line.36"> *</a>
<span class="sourceLineNo">037</span><a id="line.37"> * @see AllSuccessfulStrategy</a>
<span class="sourceLineNo">038</span><a id="line.38"> * @see AtLeastOneSuccessfulStrategy</a>
<span class="sourceLineNo">039</span><a id="line.39"> * @see FirstSuccessfulStrategy</a>
<span class="sourceLineNo">040</span><a id="line.40"> * @since 0.2</a>
<span class="sourceLineNo">041</span><a id="line.41"> */</a>
<span class="sourceLineNo">042</span><a id="line.42">public interface AuthenticationStrategy {</a>
<span class="sourceLineNo">043</span><a id="line.43"></a>
<span class="sourceLineNo">044</span><a id="line.44"> /**</a>
<span class="sourceLineNo">045</span><a id="line.45"> * Method invoked by the ModularAuthenticator signifying that the authentication process is about to begin for the</a>
<span class="sourceLineNo">046</span><a id="line.46"> * specified {@code token} - called before any {@code Realm} is actually invoked.</a>
<span class="sourceLineNo">047</span><a id="line.47"> *</a>
<span class="sourceLineNo">048</span><a id="line.48"> * &lt;p&gt;The {@code AuthenticationInfo} object returned from this method is essentially an empty place holder for</a>
<span class="sourceLineNo">049</span><a id="line.49"> * aggregating account data across multiple realms. It should be populated by the strategy implementation over the</a>
<span class="sourceLineNo">050</span><a id="line.50"> * course of authentication attempts across the multiple realms. It will be passed into the</a>
<span class="sourceLineNo">051</span><a id="line.51"> * {@link #beforeAttempt} calls, allowing inspection of the aggregated account data up to that point in the</a>
<span class="sourceLineNo">052</span><a id="line.52"> * multi-realm authentication, allowing any logic to be executed accordingly.</a>
<span class="sourceLineNo">053</span><a id="line.53"> *</a>
<span class="sourceLineNo">054</span><a id="line.54"> * @param realms the Realms that will be consulted during the authentication process for the specified token.</a>
<span class="sourceLineNo">055</span><a id="line.55"> * @param token the Principal/Credential representation to be used during authentication for a corresponding subject.</a>
<span class="sourceLineNo">056</span><a id="line.56"> * @return an empty AuthenticationInfo object that will populated with data from multiple realms.</a>
<span class="sourceLineNo">057</span><a id="line.57"> * @throws AuthenticationException if the strategy implementation does not wish the Authentication attempt to execute.</a>
<span class="sourceLineNo">058</span><a id="line.58"> */</a>
<span class="sourceLineNo">059</span><a id="line.59"> AuthenticationInfo beforeAllAttempts(Collection&lt;? extends Realm&gt; realms, AuthenticationToken token) throws AuthenticationException;</a>
<span class="sourceLineNo">060</span><a id="line.60"></a>
<span class="sourceLineNo">061</span><a id="line.61"> /**</a>
<span class="sourceLineNo">062</span><a id="line.62"> * Method invoked by the ModularAuthenticator just prior to the realm being consulted for account data,</a>
<span class="sourceLineNo">063</span><a id="line.63"> * allowing pre-authentication-attempt logic for that realm only.</a>
<span class="sourceLineNo">064</span><a id="line.64"> *</a>
<span class="sourceLineNo">065</span><a id="line.65"> * &lt;p&gt;This method returns an {@code AuthenticationInfo} object that will be used for further interaction with realms. Most</a>
<span class="sourceLineNo">066</span><a id="line.66"> * implementations will merely return the {@code aggregate} method argument if they don't have a need to</a>
<span class="sourceLineNo">067</span><a id="line.67"> * manipulate it.</a>
<span class="sourceLineNo">068</span><a id="line.68"> *</a>
<span class="sourceLineNo">069</span><a id="line.69"> * @param realm the realm that will be consulted for {@code AuthenticationInfo} for the specified {@code token}.</a>
<span class="sourceLineNo">070</span><a id="line.70"> * @param token the {@code AuthenticationToken} submitted for the subject attempting system log-in.</a>
<span class="sourceLineNo">071</span><a id="line.71"> * @param aggregate the aggregated AuthenticationInfo object being used across the multi-realm authentication attempt</a>
<span class="sourceLineNo">072</span><a id="line.72"> * @return the AuthenticationInfo object that will be presented to further realms in the authentication process - returning</a>
<span class="sourceLineNo">073</span><a id="line.73"> * the {@code aggregate} method argument is the normal case if no special action needs to be taken.</a>
<span class="sourceLineNo">074</span><a id="line.74"> * @throws org.apache.shiro.authc.AuthenticationException</a>
<span class="sourceLineNo">075</span><a id="line.75"> * an exception thrown by the Strategy implementation if it wishes the login</a>
<span class="sourceLineNo">076</span><a id="line.76"> * process for the associated subject (user) to stop immediately.</a>
<span class="sourceLineNo">077</span><a id="line.77"> */</a>
<span class="sourceLineNo">078</span><a id="line.78"> AuthenticationInfo beforeAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo aggregate) throws AuthenticationException;</a>
<span class="sourceLineNo">079</span><a id="line.79"></a>
<span class="sourceLineNo">080</span><a id="line.80"> /**</a>
<span class="sourceLineNo">081</span><a id="line.81"> * Method invoked by the ModularAuthenticator just after the given realm has been consulted for authentication,</a>
<span class="sourceLineNo">082</span><a id="line.82"> * allowing post-authentication-attempt logic for that realm only.</a>
<span class="sourceLineNo">083</span><a id="line.83"> *</a>
<span class="sourceLineNo">084</span><a id="line.84"> * &lt;p&gt;This method returns an {@code AuthenticationInfo} object that will be used for further interaction with realms. Most</a>
<span class="sourceLineNo">085</span><a id="line.85"> * implementations will merge the {@code singleRealmInfo} into the {@code aggregateInfo} and</a>
<span class="sourceLineNo">086</span><a id="line.86"> * just return the {@code aggregateInfo} for continued use throughout the authentication process.&lt;/p&gt;</a>
<span class="sourceLineNo">087</span><a id="line.87"> *</a>
<span class="sourceLineNo">088</span><a id="line.88"> * @param realm the realm that was just consulted for {@code AuthenticationInfo} for the given {@code token}.</a>
<span class="sourceLineNo">089</span><a id="line.89"> * @param token the {@code AuthenticationToken} submitted for the subject attempting system log-in.</a>
<span class="sourceLineNo">090</span><a id="line.90"> * @param singleRealmInfo the info returned from a single realm.</a>
<span class="sourceLineNo">091</span><a id="line.91"> * @param aggregateInfo the aggregate info representing all realms in a multi-realm environment.</a>
<span class="sourceLineNo">092</span><a id="line.92"> * @param t the Throwable thrown by the Realm during the attempt, or {@code null} if the method returned normally.</a>
<span class="sourceLineNo">093</span><a id="line.93"> * @return the AuthenticationInfo object that will be presented to further realms in the authentication process - returning</a>
<span class="sourceLineNo">094</span><a id="line.94"> * the {@code aggregateAccount} method argument is the normal case if no special action needs to be taken.</a>
<span class="sourceLineNo">095</span><a id="line.95"> * @throws AuthenticationException an exception thrown by the Strategy implementation if it wishes the login process</a>
<span class="sourceLineNo">096</span><a id="line.96"> * for the associated subject (user) to stop immediately.</a>
<span class="sourceLineNo">097</span><a id="line.97"> */</a>
<span class="sourceLineNo">098</span><a id="line.98"> AuthenticationInfo afterAttempt(Realm realm, AuthenticationToken token, AuthenticationInfo singleRealmInfo, AuthenticationInfo aggregateInfo, Throwable t)</a>
<span class="sourceLineNo">099</span><a id="line.99"> throws AuthenticationException;</a>
<span class="sourceLineNo">100</span><a id="line.100"></a>
<span class="sourceLineNo">101</span><a id="line.101"> /**</a>
<span class="sourceLineNo">102</span><a id="line.102"> * Method invoked by the ModularAuthenticator signifying that all of its configured Realms have been consulted</a>
<span class="sourceLineNo">103</span><a id="line.103"> * for account data, allowing post-processing after all realms have completed.</a>
<span class="sourceLineNo">104</span><a id="line.104"> *</a>
<span class="sourceLineNo">105</span><a id="line.105"> * &lt;p&gt;Returns the final AuthenticationInfo object that will be returned from the Authenticator to the authenticate() caller.</a>
<span class="sourceLineNo">106</span><a id="line.106"> * This is most likely the aggregate AuthenticationInfo object that has been populated by many realms, but the actual return value is</a>
<span class="sourceLineNo">107</span><a id="line.107"> * always up to the implementation.</a>
<span class="sourceLineNo">108</span><a id="line.108"> *</a>
<span class="sourceLineNo">109</span><a id="line.109"> * @param token the {@code AuthenticationToken} submitted for the subject attempting system log-in.</a>
<span class="sourceLineNo">110</span><a id="line.110"> * @param aggregate the aggregate {@code AuthenticationInfo} instance populated by all realms during the log-in attempt.</a>
<span class="sourceLineNo">111</span><a id="line.111"> * @return the final {@code AuthenticationInfo} object to return to the Authenticator.authenticate() caller.</a>
<span class="sourceLineNo">112</span><a id="line.112"> * @throws AuthenticationException if the Strategy implementation wishes to fail the authentication attempt.</a>
<span class="sourceLineNo">113</span><a id="line.113"> */</a>
<span class="sourceLineNo">114</span><a id="line.114"> AuthenticationInfo afterAllAttempts(AuthenticationToken token, AuthenticationInfo aggregate) throws AuthenticationException;</a>
<span class="sourceLineNo">115</span><a id="line.115">}</a>
</pre>
</div>
</main>
</body>
</html>