List of usage examples for org.apache.shiro.session.mgt SimpleSession getAttributes
public Map<Object, Object> getAttributes()
From source file:com.parallax.server.blocklyprop.security.BlocklyPropSessionDao.java
/** * Convert a Session object into a SessionRecord object * * @param session//from w ww. j ava 2 s. c o m * the session to convert into a SessionRecord * * @return * a SessionRecord object containing the details necessary to persist the object * into an EIS. */ private SessionRecord convert(Session session) { LOG.trace("Converting session {} to a SessionRecord object", session.getId()); // Cast the Session parameter into a SimpleSession reference SimpleSession ssession = (SimpleSession) session; SessionRecord sessionRecord = new SessionRecord(); sessionRecord.setIdsession(session.getId().toString()); sessionRecord.setStarttimestamp(new Timestamp(session.getStartTimestamp().getTime())); sessionRecord.setLastaccesstime(new Timestamp(session.getLastAccessTime().getTime())); sessionRecord.setTimeout(session.getTimeout()); sessionRecord.setHost(session.getHost()); // Gather the session attributes into a HashMap that can be persisted into the // SessionRecord object if (ssession.getAttributes() != null) { HashMap<Object, Object> attributes = (HashMap<Object, Object>) ssession.getAttributes(); // Logging attributes // LOG.debug("Session attributes:"); // attributes.forEach( (k,v) -> LOG.debug("Key: {}, Value: {}", k, v)); sessionRecord.setAttributes(SerializationUtils.serialize(attributes)); } return sessionRecord; }
From source file:org.graylog2.security.MongoDbSessionDAO.java
License:Open Source License
@Override protected void doUpdate(Session session) { final MongoDbSession dbSession = mongoDBSessionService.load(session.getId().toString()); if (null == dbSession) { throw new RuntimeException("Couldn't load session <" + session.getId() + ">"); }// w w w . ja v a 2 s . c o m LOG.debug("Updating session {}", session); dbSession.setHost(session.getHost()); dbSession.setTimeout(session.getTimeout()); dbSession.setStartTimestamp(session.getStartTimestamp()); dbSession.setLastAccessTime(session.getLastAccessTime()); if (session instanceof SimpleSession) { final SimpleSession simpleSession = (SimpleSession) session; dbSession.setAttributes(simpleSession.getAttributes()); dbSession.setExpired(simpleSession.isExpired()); } else { throw new RuntimeException("Unsupported session type: " + session.getClass().getCanonicalName()); } mongoDBSessionService.saveWithoutValidation(dbSession); }