本文整理汇总了Java中org.apache.shiro.subject.SubjectContext类的典型用法代码示例。如果您正苦于以下问题:Java SubjectContext类的具体用法?Java SubjectContext怎么用?Java SubjectContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SubjectContext类属于org.apache.shiro.subject包,在下文中一共展示了SubjectContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: doCreateSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
protected Subject doCreateSubject(SubjectContext context) {
Subject subject = this.getSubjectFactory().createSubject(context);
String username = (String) subject.getPrincipal();
if(username != null){
//后端用户数据源
SysUsers sysUsers = userService.findByUsername(username);
if(sysUsers !=null && sysUsers.getId() != null){
subject.getSession().setAttribute(AppConstants.SESSION_USER_ID_KEY, sysUsers.getId());
} else {
CdMember memberQuery = new CdMember();
memberQuery.setPhoneNumber(username);
//前端用户数据源
CdMember member = memberService.findMember(memberQuery);
if(member != null && member.getId() != null) {
subject.getSession().setAttribute(AppConstants.SESSION_USER_ID_KEY, member.getId());
}
}
}
return subject;
}
示例3: createSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
public Subject createSubject(SubjectContext context) {
if (!(context instanceof WebSubjectContext)) {
return super.createSubject(context);
}
WebSubjectContext wsc = (WebSubjectContext) context;
SecurityManager securityManager = wsc.resolveSecurityManager();
Session session = wsc.resolveSession();
boolean sessionEnabled = wsc.isSessionCreationEnabled();
PrincipalCollection principals = wsc.resolvePrincipals();
boolean authenticated = wsc.resolveAuthenticated();
String host = wsc.resolveHost();
ServletRequest request = wsc.resolveServletRequest();
ServletResponse response = wsc.resolveServletResponse();
return new WebDelegatingSubject(principals, authenticated, host, session, sessionEnabled,
request, response, securityManager);
}
示例4: createSessionContext
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
protected SessionContext createSessionContext(SubjectContext subjectContext) {
SessionContext sessionContext = super.createSessionContext(subjectContext);
if (subjectContext instanceof WebSubjectContext) {
WebSubjectContext wsc = (WebSubjectContext) subjectContext;
ServletRequest request = wsc.resolveServletRequest();
ServletResponse response = wsc.resolveServletResponse();
DefaultWebSessionContext webSessionContext = new DefaultWebSessionContext(sessionContext);
if (request != null) {
webSessionContext.setServletRequest(request);
}
if (response != null) {
webSessionContext.setServletResponse(response);
}
sessionContext = webSessionContext;
}
return sessionContext;
}
示例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
*/
@SuppressWarnings({"unchecked"})
protected 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:
Session session = resolveContextSession(context);
if (session != null) {
context.setSession(session);
}
} catch (InvalidSessionException e) {
log.debug("Resolved SubjectContext context session is invalid. Ignoring and creating an anonymous " +
"(session-less) Subject instance.", e);
}
return context;
}
示例6: createSessionContext
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
protected SessionContext createSessionContext(SubjectContext subjectContext) {
SessionContext sessionContext = super
.createSessionContext(subjectContext);
if (subjectContext instanceof WebSubjectContext) {
WebSubjectContext wsc = (WebSubjectContext) subjectContext;
ServletRequest request = wsc.resolveServletRequest();
ServletResponse response = wsc.resolveServletResponse();
DefaultWebSessionContext webSessionContext = new DefaultWebSessionContext(
sessionContext);
if (request != null) {
webSessionContext.setServletRequest(request);
}
if (response != null) {
webSessionContext.setServletResponse(response);
}
sessionContext = webSessionContext;
}
return sessionContext;
}
示例7: createSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
public Subject createSubject(SubjectContext subjectContext) {
if (!(subjectContext instanceof JWebSubjectContext))
return super.createSubject(subjectContext);
JWebSubjectContext c = (JWebSubjectContext)subjectContext;
SecurityManager securityManager = c.resolveSecurityManager();
Session session = c.resolveSession();
boolean sessionCreationEnabled = c.isSessionCreationEnabled();
PrincipalCollection principals = c.resolvePrincipals();
boolean authenticated = c.resolveAuthenticated();
String host = c.resolveHost();
Context context = c.getContext();
if (context == null) {
Subject subject = c.getSubject();
if (subject instanceof ContextSource)
context = ((ContextSource) subject).getContext();
}
return new JWebDelegatingSubject(principals, authenticated, host, session, sessionCreationEnabled, securityManager, context);
}
示例8: getRememberedSerializedIdentity
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
protected byte[] getRememberedSerializedIdentity(SubjectContext subjectContext) {
RequestWrapper requestWrapper = getRequestWrapper(subjectContext);
ResponseWrapper responseWrapper = getResponseWrapper(subjectContext);
String base64 = getCookie().readValue(requestWrapper, responseWrapper);
if (Cookie.DELETED_COOKIE_VALUE.equals(base64)) {
return null;
}
if (base64 != null) {
base64 = ensurePadding(base64);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Acquired Base64 encoded identity [" + base64 + "]");
}
byte[] decoded = Base64.decode(base64);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Base64 decoded byte array length: " + (decoded != null ? decoded.length : 0) + " bytes.");
}
return decoded;
} else {
//no cookie set - new site visitor?
return null;
}
}
示例9: createSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
public Subject createSubject(SubjectContext subjectContext) {
if (!(subjectContext instanceof LaputaSubjectContext)) {
return super.createSubject(subjectContext);
}
LaputaSubjectContext lsc = (LaputaSubjectContext) subjectContext;
SecurityManager securityManager = lsc.resolveSecurityManager();
Session session = lsc.resolveSession();
boolean sessionEnabled = lsc.isSessionCreationEnabled();
PrincipalCollection principals = lsc.resolvePrincipals();
boolean authenticated = lsc.resolveAuthenticated();
String host = lsc.resolveHost();
RequestWrapper requestWrapper = lsc.getRequestWrapper();
ResponseWrapper responseWrapper = lsc.getResponseWrapper();
return new LaputaDelegatingSubject(
principals,
authenticated,
host,
session,
sessionEnabled,
requestWrapper,
responseWrapper,
securityManager
);
}
示例10: getRememberedSerializedIdentity
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
protected byte[] getRememberedSerializedIdentity(SubjectContext subjectContext) {
if (isIdentityRemoved()) {
return null;
}
Cookie cookie = Requests.getCookies().get(getCookie().getName());
//no cookie set - new site visitor?
if (cookie == null) return null;
String base64 = cookie.getValue();
if (Cookies.DELETED_COOKIE_VALUE.equals(base64)) return null;
if (base64 != null) {
base64 = ensurePadding(base64);
logger.trace("Acquired Base64 encoded identity [" + base64 + "]");
byte[] decoded = Base64.decode(base64);
logger.trace("Base64 decoded byte array length: " + (decoded != null ? decoded.length : 0) + " bytes.");
return decoded;
} else {
//no cookie set - new site visitor?
return null;
}
}
示例11: setAuthProvider
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
public void setAuthProvider(AuthProvider authProvider) {
if (authProvider instanceof ShiroAuthProviderImpl) {
ShiroAuthProviderImpl shiroAuthProvider = (ShiroAuthProviderImpl)authProvider;
this.vertx = shiroAuthProvider.getVertx();
this.securityManager = shiroAuthProvider.getSecurityManager();
// generate the subject back from the provider
SubjectContext subjectContext = new DefaultSubjectContext();
PrincipalCollection coll = new SimplePrincipalCollection(username, shiroAuthProvider.getRealmName());
subjectContext.setPrincipals(coll);
subject = securityManager.createSubject(subjectContext);
} else {
throw new IllegalArgumentException("Not a ShiroAuthProviderImpl");
}
}
示例12: authenticate
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) {
vertx.executeBlocking(fut -> {
SubjectContext subjectContext = new DefaultSubjectContext();
Subject subject = securityManager.createSubject(subjectContext);
String username = authInfo.getString("username");
String password = authInfo.getString("password");
AuthenticationToken token = new UsernamePasswordToken(username, password);
try {
subject.login(token);
} catch (AuthenticationException e) {
throw new VertxException(e);
}
fut.complete(new ShiroUser(vertx, securityManager, subject, rolePrefix));
}, resultHandler);
}
示例13: createSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
/**
* {@inheritDoc} <br />
* Original code taken from {@link DefaultWebSubjectFactory} and modified
* in order to return {@link SodaWebDelegatingSubject} instances.
*/
@Override
public Subject createSubject( SubjectContext context ) {
if ( !(context instanceof WebSubjectContext) ) {
return super.createSubject( context );
}
WebSubjectContext wsc = (WebSubjectContext) context;
SecurityManager securityManager = wsc.resolveSecurityManager();
Session session = wsc.resolveSession();
boolean sessionEnabled = wsc.isSessionCreationEnabled();
PrincipalCollection principals = wsc.resolvePrincipals();
boolean authenticated = wsc.resolveAuthenticated();
String host = wsc.resolveHost();
ServletRequest request = wsc.resolveServletRequest();
ServletResponse response = wsc.resolveServletResponse();
return new SodaWebDelegatingSubject( principals, authenticated, host, session, sessionEnabled, request, response, securityManager );
}
示例14: createSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
public Subject createSubject(SubjectContext context) {
//不创建session
context.setSessionCreationEnabled(false);
super.createSubject(context).getSession(false);
return super.createSubject(context);
}
示例15: copy
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
protected SubjectContext copy(SubjectContext subjectContext ) {
if (subjectContext instanceof StalessSubjectContext) {
return new StalessSubjectContext(subjectContext) ;
}
return super.copy(subjectContext) ;
}