当前位置: 首页>>代码示例>>Java>>正文


Java ThreadContext.getSubject方法代码示例

本文整理汇总了Java中org.apache.shiro.util.ThreadContext.getSubject方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadContext.getSubject方法的具体用法?Java ThreadContext.getSubject怎么用?Java ThreadContext.getSubject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.util.ThreadContext的用法示例。


在下文中一共展示了ThreadContext.getSubject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setAttribute

import org.apache.shiro.util.ThreadContext; //导入方法依赖的package包/类
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException {
	try {
		super.setAttribute(sessionKey, attributeKey, value);
	} catch (UnknownSessionException e) {
		Subject subject = ThreadContext.getSubject();
		if ((value instanceof PrincipalCollection) && sessionDAO != null && subject != null
				&& (subject instanceof DelegatingSubject)) {
			try {
				SessionContext sessionContext = createSessionContext(((DelegatingSubject) subject).getHost());
				Session session = newSessionInstance(sessionContext);
				session.setAttribute(attributeKey, value);
				session.setTimeout(getGlobalSessionTimeout());
				((SimpleSession) session).setId(sessionKey.getSessionId());
				sessionDAO.create(session);
			} catch (Exception ex) {
				throw e;
			}
		} else {
			if (!(value instanceof SavedRequest)) {
				throw e;
			}
		}
	}
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:26,代码来源:SimpleSessionManager.java

示例2: filter

import org.apache.shiro.util.ThreadContext; //导入方法依赖的package包/类
/**
 * Authorizes the client for the annotated permissions.  If any authorizations fail an {@link AuthorizationException}
 * will be thrown, otherwise the original request is returned.
 */
@Override
public ContainerRequest filter(ContainerRequest request) {
    Subject subject = ThreadContext.getSubject();

    String[] permissions = resolvePermissions(request);

    if (permissions.length == 1 || _logical == Logical.AND) {
        // Shortcut call to check all permissions at once
        subject.checkPermissions(permissions);
    } else {
        // Check each permission until any passes
        boolean anyPermitted = false;
        int p = 0;
        while (!anyPermitted) {
            try {
                subject.checkPermission(permissions[p]);
                anyPermitted = true;
            } catch (AuthorizationException e) {
                // If this is the last permission then pass the exception along
                if (++p == permissions.length) {
                    throw e;
                }
            }
        }
    }

    return request;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:33,代码来源:AuthorizationResourceFilter.java

示例3: getSubject

import org.apache.shiro.util.ThreadContext; //导入方法依赖的package包/类
public Subject getSubject(){
    Subject currentUser = ThreadContext.getSubject();// SecurityUtils.getSubject();
    if (currentUser == null){
        currentUser = SecurityUtils.getSubject();
    }
    return currentUser;
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:8,代码来源:AppUserSession.java

示例4: filter

import org.apache.shiro.util.ThreadContext; //导入方法依赖的package包/类
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
    Subject subject = ThreadContext.getSubject();
    if (subject != null) {
        if (subject.isAuthenticated()) {
            subject.logout();
        }
        ThreadContext.unbindSubject();
    }
    return response;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:12,代码来源:AuthenticationResourceFilter.java

示例5: getSubject

import org.apache.shiro.util.ThreadContext; //导入方法依赖的package包/类
/**
 * Gets the subject of the current thread. There can only be one subject
 * logged in within a thread.
 * 
 * @return the current subject of the current thread
 */
protected Subject getSubject() {
	Subject subject = ThreadContext.getSubject();
	if (subject == null) {
		subject = this.builder.buildSubject();
		ThreadContext.bind(manager);
		ThreadContext.bind(subject);
	}

	return subject;
}
 
开发者ID:pmeisen,项目名称:dis-timeintervaldataanalyzer,代码行数:17,代码来源:ShiroAuthManager.java

示例6: getSubject

import org.apache.shiro.util.ThreadContext; //导入方法依赖的package包/类
/**
 * Returns the currently accessible {@code Subject} available to the calling code depending on
 * runtime environment.
 * <p/>
 * This method is provided as a way of obtaining a {@code Subject} without having to resort to
 * implementation-specific methods.  It also allows the Shiro team to change the underlying implementation of
 * this method in the future depending on requirements/updates without affecting your code that uses it.
 *
 * @return the currently accessible {@code Subject} accessible to the calling code.
 * @throws IllegalStateException if no {@link Subject Subject} instance or
 *                               {@link SecurityManager SecurityManager} instance is available with which to obtain
 *                               a {@code Subject}, which which is considered an invalid application configuration
 *                               - a Subject should <em>always</em> be available to the caller.
 */
public static Subject getSubject() {
    Subject subject = ThreadContext.getSubject();
    if (subject == null) {
        subject = (new Subject.Builder()).buildSubject();
        ThreadContext.bind(subject);
    }
    return subject;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:23,代码来源:SecurityUtils.java


注:本文中的org.apache.shiro.util.ThreadContext.getSubject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。