SubjectBuilder.principals

Ensures the {@code Subject} being built will reflect the specified principals (aka identity). <p/> For example, if your application's unique identifier for users is a {@code string} username, and you wanted to create a {@code Subject} instance that reflected a user whose username is '{@code jsmith}', and you knew the Realm that could acquire {@code jsmith}'s principals based on the username was named &quot;{@code myRealm}&quot;, you might create the '{@code jsmith} {@code Subject} instance this way: <pre> PrincipalCollection identity = new {@link hunt.shiro.subject.SimplePrincipalCollection#SimplePrincipalCollection(Object, string) SimplePrincipalCollection}(&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} value (such as might be used as a primary key in a relational database) and you were using a {@code JDBC} {@code Realm} named, (unimaginatively) &quot;jdbcRealm&quot;, you might create the Subject instance this way: <pre> long userId = //get user ID from somewhere PrincipalCollection userIdentity = new {@link hunt.shiro.subject.SimplePrincipalCollection#SimplePrincipalCollection(Object, string) SimplePrincipalCollection}(<em>userId</em>, &quot;jdbcRealm&quot;); Subject user = new Subject.Builder().principals(identity).buildSubject();</pre>

@param principals the principals to use as the {@code Subject}'s identity. @return this {@code Builder} instance for method chaining.

class SubjectBuilder
principals

Meta