default String serializeKey() { String userId = getUserId(); String encodedUserId = userId == null ? "" : Base64.encodeBytes(userId.getBytes(StandardCharsets.UTF_8)); return String.format("%s.%d.%s.%s", encodedUserId, getExpiration(), getActionVerificationNonce(), getActionId()); } }
@Override public ActionTokenValueModel remove(ActionTokenKeyModel actionTokenKey) { if (actionTokenKey == null || actionTokenKey.getUserId() == null || actionTokenKey.getActionId() == null) { return null; } ActionTokenReducedKey key = new ActionTokenReducedKey(actionTokenKey.getUserId(), actionTokenKey.getActionId(), actionTokenKey.getActionVerificationNonce()); ActionTokenValueEntity value = this.actionKeyCache.get(key); if (value != null) { this.tx.remove(actionKeyCache, key); } return value; } }
@Override public void put(ActionTokenKeyModel key, Map<String, String> notes) { if (key == null || key.getUserId() == null || key.getActionId() == null) { return; } ActionTokenReducedKey tokenKey = new ActionTokenReducedKey(key.getUserId(), key.getActionId(), key.getActionVerificationNonce()); ActionTokenValueEntity tokenValue = new ActionTokenValueEntity(notes); LOG.debugf("Adding used action token to actionTokens cache: %s", tokenKey.toString()); this.tx.put(actionKeyCache, tokenKey, tokenValue, key.getExpiration() - Time.currentTime(), TimeUnit.SECONDS); }
@Override public ActionTokenValueModel get(ActionTokenKeyModel actionTokenKey) { if (actionTokenKey == null || actionTokenKey.getUserId() == null || actionTokenKey.getActionId() == null) { return null; } ActionTokenReducedKey key = new ActionTokenReducedKey(actionTokenKey.getUserId(), actionTokenKey.getActionId(), actionTokenKey.getActionVerificationNonce()); ActionTokenValueModel value = this.actionKeyCache.getAdvancedCache().get(key); if (value == null) { LOG.debugf("Not found any value in actionTokens cache for key: %s", key.toString()); } else { LOG.debugf("Found value in actionTokens cache for key: %s", key.toString()); } return value; }