本文整理汇总了Java中org.apache.shiro.subject.SubjectContext类的典型用法代码示例。如果您正苦于以下问题:Java SubjectContext类的具体用法?Java SubjectContext怎么用?Java SubjectContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SubjectContext类属于org.apache.shiro.subject包,在下文中一共展示了SubjectContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:monkeyk,项目名称:oauth2-shiro,代码行数:21,代码来源:OAuth2SubjectFactory.java
示例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;
}
开发者ID:xmomen,项目名称:dms-webapp,代码行数:21,代码来源:WebSecurityManagerExt.java
示例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);
}
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:DefaultWebSubjectFactory.java
示例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;
}
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:20,代码来源:DefaultWebSecurityManager.java
示例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;
}
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:33,代码来源:DefaultSecurityManager.java
示例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;
}
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:22,代码来源:SimpleWebSecurityManager.java
示例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);
}
开发者ID:MTDdk,项目名称:jawn,代码行数:22,代码来源:JWebSubjectFactory.java
示例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;
}
}
开发者ID:orctom,项目名称:laputa,代码行数:25,代码来源:CookieRememberMeManager.java
示例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
);
}
开发者ID:orctom,项目名称:laputa,代码行数:27,代码来源:LaputaSubjectFactory.java
示例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;
}
}
开发者ID:icode,项目名称:ameba-shiro,代码行数:24,代码来源:CookieRememberMeManager.java
示例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");
}
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:17,代码来源:ShiroUser.java
示例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);
}
开发者ID:vert-x3,项目名称:vertx-auth,代码行数:17,代码来源:ShiroAuthProviderImpl.java
示例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 );
}
开发者ID:PE-INTERNATIONAL,项目名称:soda4lca,代码行数:23,代码来源:SodaSubjectFactory.java
示例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);
}
开发者ID:YupaiTS,项目名称:docs-manage,代码行数:8,代码来源:StatelessSubjectFactory.java
示例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) ;
}
开发者ID:auslides,项目名称:stateless-shiro,代码行数:8,代码来源:StalessSecurityManager.java
示例16: createSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
public Subject createSubject(SubjectContext context) {
WebSubjectContext wsc = (WebSubjectContext) context;
AuthenticationInfo info = wsc.getAuthenticationInfo();
AccountProfile profile = null;
AccountSubject subject = null;
if (info instanceof AccountAuthenticationInfo) {
profile = ((AccountAuthenticationInfo) info).getProfile();
subject = doCreate(wsc, profile);
subject.getSession(true).setAttribute("profile", profile);
}else{
Session session = wsc.getSession();
if(session != null){
profile = (AccountProfile)session.getAttribute("profile");
}
subject = doCreate(wsc, profile);
boolean isRemembered = subject.isRemembered();
if (session == null) {
wsc.setSessionCreationEnabled(true);
subject.getSession(true);
}
if (isRemembered && profile == null) {
Object username = subject.getPrincipal();
profile = userService.getProfileByName((String) username);
subject.getSession(true).setTimeout(30 * 60 * Consts.TIME_MIN);
subject.getSession(true).setAttribute("profile", profile);
}
}
return doCreate(wsc, profile);
}
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:35,代码来源:AccountSubjectFactory.java
示例17: createSubject
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
public Subject createSubject(SubjectContext context) {
// 不创建session
context.setSessionCreationEnabled(false);
return super.createSubject(context);
}
开发者ID:wanghongfei,项目名称:shiro-spring-boot-starter,代码行数:8,代码来源:StatelessSubjectFactory.java
示例18: createSubjectContext
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
/**
* Required to by-pass a Shiro issue caused by not binding the SecurityManager globally.
*/
@Override
protected SubjectContext createSubjectContext() {
SubjectContext subjectContext = super.createSubjectContext();
subjectContext.setSecurityManager(this);
return subjectContext;
}
开发者ID:bazaarvoice,项目名称:emodb,代码行数:10,代码来源:ApiKeySecurityManager.java
示例19: copy
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
protected SubjectContext copy(SubjectContext subjectContext) {
if (subjectContext instanceof WebSubjectContext) {
return new DefaultWebSubjectContext((WebSubjectContext) subjectContext);
}
return super.copy(subjectContext);
}
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:8,代码来源:DefaultWebSecurityManager.java
示例20: getSessionKey
import org.apache.shiro.subject.SubjectContext; //导入依赖的package包/类
@Override
protected SessionKey getSessionKey(SubjectContext context) {
if (WebUtils.isWeb(context)) {
Serializable sessionId = context.getSessionId();
ServletRequest request = WebUtils.getRequest(context);
ServletResponse response = WebUtils.getResponse(context);
return new WebSessionKey(sessionId, request, response);
} else {
return super.getSessionKey(context);
}
}
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:13,代码来源:DefaultWebSecurityManager.java
注:本文中的org.apache.shiro.subject.SubjectContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论