@Test public void shouldAssignAttributeFromSessionLatestAccessTime() { long timestamp = 12345l; InternalSession mockSession = mock(InternalSession.class); SessionID mockSessionID = mock(SessionID.class); given(mockSessionID.toString()).willReturn("badger"); given(jsonSerialisation.deserialise(anyString(), any(Class.class))).willReturn(mockSession); given(mockSession.getExpirationTime()).willReturn(timestamp); given(mockSession.getID()).willReturn(mockSessionID); given(tokenIdFactory.toSessionTokenId(eq(mockSession))).willReturn("badger"); given(jsonSerialisation.serialise(any())).willReturn(""); adapter.toToken(mockSession); verify(ldapDataConversion).fromEpochedSeconds(eq(timestamp)); }
public Token toToken(InternalSession session) { String tokenId = tokenIdFactory.toSessionTokenId(session); Token token = new Token(tokenId, TokenType.SESSION); String userId = config.getUserId(session); token.setUserId(userId); long epochedTimeInSeconds = session.getExpirationTime() + config.getSessionExpiryGracePeriod(); Calendar expiryTimeStamp = dataConversion.fromEpochedSeconds(epochedTimeInSeconds); token.setExpiryTimestamp(expiryTimeStamp); token.setAttribute(SessionTokenField.SESSION_ID.getField(), session.getID().toString()); String jsonBlob = serialisation.serialise(session); blobUtils.setBlobFromString(token, jsonBlob); String latestAccessTime = filterLatestAccessTime(token); if (latestAccessTime != null) { token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); } return token; }
SessionAdapter implements TokenAdapter<InternalSession> { public Token toToken(InternalSession session) { String tokenId = tokenIdFactory.toSessionTokenId(session); Token token = new Token(tokenId, TokenType.SESSION); String userId = config.getUserId(session); token.setUserId(userId); long epochedTimeInSeconds = session.getExpirationTime() + config.getSessionExpiryGracePeriod(); Calendar expiryTimeStamp = dataConversion.fromEpochedSeconds(epochedTimeInSeconds); token.setExpiryTimestamp(expiryTimeStamp); token.setAttribute(SessionTokenField.SESSION_ID.getField(), session.getID().toString()); String jsonBlob = serialisation.serialise(session); blobUtils.setBlobFromString(token, jsonBlob); String latestAccessTime = filterLatestAccessTime(token); if (latestAccessTime != null) { token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); } return token; } }
SessionAdapter implements TokenAdapter<InternalSession> { public Token toToken(InternalSession session) { String tokenId = tokenIdFactory.toSessionTokenId(session); Token token = new Token(tokenId, TokenType.SESSION); String userId = config.getUserId(session); token.setUserId(userId); long epochedTimeInSeconds = session.getExpirationTime() + config.getSessionExpiryGracePeriod(); Calendar expiryTimeStamp = dataConversion.fromEpochedSeconds(epochedTimeInSeconds); token.setExpiryTimestamp(expiryTimeStamp); token.setAttribute(SessionTokenField.SESSION_ID.getField(), session.getID().toString()); String jsonBlob = serialisation.serialise(session); blobUtils.setBlobFromString(token, jsonBlob); String latestAccessTime = filterLatestAccessTime(token); if (latestAccessTime != null) { token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); } return token; } @Inject  SessionAdapter(TokenIdFactory tokenIdFactory, CoreTokenConfig config,
                          JSONSerialisation serialisation, LDAPDataConversion dataConversion,
                          TokenBlobUtils blobUtils); }
SessionAdapter implements TokenAdapter<InternalSession> { public Token toToken(InternalSession session) { String tokenId = tokenIdFactory.toSessionTokenId(session); Token token = new Token(tokenId, TokenType.SESSION); String userId = config.getUserId(session); token.setUserId(userId); long epochedTimeInSeconds = session.getExpirationTime() + config.getSessionExpiryGracePeriod(); Calendar expiryTimeStamp = dataConversion.fromEpochedSeconds(epochedTimeInSeconds); token.setExpiryTimestamp(expiryTimeStamp); token.setAttribute(SessionTokenField.SESSION_ID.getField(), session.getID().toString()); String jsonBlob = serialisation.serialise(session); blobUtils.setBlobFromString(token, jsonBlob); String latestAccessTime = filterLatestAccessTime(token); if (latestAccessTime != null) { token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); } return token; } @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 Token toToken(InternalSession session) { String tokenId = tokenIdFactory.toSessionTokenId(session); Token token = new Token(tokenId, TokenType.SESSION); String userId = config.getUserId(session); token.setUserId(userId); long epochedTimeInSeconds = session.getExpirationTime() + config.getSessionExpiryGracePeriod(); Calendar expiryTimeStamp = dataConversion.fromEpochedSeconds(epochedTimeInSeconds); token.setExpiryTimestamp(expiryTimeStamp); token.setAttribute(SessionTokenField.SESSION_ID.getField(), session.getID().toString()); String jsonBlob = serialisation.serialise(session); blobUtils.setBlobFromString(token, jsonBlob); String latestAccessTime = filterLatestAccessTime(token); if (latestAccessTime != null) { token.setAttribute(SessionTokenField.LATEST_ACCESS_TIME.getField(), latestAccessTime); } return token; } @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);  }