private LoginSession createSession(
     long loggedEntity,
     AuthenticationRealm realm,
     String entityLabel,
     boolean outdatedCredential,
     Date absoluteExpiration,
     Object transaction) {
   UUID randomid = UUID.randomUUID();
   String id = randomid.toString();
   LoginSession ls =
       new LoginSession(
           id,
           new Date(),
           absoluteExpiration,
           realm.getMaxInactivity() * 1000,
           loggedEntity,
           realm.getName());
   ls.setUsedOutdatedCredential(outdatedCredential);
   ls.setEntityLabel(entityLabel);
   try {
     tokensManagement.addToken(
         SESSION_TOKEN_TYPE,
         id,
         new EntityParam(loggedEntity),
         ls.getTokenContents(),
         ls.getStarted(),
         ls.getExpires(),
         transaction);
   } catch (Exception e) {
     throw new InternalException("Can't create a new session", e);
   }
   return ls;
 }