Example usage for org.apache.shiro.session.mgt SimpleSession getHost

List of usage examples for org.apache.shiro.session.mgt SimpleSession getHost

Introduction

In this page you can find the example usage for org.apache.shiro.session.mgt SimpleSession getHost.

Prototype

public String getHost() 

Source Link

Usage

From source file:com.leshazlewood.samples.shiro.cassandra.CassandraSessionDAO.java

License:Apache License

protected void save(SimpleSession ss) {

    //Cassandra TTL values are in seconds, so we need to convert from Shiro's millis:
    int timeoutInSeconds = (int) (ss.getTimeout() / 1000);

    PreparedStatement ps = prepareSaveStatement();
    BoundStatement bs = new BoundStatement(ps);

    byte[] serialized = serializer.serialize(ss);

    ByteBuffer bytes = ByteBuffer.wrap(serialized);

    bs.bind(timeoutInSeconds, ss.getStartTimestamp(),
            ss.getStopTimestamp() != null ? ss.getStartTimestamp() : null, ss.getLastAccessTime(),
            ss.getTimeout(), ss.isExpired(), ss.getHost(), bytes, ss.getId());

    cassandraSession.execute(bs);/*  www  .  j av a 2s .  c o m*/
}

From source file:com.wms.studio.controller.admin.UserAdminManagerController.java

License:Apache License

@RequestMapping("admin/userManager/userOnlineStore")
public void getOnlineUsers(Model model) {
    Iterator<Session> sessions = sessionDao.getActiveSessions().iterator();
    ArrayList<OnlineUser> ous = new ArrayList<OnlineUser>();
    while (sessions.hasNext()) {
        OnlineUser ou = new OnlineUser();
        SimpleSession session = (SimpleSession) sessions.next();
        ou.setHost(session.getHost());
        ou.setId(session.getId().toString());
        ou.setLastAccessTime(session.getLastAccessTime());
        ou.setStartTime(session.getStartTimestamp());
        PrincipalCollection principal = (PrincipalCollection) session
                .getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
        if (principal != null) {
            ShiroUser su = (ShiroUser) principal.getPrimaryPrincipal();
            ou.setUserid(su.loginName);/*from   w ww  .j  ava 2 s.co  m*/
            ou.setUsername(su.name);
            ou.setLogin(true);
        }
        ous.add(ou);
    }
    model.addAttribute("users", ous);
    model.addAttribute("total", ous.size());
}

From source file:org.killbill.billing.util.security.shiro.dao.TestSessionModelDao.java

License:Apache License

@Test(groups = "fast")
public void testRoundTrip() throws Exception {
    final SimpleSession simpleSession = new SimpleSession();
    simpleSession.setStartTimestamp(new Date(System.currentTimeMillis() - 5000));
    simpleSession.setLastAccessTime(new Date(System.currentTimeMillis()));
    simpleSession.setTimeout(493934L);/*from w  w w  .j av a  2s. c o  m*/
    simpleSession.setHost(UUID.randomUUID().toString());
    simpleSession.setAttribute(UUID.randomUUID(), Short.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID(), Integer.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID(), Long.MIN_VALUE);
    simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    // Test with Serializable objects
    simpleSession.setAttribute(UUID.randomUUID().toString(), UUID.randomUUID());
    simpleSession.setAttribute(UUID.randomUUID().toString(), new Date(1242));

    final SessionModelDao sessionModelDao = new SessionModelDao(simpleSession);
    Assert.assertEquals(sessionModelDao.getTimeout(), simpleSession.getTimeout());
    Assert.assertEquals(sessionModelDao.getHost(), simpleSession.getHost());
    Assert.assertTrue(sessionModelDao.getSessionData().length > 0);

    final Session retrievedSession = sessionModelDao.toSimpleSession();
    Assert.assertEquals(retrievedSession, simpleSession);
}