Search in sources :

Example 76 with Session

use of org.apache.catalina.Session in project Payara by payara.

the class Response method toEncoded.

/**
 * Return the specified URL with the specified session identifier
 * suitably encoded.
 *
 * @param url URL to be encoded with the session id
 * @param sessionId Session id to be included in the encoded URL
 * @param sessionVersion Session version to be included in the encoded URL
 */
private String toEncoded(String url, String sessionId, String sessionVersion) {
    if (url == null || sessionId == null)
        return url;
    String path = url;
    String query = "";
    String anchor = "";
    int question = url.indexOf('?');
    if (question >= 0) {
        path = url.substring(0, question);
        query = url.substring(question);
    }
    int pound = path.indexOf('#');
    if (pound >= 0) {
        anchor = path.substring(pound);
        path = path.substring(0, pound);
    }
    StringBuilder sb = new StringBuilder(path);
    if (sb.length() > 0) {
        // jsessionid can't be first.
        StandardContext ctx = (StandardContext) getContext();
        String sessionParamName = ctx != null ? ctx.getSessionParameterName() : Globals.SESSION_PARAMETER_NAME;
        sb.append(";").append(sessionParamName).append("=");
        sb.append(sessionId);
        if (ctx != null && ctx.getJvmRoute() != null) {
            sb.append('.').append(ctx.getJvmRoute());
        }
        // START SJSAS 6337561
        String jrouteId = request.getHeader(Constants.PROXY_JROUTE);
        if (jrouteId != null) {
            sb.append(":");
            sb.append(jrouteId);
        }
        // END SJSAS 6337561
        final Session session = request.getSessionInternal(false);
        if (session != null) {
            String replicaLocation = (String) session.getNote(Globals.JREPLICA_SESSION_NOTE);
            if (replicaLocation != null) {
                sb.append(Globals.JREPLICA_PARAMETER);
                sb.append(replicaLocation);
            }
        }
        if (sessionVersion != null) {
            sb.append(Globals.SESSION_VERSION_PARAMETER);
            sb.append(sessionVersion);
        }
    }
    sb.append(anchor);
    sb.append(query);
    return sb.toString();
}
Also used : StandardContext(org.apache.catalina.core.StandardContext) RequestUtil.createSessionVersionString(org.apache.catalina.util.RequestUtil.createSessionVersionString) Session(org.apache.catalina.Session)

Example 77 with Session

use of org.apache.catalina.Session in project Payara by payara.

the class PESessionLocker method getSession.

private Session getSession(ServletRequest request) {
    javax.servlet.http.HttpServletRequest httpReq = (javax.servlet.http.HttpServletRequest) request;
    javax.servlet.http.HttpSession httpSess = httpReq.getSession(false);
    if (httpSess == null) {
        return null;
    }
    String id = httpSess.getId();
    Manager mgr = _context.getManager();
    Session sess = null;
    try {
        sess = mgr.findSession(id);
    } catch (java.io.IOException ex) {
    }
    return sess;
}
Also used : Manager(org.apache.catalina.Manager) Session(org.apache.catalina.Session) StandardSession(org.apache.catalina.session.StandardSession)

Example 78 with Session

use of org.apache.catalina.Session in project Payara by payara.

the class ReplicationManagerBase method removeSessionFromManagerCache.

public void removeSessionFromManagerCache(Session session) {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("in " + this.getClass().getName() + ">>removeSessionFromManagerCache:session = " + session);
    }
    if (session == null) {
        return;
    }
    Session removed = null;
    removed = sessions.remove(session.getIdInternal());
    if (removed != null && _logger.isLoggable(Level.FINE)) {
        _logger.fine("Remove from manager cache id=" + session.getId());
    }
}
Also used : Session(org.apache.catalina.Session)

Example 79 with Session

use of org.apache.catalina.Session in project Payara by payara.

the class ReplicationStore method loadFromBackingStore.

private Session loadFromBackingStore(String id, String version) throws IOException, ClassNotFoundException, BackingStoreException {
    SimpleMetadata metaData = getSimpleMetadataBackingStore().load(id, version);
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("ReplicationStore>>loadFromBackingStore:id=" + id + ", metaData=" + metaData);
    }
    Session session = getSession(metaData);
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.finest("ReplicationStore->Session is " + session);
    }
    return session;
}
Also used : SimpleMetadata(org.glassfish.ha.store.util.SimpleMetadata) Session(org.apache.catalina.Session)

Example 80 with Session

use of org.apache.catalina.Session in project keycloak by keycloak.

the class CatalinaSessionTokenStore method saveAccountInfo.

@Override
public void saveAccountInfo(OidcKeycloakAccount account) {
    RefreshableKeycloakSecurityContext securityContext = (RefreshableKeycloakSecurityContext) account.getKeycloakSecurityContext();
    Set<String> roles = account.getRoles();
    GenericPrincipal principal = principalFactory.createPrincipal(request.getContext().getRealm(), account.getPrincipal(), roles);
    SerializableKeycloakAccount sAccount = new SerializableKeycloakAccount(roles, account.getPrincipal(), securityContext);
    Session session = request.getSessionInternal(true);
    session.setPrincipal(principal);
    session.setAuthType("KEYCLOAK");
    session.getSession().setAttribute(SerializableKeycloakAccount.class.getName(), sAccount);
    session.getSession().setAttribute(KeycloakSecurityContext.class.getName(), account.getKeycloakSecurityContext());
    String username = securityContext.getToken().getSubject();
    log.fine("userSessionManagement.login: " + username);
    this.sessionManagement.login(session);
}
Also used : GenericPrincipal(org.apache.catalina.realm.GenericPrincipal) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) RefreshableKeycloakSecurityContext(org.keycloak.adapters.RefreshableKeycloakSecurityContext) KeycloakSecurityContext(org.keycloak.KeycloakSecurityContext) Session(org.apache.catalina.Session)

Aggregations

Session (org.apache.catalina.Session)106 IOException (java.io.IOException)24 Manager (org.apache.catalina.Manager)22 Context (org.apache.catalina.Context)16 HttpSession (javax.servlet.http.HttpSession)13 StringManager (org.apache.tomcat.util.res.StringManager)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpSession (jakarta.servlet.http.HttpSession)7 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)7 Principal (java.security.Principal)6 Realm (org.apache.catalina.Realm)6 StandardContext (org.apache.catalina.core.StandardContext)6 ClusterSession (org.apache.catalina.ha.ClusterSession)6 DeltaSession (org.apache.catalina.ha.session.DeltaSession)6 Container (org.apache.catalina.Container)5 ArrayList (java.util.ArrayList)4 StandardSession (org.apache.catalina.session.StandardSession)4 BufferedOutputStream (java.io.BufferedOutputStream)3 File (java.io.File)3 ObjectOutputStream (java.io.ObjectOutputStream)3