org.apache.catalina.SessionListener Java Examples

The following examples show how to use org.apache.catalina.SessionListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonSessionManager.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Session createSession(String sessionId) {
    Session session = super.createSession(sessionId);
    
    if (broadcastSessionEvents) {
        getTopic().publish(new SessionCreatedMessage(getNodeId(), session.getId()));
        session.addSessionListener(new SessionListener() {
            @Override
            public void sessionEvent(SessionEvent event) {
                if (event.getType() == Session.SESSION_DESTROYED_EVENT) {
                    getTopic().publish(new SessionDestroyedMessage(getNodeId(), session.getId()));
                }
            }
        });
    }
    return session;
}
 
Example #2
Source File: RedissonSessionManager.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Session createSession(String sessionId) {
    Session session = super.createSession(sessionId);
    
    if (broadcastSessionEvents) {
        getTopic().publish(new SessionCreatedMessage(getNodeId(), session.getId()));
        session.addSessionListener(new SessionListener() {
            @Override
            public void sessionEvent(SessionEvent event) {
                if (event.getType() == Session.SESSION_DESTROYED_EVENT) {
                    getTopic().publish(new SessionDestroyedMessage(getNodeId(), session.getId()));
                }
            }
        });
    }
    return session;
}
 
Example #3
Source File: RedissonSessionManager.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
public Session createSession(String sessionId) {
    Session session = super.createSession(sessionId);
    
    if (broadcastSessionEvents) {
        getTopic().publish(new SessionCreatedMessage(getNodeId(), session.getId()));
        session.addSessionListener(new SessionListener() {
            @Override
            public void sessionEvent(SessionEvent event) {
                if (event.getType() == Session.SESSION_DESTROYED_EVENT) {
                    getTopic().publish(new SessionDestroyedMessage(getNodeId(), session.getId()));
                }
            }
        });
    }
    return session;
}
 
Example #4
Source File: DeltaSession.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void addSessionListener(SessionListener listener, boolean addDeltaRequest) {
    lockInternal();
    try {
        super.addSessionListener(listener);
        if (addDeltaRequest && listener instanceof ReplicatedSessionListener) {
            deltaRequest.addSessionListener(listener);
        }
    } finally {
        unlockInternal();
    }
}
 
Example #5
Source File: StandardSession.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Notify all session event listeners that a particular event has
 * occurred for this Session.  The default implementation performs
 * this notification synchronously using the calling thread.
 *
 * @param type Event type
 * @param data Event data
 */
public void fireSessionEvent(String type, Object data) {
    if (listeners.size() < 1)
        return;
    SessionEvent event = new SessionEvent(this, type, data);
    SessionListener list[] = new SessionListener[0];
    synchronized (listeners) {
        list = listeners.toArray(list);
    }

    for (int i = 0; i < list.length; i++){
        (list[i]).sessionEvent(event);
    }

}
 
Example #6
Source File: DeltaSession.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void removeSessionListener(SessionListener listener, boolean addDeltaRequest) {
    lock();
    try {
        super.removeSessionListener(listener);
        if (addDeltaRequest && deltaRequest != null && listener instanceof ReplicatedSessionListener) {
            deltaRequest.removeSessionListener(listener);
        }
    } finally {
        unlock();
    }
}
 
Example #7
Source File: DeltaSession.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void addSessionListener(SessionListener listener, boolean addDeltaRequest) {
    lock();
    try {
        super.addSessionListener(listener);
        if (addDeltaRequest && deltaRequest != null && listener instanceof ReplicatedSessionListener) {
            deltaRequest.addSessionListener(listener);
        }
    } finally {
        unlock();
    }
}
 
Example #8
Source File: StandardSession.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Notify all session event listeners that a particular event has
 * occurred for this Session.  The default implementation performs
 * this notification synchronously using the calling thread.
 *
 * @param type Event type
 * @param data Event data
 */
public void fireSessionEvent(String type, Object data) {
    if (listeners.size() < 1)
        return;
    SessionEvent event = new SessionEvent(this, type, data);
    SessionListener list[] = new SessionListener[0];
    synchronized (listeners) {
        list = listeners.toArray(list);
    }

    for (int i = 0; i < list.length; i++){
        (list[i]).sessionEvent(event);
    }

}
 
Example #9
Source File: DeltaSession.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void removeSessionListener(SessionListener listener, boolean addDeltaRequest) {
    lock();
    try {
        super.removeSessionListener(listener);
        if (addDeltaRequest && deltaRequest != null && listener instanceof ReplicatedSessionListener) {
            deltaRequest.removeSessionListener(listener);
        }
    } finally {
        unlock();
    }
}
 
Example #10
Source File: DeltaSession.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void addSessionListener(SessionListener listener, boolean addDeltaRequest) {
    lock();
    try {
        super.addSessionListener(listener);
        if (addDeltaRequest && deltaRequest != null && listener instanceof ReplicatedSessionListener) {
            deltaRequest.addSessionListener(listener);
        }
    } finally {
        unlock();
    }
}
 
Example #11
Source File: StandardSession.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Notify all session event listeners that a particular event has
 * occurred for this Session.  The default implementation performs
 * this notification synchronously using the calling thread.
 *
 * @param type Event type
 * @param data Event data
 */
public void fireSessionEvent(String type, Object data) {
    if (listeners.size() < 1)
        return;
    SessionEvent event = new SessionEvent(this, type, data);
    SessionListener list[] = new SessionListener[0];
    synchronized (listeners) {
        list = listeners.toArray(list);
    }

    for (int i = 0; i < list.length; i++){
        (list[i]).sessionEvent(event);
    }

}
 
Example #12
Source File: DeltaSession.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public void removeSessionListener(SessionListener listener, boolean addDeltaRequest) {
    lockInternal();
    try {
        super.removeSessionListener(listener);
        if (addDeltaRequest && listener instanceof ReplicatedSessionListener) {
            deltaRequest.removeSessionListener(listener);
        }
    } finally {
        unlockInternal();
    }
}
 
Example #13
Source File: DummyProxySession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void addSessionListener(SessionListener listener) {
    // NOOP
}
 
Example #14
Source File: ClusterSingleSignOn.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
protected SessionListener getSessionListener(String ssoId) {
    return new ClusterSingleSignOnListener(ssoId);
}
 
Example #15
Source File: DeltaSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void removeSessionListener(SessionListener listener) {
    removeSessionListener(listener, true);
}
 
Example #16
Source File: DeltaRequest.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public void removeSessionListener(SessionListener listener) {
    addAction(TYPE_LISTENER, ACTION_REMOVE, NAME_LISTENER ,listener);
}
 
Example #17
Source File: DeltaSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
private void readObject(ObjectInput stream) throws ClassNotFoundException, IOException {

        // Deserialize the scalar instance variables (except Manager)
        authType = null; // Transient only
        creationTime = ( (Long) stream.readObject()).longValue();
        lastAccessedTime = ( (Long) stream.readObject()).longValue();
        maxInactiveInterval = ( (Integer) stream.readObject()).intValue();
        isNew = ( (Boolean) stream.readObject()).booleanValue();
        isValid = ( (Boolean) stream.readObject()).booleanValue();
        thisAccessedTime = ( (Long) stream.readObject()).longValue();
        version = ( (Long) stream.readObject()).longValue();
        boolean hasPrincipal = stream.readBoolean();
        principal = null;
        if (hasPrincipal) {
            principal = SerializablePrincipal.readPrincipal(stream);
        }

        //        setId((String) stream.readObject());
        id = (String) stream.readObject();
        if (log.isDebugEnabled()) log.debug(sm.getString("deltaSession.readSession", id));

        // Deserialize the attribute count and attribute values
        if (attributes == null) attributes = new ConcurrentHashMap<String, Object>();
        int n = ( (Integer) stream.readObject()).intValue();
        boolean isValidSave = isValid;
        isValid = true;
        for (int i = 0; i < n; i++) {
            String name = (String) stream.readObject();
            final Object value;
            try {
                value = stream.readObject();
            } catch (WriteAbortedException wae) {
                if (wae.getCause() instanceof NotSerializableException) {
                    // Skip non serializable attributes
                    continue;
                }
                throw wae;
            }
            // Handle the case where the filter configuration was changed while
            // the web application was stopped.
            if (exclude(name, value)) {
                continue;
            }
            attributes.put(name, value);
        }
        isValid = isValidSave;

        // Session listeners
        n = ((Integer) stream.readObject()).intValue();
        if (listeners == null || n > 0) {
            listeners = new ArrayList<SessionListener>();
        }
        for (int i = 0; i < n; i++) {
            SessionListener listener = (SessionListener) stream.readObject();
            listeners.add(listener);
        }

        if (notes == null) {
            notes = new Hashtable<String,Object>();
        }
        activate();
    }
 
Example #18
Source File: DeltaRequest.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void addSessionListener(SessionListener listener) {
    addAction(TYPE_LISTENER, ACTION_SET, NAME_LISTENER ,listener);
}
 
Example #19
Source File: DeltaRequest.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void removeSessionListener(SessionListener listener) {
    addAction(TYPE_LISTENER, ACTION_REMOVE, NAME_LISTENER ,listener);
}
 
Example #20
Source File: DeltaRequest.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
public void execute(DeltaSession session, boolean notifyListeners) {
    if ( !this.sessionId.equals( session.getId() ) )
        throw new java.lang.IllegalArgumentException("Session id mismatch, not executing the delta request");
    session.access();
    for ( int i=0; i<actions.size(); i++ ) {
        AttributeInfo info = actions.get(i);
        switch ( info.getType() ) {
            case TYPE_ATTRIBUTE:
                if ( info.getAction() == ACTION_SET ) {
                    if ( log.isTraceEnabled() ) log.trace("Session.setAttribute('"+info.getName()+"', '"+info.getValue()+"')");
                    session.setAttribute(info.getName(), info.getValue(),notifyListeners,false);
                }  else {
                    if ( log.isTraceEnabled() ) log.trace("Session.removeAttribute('"+info.getName()+"')");
                    session.removeAttribute(info.getName(),notifyListeners,false);
                }
                    
                break;
            case TYPE_ISNEW:
            if ( log.isTraceEnabled() ) log.trace("Session.setNew('"+info.getValue()+"')");
                session.setNew(((Boolean)info.getValue()).booleanValue(),false);
                break;
            case TYPE_MAXINTERVAL:
                if ( log.isTraceEnabled() ) log.trace("Session.setMaxInactiveInterval('"+info.getValue()+"')");
                session.setMaxInactiveInterval(((Integer)info.getValue()).intValue(),false);
                break;
            case TYPE_PRINCIPAL:
                Principal p = null;
                if ( info.getAction() == ACTION_SET ) {
                    SerializablePrincipal sp = (SerializablePrincipal)info.getValue();
                    p = sp.getPrincipal();
                }
                session.setPrincipal(p,false);
                break;
            case TYPE_AUTHTYPE:
                String authType = null;
                if ( info.getAction() == ACTION_SET ) {
                    authType = (String)info.getValue();
                }
                session.setAuthType(authType,false);
                break;
            case TYPE_LISTENER:
                SessionListener listener = (SessionListener) info.getValue();
                if (info.getAction() == ACTION_SET) {
                    session.addSessionListener(listener,false);
                } else {
                    session.removeSessionListener(listener,false);
                }
                break;
            default :
                throw new java.lang.IllegalArgumentException("Invalid attribute info type="+info);
        }//switch
    }//for
    session.endAccess();
    reset();
}
 
Example #21
Source File: ClusterSingleSignOn.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
protected SessionListener getSessionListener(String ssoId) {
    return new ClusterSingleSignOnListener(ssoId);
}
 
Example #22
Source File: DeltaSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void addSessionListener(SessionListener listener) {
    addSessionListener(listener, true);
}
 
Example #23
Source File: DummyProxySession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public void removeSessionListener(SessionListener listener) {
    // NOOP
}
 
Example #24
Source File: StandardSession.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Read a serialized version of this session object from the specified
 * object input stream.
 * <p>
 * <b>IMPLEMENTATION NOTE</b>:  The reference to the owning Manager
 * is not restored by this method, and must be set explicitly.
 *
 * @param stream The input stream to read from
 *
 * @exception ClassNotFoundException if an unknown class is specified
 * @exception IOException if an input/output error occurs
 */
protected void readObject(ObjectInputStream stream)
    throws ClassNotFoundException, IOException {

    // Deserialize the scalar instance variables (except Manager)
    authType = null;        // Transient only
    creationTime = ((Long) stream.readObject()).longValue();
    lastAccessedTime = ((Long) stream.readObject()).longValue();
    maxInactiveInterval = ((Integer) stream.readObject()).intValue();
    isNew = ((Boolean) stream.readObject()).booleanValue();
    isValid = ((Boolean) stream.readObject()).booleanValue();
    thisAccessedTime = ((Long) stream.readObject()).longValue();
    principal = null;        // Transient only
    //        setId((String) stream.readObject());
    id = (String) stream.readObject();
    if (manager.getContainer().getLogger().isDebugEnabled())
        manager.getContainer().getLogger().debug
            ("readObject() loading session " + id);

    // Deserialize the attribute count and attribute values
    if (attributes == null)
        attributes = new ConcurrentHashMap<String, Object>();
    int n = ((Integer) stream.readObject()).intValue();
    boolean isValidSave = isValid;
    isValid = true;
    for (int i = 0; i < n; i++) {
        String name = (String) stream.readObject();
        final Object value;
        try {
            value = stream.readObject();
        } catch (WriteAbortedException wae) {
            if (wae.getCause() instanceof NotSerializableException) {
                String msg = sm.getString("standardSession.notDeserializable", name, id);
                if (manager.getContainer().getLogger().isDebugEnabled()) {
                    manager.getContainer().getLogger().debug(msg, wae);
                } else {
                    manager.getContainer().getLogger().warn(msg);
                }
                // Skip non serializable attributes
                continue;
            }
            throw wae;
        }
        if (manager.getContainer().getLogger().isDebugEnabled())
            manager.getContainer().getLogger().debug("  loading attribute '" + name +
                "' with value '" + value + "'");
        // Handle the case where the filter configuration was changed while
        // the web application was stopped.
        if (exclude(name, value)) {
            continue;
        }
        attributes.put(name, value);
    }
    isValid = isValidSave;

    if (listeners == null) {
        listeners = new ArrayList<SessionListener>();
    }

    if (notes == null) {
        notes = new Hashtable<String, Object>();
    }
}
 
Example #25
Source File: DeltaRequest.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public void addSessionListener(SessionListener listener) {
    addAction(TYPE_LISTENER, ACTION_SET, NAME_LISTENER ,listener);
}
 
Example #26
Source File: SingleSignOn.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
protected SessionListener getSessionListener(String ssoId) {
    return new SingleSignOnListener(ssoId);
}
 
Example #27
Source File: DeltaSession.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public void removeSessionListener(SessionListener listener) {
    removeSessionListener(listener, true);
}
 
Example #28
Source File: DeltaSession.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public void addSessionListener(SessionListener listener) {
    addSessionListener(listener, true);
}
 
Example #29
Source File: DeltaRequest.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
public void removeSessionListener(SessionListener listener) {
    addAction(TYPE_LISTENER, ACTION_REMOVE, NAME_LISTENER ,listener);
}
 
Example #30
Source File: SingleSignOn.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected SessionListener getSessionListener(String ssoId) {
    return new SingleSignOnListener(ssoId);
}