@Override public void close() throws RedisSystemException { delegate.close(); }
private void removeAccessTokenUsingRefreshToken(String refreshToken) { byte[] key = serializeKey(REFRESH_TO_ACCESS + refreshToken); List<Object> results = null; RedisConnection conn = getConnection(); try { conn.openPipeline(); conn.get(key); conn.del(key); results = conn.closePipeline(); } finally { conn.close(); } if (results == null) { return; } byte[] bytes = (byte[]) results.get(0); String accessToken = deserializeString(bytes); if (accessToken != null) { removeAccessToken(accessToken); } }
void closeConnection() { if (connection != null) { logger.trace("Closing connection"); try { connection.close(); } catch (Exception e) { logger.warn("Error closing subscription connection", e); } connection = null; } }
public void removeRefreshToken(String tokenValue) { byte[] refreshKey = serializeKey(REFRESH + tokenValue); byte[] refreshAuthKey = serializeKey(REFRESH_AUTH + tokenValue); byte[] refresh2AccessKey = serializeKey(REFRESH_TO_ACCESS + tokenValue); byte[] access2RefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue); RedisConnection conn = getConnection(); try { conn.openPipeline(); conn.del(refreshKey); conn.del(refreshAuthKey); conn.del(refresh2AccessKey); conn.del(access2RefreshKey); conn.closePipeline(); } finally { conn.close(); } }
private void executeLockFree(Consumer<RedisConnection> callback) { RedisConnection connection = connectionFactory.getConnection(); try { callback.accept(connection); } finally { connection.close(); } }
private <T> T execute(String name, Function<RedisConnection, T> callback) { RedisConnection connection = connectionFactory.getConnection(); try { checkAndPotentiallyWaitUntilUnlocked(name, connection); return callback.apply(connection); } finally { connection.close(); } }
@Override public void afterPropertiesSet() throws Exception { if (this.configure == ConfigureRedisAction.NO_OP) { return; } RedisConnection connection = this.connectionFactory.getConnection(); try { this.configure.configure(connection); } finally { try { connection.close(); } catch (Exception ex) { LogFactory.getLog(getClass()).error("Error closing RedisConnection", ex); } } }
@Override public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) { byte[] key = serializeKey(CLIENT_ID_TO_ACCESS + clientId); List<byte[]> byteList = null; RedisConnection conn = getConnection(); try { byteList = getByteLists(key, conn); } finally { conn.close(); } if (byteList == null || byteList.size() == 0) { return Collections.<OAuth2AccessToken> emptySet(); } List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(byteList.size()); for (byte[] bytes : byteList) { OAuth2AccessToken accessToken = deserializeAccessToken(bytes); accessTokens.add(accessToken); } return Collections.<OAuth2AccessToken> unmodifiableCollection(accessTokens); }
@Override public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) { byte[] approvalKey = serializeKey(UNAME_TO_ACCESS + getApprovalKey(clientId, userName)); List<byte[]> byteList = null; RedisConnection conn = getConnection(); try { byteList = getByteLists(approvalKey, conn); } finally { conn.close(); } if (byteList == null || byteList.size() == 0) { return Collections.<OAuth2AccessToken> emptySet(); } List<OAuth2AccessToken> accessTokens = new ArrayList<OAuth2AccessToken>(byteList.size()); for (byte[] bytes : byteList) { OAuth2AccessToken accessToken = deserializeAccessToken(bytes); accessTokens.add(accessToken); } return Collections.<OAuth2AccessToken> unmodifiableCollection(accessTokens); }
private <T> T withConnection(final RedisAction<T> action) throws IOException { RedisConnection redisConnection = null; try { redisConnection = getRedis(); return action.execute(redisConnection); } finally { if (redisConnection != null) { try { redisConnection.close(); } catch (Exception e) { logger.warn("Error closing connection: " + e.getMessage(), e); } } } }
@Override public OAuth2Authentication readAuthentication(String token) { byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(serializeKey(AUTH + token)); } finally { conn.close(); } OAuth2Authentication auth = deserializeAuthentication(bytes); return auth; }
public OAuth2Authentication readAuthenticationForRefreshToken(String token) { RedisConnection conn = getConnection(); try { byte[] bytes = conn.get(serializeKey(REFRESH_AUTH + token)); OAuth2Authentication auth = deserializeAuthentication(bytes); return auth; } finally { conn.close(); } }
/** * Initialize the message listener by writing requried redis config for {@literal notify-keyspace-events} and * registering the listener within the container. */ public void init() { if (StringUtils.hasText(keyspaceNotificationsConfigParameter)) { RedisConnection connection = listenerContainer.getConnectionFactory().getConnection(); try { Properties config = connection.getConfig("notify-keyspace-events"); if (!StringUtils.hasText(config.getProperty("notify-keyspace-events"))) { connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); } } finally { connection.close(); } } doRegister(listenerContainer); }
private <T> T withConnection(final RedisAction<T> action) throws IOException { RedisConnection redisConnection = null; try { redisConnection = redisConnectionPool.getConnection(); return action.execute(redisConnection); } finally { if (redisConnection != null) { try { redisConnection.close(); } catch (Exception e) { getLogger().warn("Error closing connection: " + e.getMessage(), e); } } } }
@Override public OAuth2AccessToken readAccessToken(String tokenValue) { byte[] key = serializeKey(ACCESS + tokenValue); byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(key); } finally { conn.close(); } OAuth2AccessToken accessToken = deserializeAccessToken(bytes); return accessToken; }
@Override public OAuth2RefreshToken readRefreshToken(String tokenValue) { byte[] key = serializeKey(REFRESH + tokenValue); byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(key); } finally { conn.close(); } OAuth2RefreshToken refreshToken = deserializeRefreshToken(bytes); return refreshToken; }
@Test public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenNoExceptionThenCloseConnection() throws Exception { ConfigureRedisAction action = mock(ConfigureRedisAction.class); EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer( this.factory, action); init.afterPropertiesSet(); verify(this.connection).close(); } }
@Override public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) { String key = authenticationKeyGenerator.extractKey(authentication); byte[] serializedKey = serializeKey(AUTH_TO_ACCESS + key); byte[] bytes = null; RedisConnection conn = getConnection(); try { bytes = conn.get(serializedKey); } finally { conn.close(); } OAuth2AccessToken accessToken = deserializeAccessToken(bytes); if (accessToken != null) { OAuth2Authentication storedAuthentication = readAuthentication(accessToken.getValue()); if ((storedAuthentication == null || !key.equals(authenticationKeyGenerator.extractKey(storedAuthentication)))) { // Keep the stores consistent (maybe the same user is // represented by this authentication but the details have // changed) storeAccessToken(accessToken, authentication); } } return accessToken; }
@Test public void enableRedisKeyspaceNotificationsInitializerAfterPropertiesSetWhenExceptionThenCloseConnection() throws Exception { ConfigureRedisAction action = mock(ConfigureRedisAction.class); willThrow(new RuntimeException()).given(action).configure(this.connection); EnableRedisKeyspaceNotificationsInitializer init = new EnableRedisKeyspaceNotificationsInitializer( this.factory, action); try { init.afterPropertiesSet(); failBecauseExceptionWasNotThrown(Throwable.class); } catch (Throwable success) { } verify(this.connection).close(); }