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


Java SessionKey.getSessionId方法代码示例

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


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

示例1: createRemoteInvocation

import org.apache.shiro.session.mgt.SessionKey; //导入方法依赖的package包/类
/**
 * Creates a {@link RemoteInvocation} with the current session ID as an
 * {@link RemoteInvocation#getAttribute(String) attribute}.
 *
 * @param mi the method invocation that the remote invocation should be based on.
 * @return a remote invocation object containing the current session ID as an attribute.
 */
public RemoteInvocation createRemoteInvocation(MethodInvocation mi) {

    Serializable sessionId = null;
    String host = null;
    boolean sessionManagerMethodInvocation = false;

    //If the calling MI is for a remoting SessionManager delegate, we need to acquire the session ID from the method
    //argument and NOT interact with SecurityUtils/subject.getSession to avoid a stack overflow
    Class miDeclaringClass = mi.getMethod().getDeclaringClass();
    if (SessionManager.class.equals(miDeclaringClass) || NativeSessionManager.class.equals(miDeclaringClass)) {
        sessionManagerMethodInvocation = true;
        //for SessionManager calls, all method calls except the 'start' methods require a SessionKey
        // as the first argument, so just get it from there:
        if (!mi.getMethod().getName().equals("start")) {
            SessionKey key = (SessionKey) mi.getArguments()[0];
            sessionId = key.getSessionId();
        }
    }

    //tried the delegate. Use the injected session id if given
    if (sessionId == null) sessionId = this.sessionId;

    // If sessionId is null, only then try the Subject:
    if (sessionId == null) {
        try {
            // HACK Check if can get the securityManager - this'll cause an exception if it's not set 
            SecurityUtils.getSecurityManager();
            if (!sessionManagerMethodInvocation) {
                Subject subject = SecurityUtils.getSubject();
                Session session = subject.getSession(false);
                if (session != null) {
                    sessionId = session.getId();
                    host = session.getHost();
                }
            }
        }
        catch (Exception e) {
            log.trace("No security manager set. Trying next to get session id from system property");
        }
    }
    //No call to the sessionManager, and the Subject doesn't have a session.  Try a system property
    //as a last result:
    if (sessionId == null) {
        if (log.isTraceEnabled()) {
            log.trace("No Session found for the currently executing subject via subject.getSession(false).  " +
                    "Attempting to revert back to the 'shiro.session.id' system property...");
        }
        sessionId = System.getProperty(SESSION_ID_SYSTEM_PROPERTY_NAME);
        if (sessionId == null && log.isTraceEnabled()) {
            log.trace("No 'shiro.session.id' system property found.  Heuristics have been exhausted; " +
                    "RemoteInvocation will not contain a sessionId.");
        }
    }

    RemoteInvocation ri = new RemoteInvocation(mi);
    if (sessionId != null) {
        ri.addAttribute(SESSION_ID_KEY, sessionId);
    }
    if (host != null) {
        ri.addAttribute(HOST_KEY, host);
    }

    return ri;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:72,代码来源:SecureRemoteInvocationFactory.java

示例2: getSessionId

import org.apache.shiro.session.mgt.SessionKey; //导入方法依赖的package包/类
protected Serializable getSessionId(SessionKey sessionKey) {
	return sessionKey.getSessionId();
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:4,代码来源:SimpleSessionManager.java


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