blob: bd3dcf5d5b2d497695f331b1ea9cd0bd2f37aa75 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="fr">
<head>
<!-- Generated by javadoc (1.8.0_201) on Sat May 02 22:23:41 CEST 2020 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Subject.Builder (Apache Shiro :: Core 1.5.3 API)</title>
<meta name="date" content="2020-05-02">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../script.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.5.3 API)";
}
}
catch(err) {
}
//-->
var methods = {"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";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.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">
<li><a href="../../../../org/apache/shiro/subject/Subject.html" title="interface in org.apache.shiro.subject"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../org/apache/shiro/subject/SubjectContext.html" title="interface in org.apache.shiro.subject"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/shiro/subject/Subject.Builder.html" target="_top">Frames</a></li>
<li><a href="Subject.Builder.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All&nbsp;Classes</a></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>
</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 name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.shiro.subject</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/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">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="../../../../org/apache/shiro/subject/Subject.html" title="interface in org.apache.shiro.subject">Subject</a></dd>
</dl>
<hr>
<br>
<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/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></pre>
<div class="block">Builder design pattern implementation for creating <a href="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/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.<code>Builder</code>().<a href="../../../../org/apache/shiro/subject/Subject.Builder.html#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="../../../../org/apache/shiro/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.<code>Builder(securityManager)</code></code>
constructor if desired.
<p/>
All other methods may be called before the <a href="../../../../org/apache/shiro/subject/Subject.Builder.html#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="../../../../org/apache/shiro/SecurityUtils.html" title="class in org.apache.shiro"><code>SecurityUtils</code></a>.<a href="../../../../org/apache/shiro/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 ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#Builder--">Builder</a></span>()</code>
<div class="block">Constructs a new <a href="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/SecurityUtils.html#getSecurityManager--"><code>SecurityUtils.getSecurityManager()</code></a>
to build the <code>Subject</code> instance.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#Builder-org.apache.shiro.mgt.SecurityManager-">Builder</a></span>(<a href="../../../../org/apache/shiro/mgt/SecurityManager.html" title="interface in org.apache.shiro.mgt">SecurityManager</a>&nbsp;securityManager)</code>
<div class="block">Constructs a new <a href="../../../../org/apache/shiro/subject/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>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<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="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code><a href="../../../../org/apache/shiro/subject/Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#authenticated-boolean-">authenticated</a></span>(boolean&nbsp;authenticated)</code>
<div class="block">Ensures the <code>Subject</code> being built will be considered
<a href="../../../../org/apache/shiro/subject/Subject.html#isAuthenticated--"><code>authenticated</code></a>.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code><a href="../../../../org/apache/shiro/subject/Subject.html" title="interface in org.apache.shiro.subject">Subject</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#buildSubject--">buildSubject</a></span>()</code>
<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="../../../../org/apache/shiro/subject/Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#contextAttribute-java.lang.String-java.lang.Object-">contextAttribute</a></span>(<a href="https://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;attributeKey,
<a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a>&nbsp;attributeValue)</code>
<div class="block">Allows custom attributes to be added to the underlying context <code>Map</code> used to construct the
<a href="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/subject/SubjectContext.html" title="interface in org.apache.shiro.subject">SubjectContext</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#getSubjectContext--">getSubjectContext</a></span>()</code>
<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="../../../../org/apache/shiro/subject/Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#host-java.lang.String-">host</a></span>(<a href="https://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;host)</code>
<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="../../../../org/apache/shiro/subject/SubjectContext.html" title="interface in org.apache.shiro.subject">SubjectContext</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#newSubjectContextInstance--">newSubjectContextInstance</a></span>()</code>
<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="../../../../org/apache/shiro/subject/Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#principals-org.apache.shiro.subject.PrincipalCollection-">principals</a></span>(<a href="../../../../org/apache/shiro/subject/PrincipalCollection.html" title="interface in org.apache.shiro.subject">PrincipalCollection</a>&nbsp;principals)</code>
<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="../../../../org/apache/shiro/subject/Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#session-org.apache.shiro.session.Session-">session</a></span>(<a href="../../../../org/apache/shiro/session/Session.html" title="interface in org.apache.shiro.session">Session</a>&nbsp;session)</code>
<div class="block">Ensures the <code>Subject</code> being built will use the specified <a href="../../../../org/apache/shiro/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="../../../../org/apache/shiro/subject/Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#sessionCreationEnabled-boolean-">sessionCreationEnabled</a></span>(boolean&nbsp;enabled)</code>
<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="../../../../org/apache/shiro/subject/Subject.Builder.html" title="class in org.apache.shiro.subject">Subject.Builder</a></code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../org/apache/shiro/subject/Subject.Builder.html#sessionId-java.io.Serializable-">sessionId</a></span>(<a href="https://docs.oracle.com/javase/6/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io">Serializable</a>&nbsp;sessionId)</code>
<div class="block">Enables building a <a href="../../../../org/apache/shiro/subject/Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instance that owns the <a href="../../../../org/apache/shiro/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 name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3>
<code><a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#clone--" title="class or interface in java.lang">clone</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#equals-java.lang.Object-" title="class or interface in java.lang">equals</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#finalize--" title="class or interface in java.lang">finalize</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#getClass--" title="class or interface in java.lang">getClass</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#hashCode--" title="class or interface in java.lang">hashCode</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notify--" title="class or interface in java.lang">notify</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#notifyAll--" title="class or interface in java.lang">notifyAll</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#toString--" title="class or interface in java.lang">toString</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait--" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait-long-" title="class or interface in java.lang">wait</a>, <a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true#wait-long-int-" title="class or interface in java.lang">wait</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="Builder--">
<!-- -->
</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="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/SecurityUtils.html#getSecurityManager--"><code>SecurityUtils.getSecurityManager()</code></a>
to build the <code>Subject</code> instance.</div>
</li>
</ul>
<a name="Builder-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>(<a href="../../../../org/apache/shiro/mgt/SecurityManager.html" title="interface in org.apache.shiro.mgt">SecurityManager</a>&nbsp;securityManager)</pre>
<div class="block">Constructs a new <a href="../../../../org/apache/shiro/subject/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>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="newSubjectContextInstance--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>newSubjectContextInstance</h4>
<pre>protected&nbsp;<a href="../../../../org/apache/shiro/subject/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 name="getSubjectContext--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getSubjectContext</h4>
<pre>protected&nbsp;<a href="../../../../org/apache/shiro/subject/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 name="sessionId-java.io.Serializable-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sessionId</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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>(<a href="https://docs.oracle.com/javase/6/docs/api/java/io/Serializable.html?is-external=true" title="class or interface in java.io">Serializable</a>&nbsp;sessionId)</pre>
<div class="block">Enables building a <a href="../../../../org/apache/shiro/subject/Subject.html" title="interface in org.apache.shiro.subject"><code>Subject</code></a> instance that owns the <a href="../../../../org/apache/shiro/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 name="host-java.lang.String-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>host</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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>(<a href="https://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">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 name="session-org.apache.shiro.session.Session-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>session</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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>(<a href="../../../../org/apache/shiro/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="../../../../org/apache/shiro/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="../../../../org/apache/shiro/subject/Subject.Builder.html#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="../../../../org/apache/shiro/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 name="principals-org.apache.shiro.subject.PrincipalCollection-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>principals</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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>(<a href="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/subject/SimplePrincipalCollection.html#SimplePrincipalCollection-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="../../../../org/apache/shiro/subject/SimplePrincipalCollection.html#SimplePrincipalCollection-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 name="sessionCreationEnabled-boolean-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sessionCreationEnabled</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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>(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 name="authenticated-boolean-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>authenticated</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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>(boolean&nbsp;authenticated)</pre>
<div class="block">Ensures the <code>Subject</code> being built will be considered
<a href="../../../../org/apache/shiro/subject/Subject.html#isAuthenticated--"><code>authenticated</code></a>. Per the
<a href="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/subject/Subject.html#isAuthenticated--"><code>Subject.isAuthenticated()</code></a></dd>
</dl>
</li>
</ul>
<a name="contextAttribute-java.lang.String-java.lang.Object-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>contextAttribute</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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>(<a href="https://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;attributeKey,
<a href="https://docs.oracle.com/javase/6/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">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="../../../../org/apache/shiro/subject/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/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang"><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="../../../../org/apache/shiro/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/6/docs/api/java/lang/IllegalArgumentException.html?is-external=true" title="class or interface in java.lang">IllegalArgumentException</a></code> - if the <code>attributeKey</code> is <code>null</code>.</dd>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../../org/apache/shiro/mgt/SubjectFactory.html#createSubject-org.apache.shiro.subject.SubjectContext-"><code>SubjectFactory.createSubject(SubjectContext)</code></a></dd>
</dl>
</li>
</ul>
<a name="buildSubject--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>buildSubject</h4>
<pre>public&nbsp;<a href="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/subject/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="../../../../org/apache/shiro/SecurityUtils.html" title="class in org.apache.shiro"><code>SecurityUtils</code></a>.<a href="../../../../org/apache/shiro/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>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../overview-summary.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">
<li><a href="../../../../org/apache/shiro/subject/Subject.html" title="interface in org.apache.shiro.subject"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../../../org/apache/shiro/subject/SubjectContext.html" title="interface in org.apache.shiro.subject"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/apache/shiro/subject/Subject.Builder.html" target="_top">Frames</a></li>
<li><a href="Subject.Builder.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.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>
</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 name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<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>
</body>
</html>