@Test public void shouldRestoreLatestAccessTimeFromAttribute() { String latestAccessTime = "12345"; Token token = new Token("badger", TokenType.SESSION); token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); token.setBlob("{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true,\"maxCachingTime\":3}".getBytes()); JSONSerialisation serialisation = new JSONSerialisation(); adapter = new SessionAdapter(tokenIdFactory, coreTokenConfig, serialisation, ldapDataConversion, blobUtils); InternalSession session = adapter.fromToken(token); long epochedSeconds = System.currentTimeMillis() / 1000; long idleTime = session.getIdleTime(); assertTrue(idleTime < epochedSeconds); }
public InternalSession fromToken(Token token) { String jsonBlob = blobUtils.getBlobAsString(token); int index = findIndexOfValidField(jsonBlob); String latestAccessTime = token.getValue(SessionTokenField.LATEST_ACCESS_TIME.getField()); if (latestAccessTime != null && index != -1) { String fieldName = SessionTokenField.LATEST_ACCESS_TIME.getInternalSessionFieldName(); String jsonField = JSONSerialisation.jsonAttributeName(fieldName); String addition = jsonField + latestAccessTime + ","; jsonBlob = jsonBlob.substring(0, index) + addition + jsonBlob.substring(index, jsonBlob.length()); } return serialisation.deserialise(jsonBlob, InternalSession.class); }
SessionAdapter implements TokenAdapter<InternalSession> { public InternalSession fromToken(Token token) { String jsonBlob = blobUtils.getBlobAsString(token); int index = findIndexOfValidField(jsonBlob); String latestAccessTime = token.getValue(SessionTokenField.LATEST_ACCESS_TIME.getField()); if (latestAccessTime != null && index != -1) { String fieldName = SessionTokenField.LATEST_ACCESS_TIME.getInternalSessionFieldName(); String jsonField = JSONSerialisation.jsonAttributeName(fieldName); String addition = jsonField + latestAccessTime + ","; jsonBlob = jsonBlob.substring(0, index) + addition + jsonBlob.substring(index, jsonBlob.length()); } return serialisation.deserialise(jsonBlob, InternalSession.class); } }
SessionAdapter implements TokenAdapter<InternalSession> { public InternalSession fromToken(Token token) { String jsonBlob = blobUtils.getBlobAsString(token); int index = findIndexOfValidField(jsonBlob); String latestAccessTime = token.getValue(SessionTokenField.LATEST_ACCESS_TIME.getField()); if (latestAccessTime != null && index != -1) { String fieldName = SessionTokenField.LATEST_ACCESS_TIME.getInternalSessionFieldName(); String jsonField = JSONSerialisation.jsonAttributeName(fieldName); String addition = jsonField + latestAccessTime + ","; jsonBlob = jsonBlob.substring(0, index) + addition + jsonBlob.substring(index, jsonBlob.length()); } return serialisation.deserialise(jsonBlob, InternalSession.class); } @Inject  SessionAdapter(TokenIdFactory tokenIdFactory, CoreTokenConfig config,
                          JSONSerialisation serialisation, LDAPDataConversion dataConversion,
                          TokenBlobUtils blobUtils); }
SessionAdapter implements TokenAdapter<InternalSession> { public InternalSession fromToken(Token token) { String jsonBlob = blobUtils.getBlobAsString(token); int index = findIndexOfValidField(jsonBlob); String latestAccessTime = token.getValue(SessionTokenField.LATEST_ACCESS_TIME.getField()); if (latestAccessTime != null && index != -1) { String fieldName = SessionTokenField.LATEST_ACCESS_TIME.getInternalSessionFieldName(); String jsonField = JSONSerialisation.jsonAttributeName(fieldName); String addition = jsonField + latestAccessTime + ","; jsonBlob = jsonBlob.substring(0, index) + addition + jsonBlob.substring(index, jsonBlob.length()); } return serialisation.deserialise(jsonBlob, InternalSession.class); } @Inject  SessionAdapter(TokenIdFactory tokenIdFactory, CoreTokenConfig config,
                          JSONSerialisation serialisation, LDAPDataConversion dataConversion,
                          TokenBlobUtils blobUtils); Token toToken(InternalSession session); InternalSession fromToken(Token token); int findIndexOfValidField(String blob); String filterLatestAccessTime(Token token); }
SessionAdapter implements TokenAdapter<InternalSession> { public InternalSession fromToken(Token token) { String jsonBlob = blobUtils.getBlobAsString(token); int index = findIndexOfValidField(jsonBlob); String latestAccessTime = token.getValue(SessionTokenField.LATEST_ACCESS_TIME.getField()); if (latestAccessTime != null && index != -1) { String fieldName = SessionTokenField.LATEST_ACCESS_TIME.getInternalSessionFieldName(); String jsonField = JSONSerialisation.jsonAttributeName(fieldName); String addition = jsonField + latestAccessTime + ","; jsonBlob = jsonBlob.substring(0, index) + addition + jsonBlob.substring(index, jsonBlob.length()); } return serialisation.deserialise(jsonBlob, InternalSession.class); } @Inject  SessionAdapter(TokenIdFactory tokenIdFactory, CoreTokenConfig config,
                          JSONSerialisation serialisation, LDAPDataConversion dataConversion,
                          TokenBlobUtils blobUtils); Token toToken(InternalSession session); InternalSession fromToken(Token token); int findIndexOfValidField(String blob); String filterLatestAccessTime(Token token);  }