本文整理汇总了Java中org.apache.shiro.subject.SubjectContext.setAuthenticated方法的典型用法代码示例。如果您正苦于以下问题:Java SubjectContext.setAuthenticated方法的具体用法?Java SubjectContext.setAuthenticated怎么用?Java SubjectContext.setAuthenticated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.subject.SubjectContext
的用法示例。
在下文中一共展示了SubjectContext.setAuthenticated方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSubject
import org.apache.shiro.subject.SubjectContext; //导入方法依赖的package包/类
@Override
public Subject createSubject(SubjectContext context) {
boolean authenticated = context.isAuthenticated();
if (authenticated) {
AuthenticationToken token = context.getAuthenticationToken();
if (token != null && token instanceof OAuth2Token) {
OAuth2Token oAuth2Token = (OAuth2Token) token;
if (oAuth2Token.isRememberMe()) {
context.setAuthenticated(false);
}
}
}
return super.createSubject(context);
}
示例2: createSubject
import org.apache.shiro.subject.SubjectContext; //导入方法依赖的package包/类
/**
* Creates a {@code Subject} instance for the user represented by the given method arguments.
*
* @param token the {@code AuthenticationToken} submitted for the successful authentication.
* @param info the {@code AuthenticationInfo} of a newly authenticated user.
* @param existing the existing {@code Subject} instance that initiated the authentication attempt
* @return the {@code Subject} instance that represents the context and session data for the newly
* authenticated subject.
*/
protected Subject createSubject(AuthenticationToken token, AuthenticationInfo info, Subject existing) {
SubjectContext context = createSubjectContext();
context.setAuthenticated(true);
context.setAuthenticationToken(token);
context.setAuthenticationInfo(info);
if (existing != null) {
context.setSubject(existing);
}
return createSubject(context);
}
示例3: copy
import org.apache.shiro.subject.SubjectContext; //导入方法依赖的package包/类
@Override
protected SubjectContext copy(SubjectContext subjectContext) {
// this is the only way to trick the superclass into believing subject is always authenticated
UsernamePasswordToken token = new UsernamePasswordToken("permissive", "nopassword");
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), "Permissive");
subjectContext.setAuthenticated(true);
subjectContext.setAuthenticationToken(token);
subjectContext.setAuthenticationInfo(info);
return subjectContext;
}
示例4: copy
import org.apache.shiro.subject.SubjectContext; //导入方法依赖的package包/类
@Override
protected SubjectContext copy(SubjectContext subjectContext) {
// this is the only way to trick the superclass into believing subject is always authenticated
UsernamePasswordToken token = new UsernamePasswordToken("permissive", "nopassword");
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getPrincipal(),
token.getCredentials(),
"Permissive");
subjectContext.setAuthenticated(true);
subjectContext.setAuthenticationToken(token);
subjectContext.setAuthenticationInfo(info);
return subjectContext;
}
示例5: resolveSession
import org.apache.shiro.subject.SubjectContext; //导入方法依赖的package包/类
/**
* Attempts to resolve any associated session based on the context and returns a
* context that represents this resolved {@code Session} to ensure it may be referenced if necessary by the
* invoked {@link SubjectFactory} that performs actual {@link Subject} construction.
* <p/>
* If there is a {@code Session} already in the context because that is what the caller wants to be used for
* {@code Subject} construction, or if no session is resolved, this method effectively does nothing
* returns the context method argument unaltered.
*
* @param context the subject context data that may resolve a Session instance.
* @return The context to use to pass to a {@link SubjectFactory} for subject creation.
* @since 1.0
*/
private SubjectContext resolveSession(SubjectContext context) {
if (context.resolveSession() != null) {
log.debug("Context already contains a session. Returning.");
return context;
}
try {
//Context couldn't resolve it directly,
// let's see if we can since we have direct access to
// the session manager:
IOTClient session = resolveContextSession(context);
if (session != null) {
context.setAuthenticated(true);
context.setSession(session);
PrincipalCollection principles = session.getPrincipleCollection();
if(null != principles){
context.setPrincipals(principles);
}
}
} catch (InvalidSessionException e) {
log.trace("Resolved SubjectContext context session is invalid. Ignoring and creating an anonymous " +
"(session-less) Subject instance.", e);
}
return context;
}
示例6: login
import org.apache.shiro.subject.SubjectContext; //导入方法依赖的package包/类
/**
* Logs in the specified Subject using the given {@code authenticationToken}, returning an updated Subject
* instance reflecting the authenticated state if successful or throwing {@code AuthenticationException} if it is
* not.
* <p>
* Note that most application developers should probably not call this method directly unless they have a good
* reason for doing so. The preferred way to log in a Subject is to call
* <code>subject.{@link Subject#login login(authenticationToken)}</code> (usually after
* acquiring the Subject by calling {@link SecurityUtils#getSubject() SecurityUtils.getSubject()}).
* <p>
* Framework developers on the other hand might find calling this method directly useful in certain cases.
*
* @param subject the subject against which the authentication attempt will occur
* @param authenticationToken the token representing the Subject's principal(s) and credential(s)
* @return the subject instance reflecting the authenticated state after a successful attempt
* @throws AuthenticationException if the login attempt failed.
* @since 1.0
*/
@Override
public Subject login(Subject subject, AuthenticationToken authenticationToken) throws AuthenticationException {
AuthenticationInfo info = authenticate(authenticationToken);
SubjectContext context = new DefaultSubjectContext();
context.setAuthenticated(true);
context.setAuthenticationToken(authenticationToken);
context.setAuthenticationInfo(info);
context.setSessionCreationEnabled(true);
if (subject != null) {
context.setSubject(subject);
}
return createSubject(context);
}