Search in sources :

Example 86 with Session

use of org.apache.shiro.session.Session in project shiro by apache.

the class DefaultSampleManager method setValue.

public void setValue(String newValue) {
    Subject subject = SecurityUtils.getSubject();
    Session session = subject.getSession();
    if (log.isDebugEnabled()) {
        log.debug("saving session key [" + VALUE_KEY + "] with value [" + newValue + "] on session with id [" + session.getId() + "]");
    }
    session.setAttribute(VALUE_KEY, newValue);
}
Also used : Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session)

Example 87 with Session

use of org.apache.shiro.session.Session in project shiro by apache.

the class JnlpController method handleRequestInternal.

/*--------------------------------------------
    |               M E T H O D S               |
    ============================================*/
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Subject subject = SecurityUtils.getSubject();
    Session session = null;
    if (subject != null) {
        session = subject.getSession();
    }
    if (session == null) {
        String msg = "Expected a non-null Shiro session.";
        throw new IllegalArgumentException(msg);
    }
    StringBuilder sb = new StringBuilder();
    sb.append("http://");
    sb.append(request.getServerName());
    if (request.getServerPort() != 80) {
        sb.append(":");
        sb.append(request.getServerPort());
    }
    sb.append(request.getContextPath());
    // prevent JNLP caching by setting response headers
    response.setHeader("cache-control", "no-cache");
    response.setHeader("pragma", "no-cache");
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("codebaseUrl", sb.toString());
    model.put("sessionId", session.getId());
    return new ModelAndView(jnlpView, model);
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session)

Example 88 with Session

use of org.apache.shiro.session.Session in project killbill by killbill.

the class KillBillWebSessionManager method start.

@Override
public Session start(final SessionContext context) {
    final Session session = createSession(context);
    // See above
    // applyGlobalSessionTimeout(session);
    onStart(session, context);
    notifyStart(session);
    return createExposedSession(session, context);
}
Also used : Session(org.apache.shiro.session.Session)

Example 89 with Session

use of org.apache.shiro.session.Session in project killbill by killbill.

the class KillBillWebSessionManager method newSessionInstance.

@Override
protected Session newSessionInstance(final SessionContext context) {
    final Session session = super.newSessionInstance(context);
    // DefaultWebSessionManager will call applyGlobalSessionTimeout() in
    // start() below instead, which in turn calls onChange() and triggers a DAO UPDATE call
    session.setTimeout(getGlobalSessionTimeout());
    return session;
}
Also used : Session(org.apache.shiro.session.Session)

Example 90 with Session

use of org.apache.shiro.session.Session in project killbill by killbill.

the class KillBillSubjectDAO method saveToSession.

@Override
protected void saveToSession(final Subject subject) {
    boolean updatesDisabled = false;
    Session session = subject.getSession(false);
    if (session == null && !CollectionUtils.isEmpty(subject.getPrincipals())) {
        // Force the creation of the session here to get the id
        session = subject.getSession();
        // Optimize the session creation path: the default saveToSession implementation
        // will call setAttribute() several times in a row, causing unnecessary DAO UPDATE queries
        updatesDisabled = disableUpdatesForSession(subject, session);
    }
    super.saveToSession(subject);
    if (updatesDisabled) {
        enableUpdatesForSession(subject, session);
    }
}
Also used : Session(org.apache.shiro.session.Session)

Aggregations

Session (org.apache.shiro.session.Session)93 Subject (org.apache.shiro.subject.Subject)34 Test (org.junit.Test)21 Serializable (java.io.Serializable)11 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)8 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 SecurityManager (org.apache.shiro.mgt.SecurityManager)5 SessionListener (org.apache.shiro.session.SessionListener)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 User (com.hfut.entity.User)4 Subject (ddf.security.Subject)4 ApiOperation (io.swagger.annotations.ApiOperation)4 Date (java.util.Date)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 AuthenticationException (org.apache.shiro.authc.AuthenticationException)4 InvalidSessionException (org.apache.shiro.session.InvalidSessionException)4 SessionListenerAdapter (org.apache.shiro.session.SessionListenerAdapter)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3