protected void storeAccessTokenToMemory(String accessTokenValue, byte[] accessTokenBytes, String authenticationKey, byte[] authenticationBytes, Date tokenExpiry, String userLogin, @Nullable String refreshTokenValue) { lock.writeLock().lock(); try { accessTokenValueToAccessTokenStore.put(accessTokenValue, accessTokenBytes); authenticationToAccessTokenStore.put(authenticationKey, accessTokenBytes); accessTokenValueToAuthenticationStore.put(accessTokenValue, authenticationBytes); accessTokenValueToAuthenticationKeyStore.put(accessTokenValue, authenticationKey); accessTokenValueToUserLoginStore.put(accessTokenValue, userLogin); if (!Strings.isNullOrEmpty(refreshTokenValue)) { refreshTokenValueToAccessTokenValueStore.put(refreshTokenValue, accessTokenValue); } } finally { lock.writeLock().unlock(); } if (tokenExpiry != null) { TokenExpiry expiry = new TokenExpiry(accessTokenValue, tokenExpiry); this.accessTokensExpiryQueue.put(expiry); } }
protected void storeRefreshTokenToMemory(String refreshTokenValue, byte[] refreshTokenBytes, byte[] authenticationBytes, Date tokenExpiry, String userLogin) { refreshTokenValueToRefreshTokenStore.put(refreshTokenValue, refreshTokenBytes); refreshTokenValueToAuthenticationStore.put(refreshTokenValue, authenticationBytes); refreshTokenValueToUserLoginStore.put(refreshTokenValue, userLogin); if (tokenExpiry != null) { TokenExpiry expiry = new TokenExpiry(refreshTokenValue, tokenExpiry); this.refreshTokensExpiryQueue.put(expiry); } }
@Override public int compareTo(Delayed other) { if (this == other) { return 0; } long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS); return (diff == 0 ? 0 : ((diff < 0) ? -1 : 1)); }
protected void deleteExpiredRefreshTokensInMemory() { TokenExpiry expiry = refreshTokensExpiryQueue.poll(); while (expiry != null) { removeRefreshToken(expiry.getValue()); expiry = refreshTokensExpiryQueue.poll(); } }
protected void deleteExpiredAccessTokensInMemory() { TokenExpiry expiry = accessTokensExpiryQueue.poll(); while (expiry != null) { removeAccessToken(expiry.getValue()); expiry = accessTokensExpiryQueue.poll(); } }