All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.higgs.http.server.auth.DefaultHiggsSessionDAO Maven / Gradle / Ivy

There is a newer version: 0.0.24
Show newest version
package io.higgs.http.server.auth;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.UnknownSessionException;
import org.apache.shiro.session.mgt.eis.MemorySessionDAO;
import org.apache.shiro.session.mgt.eis.SessionDAO;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Courtney Robinson 
 */
public class DefaultHiggsSessionDAO extends MemorySessionDAO implements SessionDAO {
    protected Map sessions = new HashMap<>();

    public DefaultHiggsSessionDAO(String sessionDirName) {
    }

    @Override
    public Serializable create(Session session) {
        createOrUpdateSession(session);
        return session.getId();
    }

    private boolean createOrUpdateSession(Session session) {
        sessions.put(session.getId(), session);
        return false;
    }

    @Override
    public Session readSession(Serializable sessionId) throws UnknownSessionException {
        Session session = sessions.get(sessionId);
        if (session == null || session.getId() == null || session.getId().toString().isEmpty()) {
            throw new UnknownSessionException();
        }
        return session;
    }

    @Override
    public void update(Session session) throws UnknownSessionException {
        createOrUpdateSession(session);
    }

    @Override
    public void delete(Session session) {
        sessions.remove(session.getId());
    }

    @Override
    public Collection getActiveSessions() {
        return sessions.values();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy