Search in sources :

Example 1 with SessionContext

use of org.apache.shiro.session.mgt.SessionContext in project shiro by apache.

the class DelegatingSubject method getSession.

public Session getSession(boolean create) {
    if (log.isTraceEnabled()) {
        log.trace("attempting to get session; create = " + create + "; session is null = " + (this.session == null) + "; session has id = " + (this.session != null && session.getId() != null));
    }
    if (this.session == null && create) {
        // added in 1.2:
        if (!isSessionCreationEnabled()) {
            String msg = "Session creation has been disabled for the current subject.  This exception indicates " + "that there is either a programming error (using a session when it should never be " + "used) or that Shiro's configuration needs to be adjusted to allow Sessions to be created " + "for the current Subject.  See the " + DisabledSessionException.class.getName() + " JavaDoc " + "for more.";
            throw new DisabledSessionException(msg);
        }
        log.trace("Starting session for host {}", getHost());
        SessionContext sessionContext = createSessionContext();
        Session session = this.securityManager.start(sessionContext);
        this.session = decorate(session);
    }
    return this.session;
}
Also used : SessionContext(org.apache.shiro.session.mgt.SessionContext) DefaultSessionContext(org.apache.shiro.session.mgt.DefaultSessionContext) ProxiedSession(org.apache.shiro.session.ProxiedSession) Session(org.apache.shiro.session.Session)

Example 2 with SessionContext

use of org.apache.shiro.session.mgt.SessionContext in project shiro by apache.

the class DefaultWebSecurityManager method createSessionContext.

@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;
}
Also used : ServletRequest(javax.servlet.ServletRequest) ShiroHttpServletRequest(org.apache.shiro.web.servlet.ShiroHttpServletRequest) ServletResponse(javax.servlet.ServletResponse) SessionContext(org.apache.shiro.session.mgt.SessionContext) WebSubjectContext(org.apache.shiro.web.subject.WebSubjectContext) DefaultWebSubjectContext(org.apache.shiro.web.subject.support.DefaultWebSubjectContext)

Aggregations

SessionContext (org.apache.shiro.session.mgt.SessionContext)2 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 ProxiedSession (org.apache.shiro.session.ProxiedSession)1 Session (org.apache.shiro.session.Session)1 DefaultSessionContext (org.apache.shiro.session.mgt.DefaultSessionContext)1 ShiroHttpServletRequest (org.apache.shiro.web.servlet.ShiroHttpServletRequest)1 WebSubjectContext (org.apache.shiro.web.subject.WebSubjectContext)1 DefaultWebSubjectContext (org.apache.shiro.web.subject.support.DefaultWebSubjectContext)1