blob: 1b3831d8ff760e272e10c1d1cf0999f1776785a7 [file] [log] [blame]
<!DOCTYPE HTML>
<!-- NewPage -->
<html lang="fr">
<head>
<!-- Generated by javadoc (11.0.8) on Wed Oct 28 15:59:12 CET 2020 -->
<title>Subject.Builder (Apache Shiro :: Core 1.7.0 API)</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2020-10-28">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../../../../script.js"></script>
<script type="text/javascript" src="../../../../jquery/jszip/dist/jszip.min.js"></script>
<script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
<!--[if IE]>
<script type="text/javascript" src="../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
<![endif]-->
<script type="text/javascript" src="../../../../jquery/jquery-3.3.1.js"></script>
<script type="text/javascript" src="../../../../jquery/jquery-migrate-3.0.1.js"></script>
<script type="text/javascript" src="../../../../jquery/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Subject.Builder (Apache Shiro :: Core 1.7.0 API)";
}
}
catch(err) {
}
//-->
var data = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
var pathtoroot = "../../../../";
var useModuleDirectories = true;
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<header role="banner">
<nav role="navigation">
<div class="fixedNav">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a id="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/Subject.Builder.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<ul class="navListSearch">
<li><label for="search">SEARCH:</label>
<input type="text" id="search" value="search" disabled="disabled">
<input type="reset" id="reset" value="reset" disabled="disabled">
</li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a id="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
</div>
<div class="navPadding">&nbsp;</div>
<script type="text/javascript"><!--
$('.navPadding').css('padding-top', $('.fixedNav').css("height"));
//-->
</script>
</nav>
</header>
<!-- ======== START OF CLASS DATA ======== -->
<main role="main">
<div class="header">
<div class="subTitle"><span class="packageLabelInType">Package</span>&nbsp;<a href="package-summary.html">org.apache.shiro.subject</a></div>
<h2 title="Class Subject.Builder" class="title">Class Subject.Builder</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>org.apache.shiro.subject.Subject.Builder</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>Enclosing interface:</dt>
<dd><a href="Subject.html" title="interface in org.apache.shiro.subject">Subject</a></dd>
</dl>
<hr>
<pre>public static class <a href="../../../../src-html/org/apache/shiro/subject/Subject.html#line.607">Subject.Builder</a>
extends <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a></pre>
<div class="block">Builder design pattern implementation for creating <a href="Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instances in a simplified way without
requiring knowledge of Shiro's construction techniques.
<p/>
<b>NOTE</b>: This is provided for framework development support only and should typically never be used by
application developers. <code>Subject</code> instances should generally be acquired by using
<code>SecurityUtils.<a href="../SecurityUtils.html#getSubject()"><code>getSubject()</code></a></code>
<h4>Usage</h4>
The simplest usage of this builder is to construct an anonymous, session-less <code>Subject</code> instance:
<pre>
Subject subject = new Subject.<a href="#%3Cinit%3E()"><code>Builder</code></a>().<a href="#buildSubject()"><code>buildSubject()</code></a>;</pre>
The default, no-arg <code>Subject.Builder()</code> constructor shown above will use the application's
currently accessible <code>SecurityManager</code> via
<code>SecurityUtils.<a href="../SecurityUtils.html#getSecurityManager()"><code>getSecurityManager()</code></a></code>. You may also
specify the exact <code>SecurityManager</code> instance to be used by the additional
<code>Subject.<a href="#%3Cinit%3E(org.apache.shiro.mgt.SecurityManager)"><code>Builder(securityManager)</code></a></code>
constructor if desired.
<p/>
All other methods may be called before the <a href="#buildSubject()"><code>buildSubject()</code></a> method to
provide context on how to construct the <code>Subject</code> instance. For example, if you have a session id and
want to acquire the <code>Subject</code> that 'owns' that session (assuming the session exists and is not expired):
<pre>
Subject subject = new Subject.Builder().sessionId(sessionId).buildSubject();</pre>
<p/>
Similarly, if you want a <code>Subject</code> instance reflecting a certain identity:
<pre>
PrincipalCollection principals = new SimplePrincipalCollection("username", <em>yourRealmName</em>);
Subject subject = new Subject.Builder().principals(principals).build();</pre>
<p/>
<b>Note*</b> that the returned <code>Subject</code> instance is <b>not</b> automatically bound to the application (thread)
for further use. That is,
<a href="../SecurityUtils.html" title="class in org.apache.shiro"><code>SecurityUtils</code></a>.<a href="../SecurityUtils.html#getSubject()"><code>getSubject()</code></a>
will not automatically return the same instance as what is returned by the builder. It is up to the framework
developer to bind the built <code>Subject</code> for continued use if desired.</div>
<dl>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>1.0</dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Constructor</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr class="altColor">
<th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="#%3Cinit%3E()">Builder</a></span>()</code></th>
<td class="colLast">
<div class="block">Constructs a new <a href="Subject.Builder.html" title="class in org.apache.shiro.subject"><code>Subject.Builder</code></a> instance, using the <code>SecurityManager</code> instance available
to the calling code as determined by a call to <a href="../SecurityUtils.html#getSecurityManager()"><code>SecurityUtils.getSecurityManager()</code></a>
to build the <code>Subject</code> instance.</div>
</td>
</tr>
<tr class="rowColor">
<th class="colConstructorName" scope="row"><code><span class="memberNameLink"><a href="#%3Cinit%3E(org.apache.shiro.mgt.SecurityManager)">Builder</a></span>&#8203;(<a href="../mgt/SecurityManager.html" title="interface in org.apache.shiro.mgt">SecurityManager</a>&nbsp;securityManager)</code></th>
<td class="colLast">
<div class="block">Constructs a new <a href="Subject.Builder.html" title="class in org.apache.shiro.subject"><code>Subject.Builder</code></a> instance which will use the specified <code>SecurityManager</code> when
building the <code>Subject</code> instance.</div>
</td>
</tr>
</table>
</li>
</ul>
</section>
<!-- ========== METHOD SUMMARY =========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Method</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code><a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#authenticated(boolean)">authenticated</a></span>&#8203;(boolean&nbsp;authenticated)</code></th>
<td class="colLast">
<div class="block">Ensures the <code>Subject</code> being built will be considered
<a href="Subject.html#isAuthenticated()"><code>authenticated</code></a>.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code><a href="Subject.html" title="interface in org.apache.shiro.subject">Subject</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#buildSubject()">buildSubject</a></span>()</code></th>
<td class="colLast">
<div class="block">Creates and returns a new <code>Subject</code> instance reflecting the cumulative state acquired by the
other methods in this class.</div>
</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code><a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#contextAttribute(java.lang.String,java.lang.Object)">contextAttribute</a></span>&#8203;(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a>&nbsp;attributeKey,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a>&nbsp;attributeValue)</code></th>
<td class="colLast">
<div class="block">Allows custom attributes to be added to the underlying context <code>Map</code> used to construct the
<a href="Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instance.</div>
</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>protected <a href="SubjectContext.html" title="interface in org.apache.shiro.subject">SubjectContext</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#getSubjectContext()">getSubjectContext</a></span>()</code></th>
<td class="colLast">
<div class="block">Returns the backing context used to build the <code>Subject</code> instance, available to subclasses
since the <code>context</code> class attribute is marked as <code>private</code>.</div>
</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code><a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#host(java.lang.String)">host</a></span>&#8203;(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a>&nbsp;host)</code></th>
<td class="colLast">
<div class="block">Ensures the <code>Subject</code> being built will reflect the specified host name or IP as its originating
location.</div>
</td>
</tr>
<tr id="i5" class="rowColor">
<td class="colFirst"><code>protected <a href="SubjectContext.html" title="interface in org.apache.shiro.subject">SubjectContext</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#newSubjectContextInstance()">newSubjectContextInstance</a></span>()</code></th>
<td class="colLast">
<div class="block">Creates a new <code>SubjectContext</code> instance to be used to populate with subject contextual data that
will then be sent to the <code>SecurityManager</code> to create a new <code>Subject</code> instance.</div>
</td>
</tr>
<tr id="i6" class="altColor">
<td class="colFirst"><code><a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#principals(org.apache.shiro.subject.PrincipalCollection)">principals</a></span>&#8203;(<a href="PrincipalCollection.html" title="interface in org.apache.shiro.subject">PrincipalCollection</a>&nbsp;principals)</code></th>
<td class="colLast">
<div class="block">Ensures the <code>Subject</code> being built will reflect the specified principals (aka identity).</div>
</td>
</tr>
<tr id="i7" class="rowColor">
<td class="colFirst"><code><a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#session(org.apache.shiro.session.Session)">session</a></span>&#8203;(<a href="../session/Session.html" title="interface in org.apache.shiro.session">Session</a>&nbsp;session)</code></th>
<td class="colLast">
<div class="block">Ensures the <code>Subject</code> being built will use the specified <a href="../session/Session.html" title="interface in org.apache.shiro.session"><code>Session</code></a> instance.</div>
</td>
</tr>
<tr id="i8" class="altColor">
<td class="colFirst"><code><a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#sessionCreationEnabled(boolean)">sessionCreationEnabled</a></span>&#8203;(boolean&nbsp;enabled)</code></th>
<td class="colLast">
<div class="block">Configures whether or not the created Subject instance can create a new <code>Session</code> if one does not
already exist.</div>
</td>
</tr>
<tr id="i9" class="rowColor">
<td class="colFirst"><code><a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="#sessionId(java.io.Serializable)">sessionId</a></span>&#8203;(<a href="https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io" class="externalLink">Serializable</a>&nbsp;sessionId)</code></th>
<td class="colLast">
<div class="block">Enables building a <a href="Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instance that owns the <a href="../session/Session.html" title="interface in org.apache.shiro.session"><code>Session</code></a> with the
specified <code>sessionId</code>.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a id="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a></h3>
<code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang" class="externalLink">clone</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang" class="externalLink">equals</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang" class="externalLink">finalize</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang" class="externalLink">getClass</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang" class="externalLink">hashCode</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang" class="externalLink">notify</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang" class="externalLink">notifyAll</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang" class="externalLink">toString</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang" class="externalLink">wait</a>, <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true#wait(long,int)" title="class or interface in java.lang" class="externalLink">wait</a></code></li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a id="&lt;init&gt;()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>Builder</h4>
<pre>public&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.625">Builder</a>()</pre>
<div class="block">Constructs a new <a href="Subject.Builder.html" title="class in org.apache.shiro.subject"><code>Subject.Builder</code></a> instance, using the <code>SecurityManager</code> instance available
to the calling code as determined by a call to <a href="../SecurityUtils.html#getSecurityManager()"><code>SecurityUtils.getSecurityManager()</code></a>
to build the <code>Subject</code> instance.</div>
</li>
</ul>
<a id="&lt;init&gt;(org.apache.shiro.mgt.SecurityManager)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>Builder</h4>
<pre>public&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.635">Builder</a>&#8203;(<a href="../mgt/SecurityManager.html" title="interface in org.apache.shiro.mgt">SecurityManager</a>&nbsp;securityManager)</pre>
<div class="block">Constructs a new <a href="Subject.Builder.html" title="class in org.apache.shiro.subject"><code>Subject.Builder</code></a> instance which will use the specified <code>SecurityManager</code> when
building the <code>Subject</code> instance.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>securityManager</code> - the <code>SecurityManager</code> to use when building the <code>Subject</code> instance.</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
<!-- ============ METHOD DETAIL ========== -->
<section role="region">
<ul class="blockList">
<li class="blockList"><a id="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a id="newSubjectContextInstance()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>newSubjectContextInstance</h4>
<pre class="methodSignature">protected&nbsp;<a href="SubjectContext.html" title="interface in org.apache.shiro.subject">SubjectContext</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.654">newSubjectContextInstance</a>()</pre>
<div class="block">Creates a new <code>SubjectContext</code> instance to be used to populate with subject contextual data that
will then be sent to the <code>SecurityManager</code> to create a new <code>Subject</code> instance.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a new <code>SubjectContext</code> instance</dd>
</dl>
</li>
</ul>
<a id="getSubjectContext()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getSubjectContext</h4>
<pre class="methodSignature">protected&nbsp;<a href="SubjectContext.html" title="interface in org.apache.shiro.subject">SubjectContext</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.664">getSubjectContext</a>()</pre>
<div class="block">Returns the backing context used to build the <code>Subject</code> instance, available to subclasses
since the <code>context</code> class attribute is marked as <code>private</code>.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the backing context used to build the <code>Subject</code> instance, available to subclasses.</dd>
</dl>
</li>
</ul>
<a id="sessionId(java.io.Serializable)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sessionId</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.695">sessionId</a>&#8203;(<a href="https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io" class="externalLink">Serializable</a>&nbsp;sessionId)</pre>
<div class="block">Enables building a <a href="Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instance that owns the <a href="../session/Session.html" title="interface in org.apache.shiro.session"><code>Session</code></a> with the
specified <code>sessionId</code>.
<p/>
Usually when specifying a <code>sessionId</code>, no other <code>Builder</code> methods would be specified because
everything else (principals, inet address, etc) can usually be reconstructed based on the referenced
session alone. In other words, this is almost always sufficient:
<pre>
new Subject.Builder().sessionId(sessionId).buildSubject();</pre>
<p/>
<b>Although simple in concept, this method provides very powerful functionality previously absent in almost
all Java environments:</b>
<p/>
The ability to reference a <code>Subject</code> and their server-side session
<em>across clients of different mediums</em> such as web applications, Java applets,
standalone C# clients over XML-RPC and/or SOAP, and many others. This is a <em>huge</em>
benefit in heterogeneous enterprise applications.
<p/>
To maintain session integrity across client mediums, the <code>sessionId</code> <b>must</b> be transmitted
to all client mediums securely (e.g. over SSL) to prevent man-in-the-middle attacks. This
is nothing new - all web applications are susceptible to the same problem when transmitting
<code>Cookie</code>s or when using URL rewriting. As long as the
<code>sessionId</code> is transmitted securely, session integrity can be maintained.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>sessionId</code> - the id of the session that backs the desired Subject being acquired.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>this <code>Builder</code> instance for method chaining.</dd>
</dl>
</li>
</ul>
<a id="host(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>host</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.709">host</a>&#8203;(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a>&nbsp;host)</pre>
<div class="block">Ensures the <code>Subject</code> being built will reflect the specified host name or IP as its originating
location.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>host</code> - the host name or IP address to use as the <code>Subject</code>'s originating location.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>this <code>Builder</code> instance for method chaining.</dd>
</dl>
</li>
</ul>
<a id="session(org.apache.shiro.session.Session)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>session</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.724">session</a>&#8203;(<a href="../session/Session.html" title="interface in org.apache.shiro.session">Session</a>&nbsp;session)</pre>
<div class="block">Ensures the <code>Subject</code> being built will use the specified <a href="../session/Session.html" title="interface in org.apache.shiro.session"><code>Session</code></a> instance. Note that it is
more common to use the <a href="#sessionId(java.io.Serializable)"><code>sessionId</code></a> builder method rather than having to construct a
<code>Session</code> instance for this method.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>session</code> - the session to use as the <code>Subject</code>'s <a href="../session/Session.html" title="interface in org.apache.shiro.session"><code>Session</code></a></dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>this <code>Builder</code> instance for method chaining.</dd>
</dl>
</li>
</ul>
<a id="principals(org.apache.shiro.subject.PrincipalCollection)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>principals</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.755">principals</a>&#8203;(<a href="PrincipalCollection.html" title="interface in org.apache.shiro.subject">PrincipalCollection</a>&nbsp;principals)</pre>
<div class="block">Ensures the <code>Subject</code> being built will reflect the specified principals (aka identity).
<p/>
For example, if your application's unique identifier for users is a <code>String</code> username, and you wanted
to create a <code>Subject</code> instance that reflected a user whose username is
'<code>jsmith</code>', and you knew the Realm that could acquire <code>jsmith</code>'s principals based on the username
was named &quot;<code>myRealm</code>&quot;, you might create the '<code>jsmith</code> <code>Subject</code> instance this
way:
<pre>
PrincipalCollection identity = new <a href="SimplePrincipalCollection.html#%3Cinit%3E(java.lang.Object,java.lang.String)"><code>SimplePrincipalCollection</code></a>(&quot;jsmith&quot;, &quot;myRealm&quot;);
Subject jsmith = new Subject.Builder().principals(identity).buildSubject();</pre>
<p/>
Similarly, if your application's unique identifier for users is a <code>long</code> value (such as might be used
as a primary key in a relational database) and you were using a <code>JDBC</code>
<code>Realm</code> named, (unimaginatively) &quot;jdbcRealm&quot;, you might create the Subject
instance this way:
<pre>
long userId = //get user ID from somewhere
PrincipalCollection userIdentity = new <a href="SimplePrincipalCollection.html#%3Cinit%3E(java.lang.Object,java.lang.String)"><code>SimplePrincipalCollection</code></a>(<em>userId</em>, &quot;jdbcRealm&quot;);
Subject user = new Subject.Builder().principals(identity).buildSubject();</pre></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>principals</code> - the principals to use as the <code>Subject</code>'s identity.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>this <code>Builder</code> instance for method chaining.</dd>
</dl>
</li>
</ul>
<a id="sessionCreationEnabled(boolean)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sessionCreationEnabled</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.774">sessionCreationEnabled</a>&#8203;(boolean&nbsp;enabled)</pre>
<div class="block">Configures whether or not the created Subject instance can create a new <code>Session</code> if one does not
already exist. If set to <code>false</code>, any application calls to
<code>subject.getSession()</code> or <code>subject.getSession(true))</code> will result in a SessionException.
<p/>
This setting is <code>true</code> by default, as most applications find value in sessions.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>enabled</code> - whether or not the created Subject instance can create a new <code>Session</code> if one does not
already exist.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>this <code>Builder</code> instance for method chaining.</dd>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>1.2</dd>
</dl>
</li>
</ul>
<a id="authenticated(boolean)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>authenticated</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.790">authenticated</a>&#8203;(boolean&nbsp;authenticated)</pre>
<div class="block">Ensures the <code>Subject</code> being built will be considered
<a href="Subject.html#isAuthenticated()"><code>authenticated</code></a>. Per the
<a href="Subject.html#isAuthenticated()"><code>isAuthenticated()</code></a> JavaDoc, be careful
when specifying <code>true</code> - you should know what you are doing and have a good reason for ignoring Shiro's
default authentication state mechanisms.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>authenticated</code> - whether or not the built <code>Subject</code> will be considered authenticated.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>this <code>Builder</code> instance for method chaining.</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="Subject.html#isAuthenticated()"><code>Subject.isAuthenticated()</code></a></dd>
</dl>
</li>
</ul>
<a id="contextAttribute(java.lang.String,java.lang.Object)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>contextAttribute</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.813">contextAttribute</a>&#8203;(<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang" class="externalLink">String</a>&nbsp;attributeKey,
<a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang" class="externalLink">Object</a>&nbsp;attributeValue)</pre>
<div class="block">Allows custom attributes to be added to the underlying context <code>Map</code> used to construct the
<a href="Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instance.
<p/>
A <code>null</code> key throws an <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang" class="externalLink"><code>IllegalArgumentException</code></a>. A <code>null</code> value effectively removes
any previously stored attribute under the given key from the context map.
<p/>
<b>*NOTE*:</b> This method is only useful when configuring Shiro with a custom <a href="../mgt/SubjectFactory.html" title="interface in org.apache.shiro.mgt"><code>SubjectFactory</code></a>
implementation. This method allows end-users to append additional data to the context map which the
<code>SubjectFactory</code> implementation can use when building custom Subject instances. As such, this method
is only useful when a custom <code>SubjectFactory</code> implementation has been configured.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>attributeKey</code> - the key under which the corresponding value will be stored in the context <code>Map</code>.</dd>
<dd><code>attributeValue</code> - the value to store in the context map under the specified <code>attributeKey</code>.</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>this <code>Builder</code> instance for method chaining.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang" class="externalLink">IllegalArgumentException</a></code> - if the <code>attributeKey</code> is <code>null</code>.</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../mgt/SubjectFactory.html#createSubject(org.apache.shiro.subject.SubjectContext)"><code>SubjectFactory.createSubject(SubjectContext)</code></a></dd>
</dl>
</li>
</ul>
<a id="buildSubject()">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>buildSubject</h4>
<pre class="methodSignature">public&nbsp;<a href="Subject.html" title="interface in org.apache.shiro.subject">Subject</a>&nbsp;<a href="../../../../src-html/org/apache/shiro/subject/Subject.Builder.html#line.844">buildSubject</a>()</pre>
<div class="block">Creates and returns a new <code>Subject</code> instance reflecting the cumulative state acquired by the
other methods in this class.
<p/>
This <code>Builder</code> instance will still retain the underlying state after this method is called - it
will not clear it; repeated calls to this method will return multiple <a href="Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instances, all
reflecting the exact same state. If a new (different) <code>Subject</code> is to be constructed, a new
<code>Builder</code> instance must be created.
<p/>
<b>Note</b> that the returned <code>Subject</code> instance is <b>not</b> automatically bound to the application
(thread) for further use. That is,
<a href="../SecurityUtils.html" title="class in org.apache.shiro"><code>SecurityUtils</code></a>.<a href="../SecurityUtils.html#getSubject()"><code>getSubject()</code></a>
will not automatically return the same instance as what is returned by the builder. It is up to the
framework developer to bind the returned <code>Subject</code> for continued use if desired.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>a new <code>Subject</code> instance reflecting the cumulative state acquired by the
other methods in this class.</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
</div>
</main>
<!-- ========= END OF CLASS DATA ========= -->
<footer role="contentinfo">
<nav role="navigation">
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a id="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/Subject.Builder.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a id="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</nav>
<p class="legalCopy"><small>Copyright &#169; 2004&#x2013;2020 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p>
</footer>
</body>
</html>