本文整理汇总了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;
}
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}