/* (non-Javadoc) * @see net.jradius.handler.EventHandler#handle(net.jradius.server.JRadiusEvent) */ public boolean handle(JRadiusEvent evt) throws Exception { if (evt instanceof SessionExpiredEvent) { SessionExpiredEvent event = (SessionExpiredEvent) evt; JRadiusSession session = event.getSession(); if (session == null) return true; RadiusLog.debug("Processing Session Expired Event for Session: " + session.getSessionKey()); if (session.getSessionState() == JRadiusSession.RADIUS_ERROR) { onRadiusError(event); } else if ((session.getSessionState() & JRadiusSession.ACCT_STOPPED) != 0) { onAcctStopped(event); } else if ((session.getSessionState() & JRadiusSession.ACCT_STARTED) != 0) { onAcctStarted(event); } else if ((session.getSessionState() & JRadiusSession.AUTH_REJECTED) != 0) { onAuthRejected(event); } else if ((session.getSessionState() & JRadiusSession.AUTH_ACCEPTED) != 0) { Long serviceType = session.getServiceType(); if (serviceType != null) { int iServiceType = serviceType.intValue(); if (iServiceType != 6 && // Administrative-User iServiceType != 8) // Authenticate-Only { onAuthAccepted(event); } } } else if ((session.getSessionState() & JRadiusSession.AUTH_REJECTED) != 0) { onAuthPending(event); } return true; } return false; }
/** * Listen for one object and place it on the request queue * * @throws IOException * @throws InterruptedException * @throws RadiusException */ public void listen() throws Exception { RadiusLog.debug("Listening on socket..."); Socket socket = serverSocket.accept(); socket.setTcpNoDelay(false); if (keepAlive) { KeepAliveListener keepAliveListener = new KeepAliveListener(socket, this, queue); keepAliveListener.start(); synchronized (keepAliveListeners) { keepAliveListeners.add(keepAliveListener); } } else { TCPListenerRequest lr = (TCPListenerRequest) requestObjectPool.borrowObject(); lr.setBorrowedFromPool(requestObjectPool); lr.accept(socket, this, false, false); while (true) { try { this.queue.put(lr); break; } catch (InterruptedException e) { } } } }
public void notifyElementExpired(Ehcache cache, Element element) { JRadiusSession session = (JRadiusSession) element.getValue(); RadiusLog.debug("Expired session: " + session.getSessionKey()); if (JRadiusServer.getEventDispatcher() != null) { SessionExpiredEvent evt = new SessionExpiredEvent(session); evt.setApplicationContext(applicationContext); JRadiusServer.getEventDispatcher().post(evt); } }
private synchronized void release(JRadiusSession session) { String thisThread = Thread.currentThread().getName(); String sessionToUnlock = session.getSessionKey(); String sessionOwner = (String) locks.get(sessionToUnlock); if (sessionOwner != null) { if (sessionOwner.equals(thisThread)) { locks.remove(sessionToUnlock); RadiusLog.debug("Release: Thread " + thisThread + " unlocking session " + sessionToUnlock); } else { RadiusLog.error( "Releasing session lock not owned by this thread (owner=" + sessionOwner + ",this=" + thisThread + ")"); } } notifyAll(); }
private synchronized void lock(JRadiusSession session) { String thisThread = Thread.currentThread().getName(); String sessionToLock = session.getSessionKey(); String sessionOwner = null; while (true) { sessionOwner = (String) locks.get(sessionToLock); if (sessionOwner == null) { locks.put(sessionToLock, thisThread); RadiusLog.debug("Lock: Thread " + thisThread + " locked session " + sessionToLock); break; } else if (sessionOwner.equals(thisThread)) { break; } else { try { wait(); } catch (InterruptedException ex) { } } } }
/** The thread's run method repeatedly calls listen() */ public void run() { while (getActive()) { try { Thread.yield(); listen(); } catch (SocketException e) { if (getActive() == false) { break; } else { RadiusLog.error("Socket exception", e); } } catch (InterruptedException e) { } catch (SSLException e) { RadiusLog.error("Error occured in TCPListener.", e); active = false; } catch (Throwable e) { RadiusLog.error("Error occured in TCPListener.", e); } } RadiusLog.debug("Listener: " + this.getClass().getName() + " exiting (not active)"); }
private void put(Serializable key, Serializable value) { RadiusLog.debug("Adding session key: " + key); sessionCache.put(new Element(key, value)); }
private void remove(Serializable key) { RadiusLog.debug("Removing session key: " + key); sessionCache.remove(key); }
/** * Returns a session object. First, a key is generated by the session manager's key provider, * based on the JRadiusRequest. If there is a stored session based on the key, this session is * returned, otherwise a new session created by the session factory is returned * * @param request a JRadiusRequest used to retrieve or generate a session with * @return Returns a RadiusSession * @throws RadiusException */ public JRadiusSession getSession(JRadiusRequest request) throws RadiusException { SessionKeyProvider skp = getSessionKeyProvider(request.getSender()); Serializable key = skp.getAppSessionKey(request); JRadiusSession session = null; Serializable nkey = null; if (key != null) { RadiusLog.debug("** Looking for session: " + key); session = getSession(request, key); if (session == null) { RadiusLog.error("Broken JRadius-Session-Id implementation for session: " + key); key = null; } } if (key == null) { key = skp.getClassKey(request); if (key != null) { RadiusLog.debug("** Looking for session: " + key); session = getSession(request, key); if (session == null) { RadiusLog.error("Broken Class implementation for session: " + key); key = null; } else { if (session.getJRadiusKey() != null && !session.getJRadiusKey().equals(session.getSessionKey())) { rehashSession(session, session.getJRadiusKey(), key); } } } } if (key == null) { Serializable keys = skp.getRequestSessionKey(request); if (keys == null) { return null; } if (keys instanceof Serializable[]) { key = ((Serializable[]) (keys))[0]; nkey = ((Serializable[]) (keys))[1]; RadiusLog.debug("Rehashing session with key " + key + " under new key " + nkey); } else { key = keys; } RadiusLog.debug("** Looking for session: " + key); session = getSession(request, key); if (session != null && nkey != null && !nkey.equals(key)) { rehashSession(session, key, nkey); } } if (session == null) { session = newSession(request, nkey == null ? key : nkey); } else { session.setNewSession(false); } session.setTimeStamp(System.currentTimeMillis()); session.setLastRadiusRequest(request); return session; }
public void onAuthRejected(SessionExpiredEvent event) { RadiusLog.debug("Rejected Session Expired: " + event); }
public void onAcctStopped(SessionExpiredEvent event) { RadiusLog.debug("Completed Session Expired: " + event); }