/* * (non-Javadoc) * * @see org.irods.jargon.datautils.datacache.AccountCacheService# * putSerializedEncryptedObjectIntoCache(java.lang.Object, java.lang.String) */ @Override public String putSerializedEncryptedObjectIntoCache( final Object informationObject, final String key) throws JargonException { if (informationObject == null) { throw new IllegalArgumentException("null informationObject"); } if (key == null || key.isEmpty()) { throw new IllegalArgumentException("null key"); } checkContracts(); log.info("putInformationIntoCache()"); // clean up old files? (or in a sep thread?) make an option based on // created date and window log.info("checking on purge of old requests..."); if (getCacheServiceConfiguration().isDoCleanupDuringRequests()) { purgeOldRequests(); } int keyHash = key.hashCode(); log.info("generated hash for key:{}", keyHash); // serialize and encrypt object log.info("serializing object to byte buffer..."); byte[] serializedObject = serializeObjectToByteStream(informationObject, key); log.info("object serialized into:{} bytes", serializedObject.length); log.info("encrypting..."); CacheEncryptor cacheEncryptor = new CacheEncryptor(key); byte[] encrypted = cacheEncryptor.encrypt(serializedObject); log.info("bytes now encrypted for length:{}", encrypted.length); // store in file String irodsFileAbsolutePath = buildIRODSFileAbsolutePath(keyHash, irodsAccount.getUserName()); log.info("storing to file at absolute path: {}", irodsFileAbsolutePath); IRODSFile cacheFile = getIrodsAccessObjectFactory() .getIRODSFileFactory(irodsAccount) .instanceIRODSFile(irodsFileAbsolutePath); createCacheFileAndCacheDir(cacheFile); Stream2StreamAO stream2StreamAO = getIrodsAccessObjectFactory().getStream2StreamAO(irodsAccount); stream2StreamAO.streamBytesToIRODSFile(encrypted, cacheFile); log.info("done..."); return irodsFileAbsolutePath; }
/* * (non-Javadoc) * * @see org.irods.jargon.datautils.datacache.AccountCacheService# * putStringValueIntoCache(java.lang.String, java.lang.String) */ @Override public String putStringValueIntoCache(final String stringToCache, final String key) throws JargonException { if (stringToCache == null) { throw new IllegalArgumentException("null stringToCache"); } if (key == null || key.isEmpty()) { throw new IllegalArgumentException("null key"); } checkContracts(); log.info("putStringValueIntoCache()"); log.info("checking on purge of old requests..."); if (getCacheServiceConfiguration().isDoCleanupDuringRequests()) { purgeOldRequests(); } int keyHash = key.hashCode(); log.info("generated hash for key:{}", keyHash); byte[] stringData = stringToCache.getBytes(); log.info("encrypting..."); CacheEncryptor cacheEncryptor = new CacheEncryptor(key); byte[] encrypted = cacheEncryptor.encrypt(stringData); log.info("bytes now encrypted for length:{}", encrypted.length); // store in file String irodsFileAbsolutePath = buildIRODSFileAbsolutePath(keyHash, irodsAccount.getUserName()); log.info("storing to file at absolute path: {}", irodsFileAbsolutePath); IRODSFile cacheFile = getIrodsAccessObjectFactory() .getIRODSFileFactory(irodsAccount) .instanceIRODSFile(irodsFileAbsolutePath); createCacheFileAndCacheDir(cacheFile); Stream2StreamAO stream2StreamAO = getIrodsAccessObjectFactory().getStream2StreamAO(irodsAccount); stream2StreamAO.streamBytesToIRODSFile(encrypted, cacheFile); log.info("done..."); return irodsFileAbsolutePath; }
/* * (non-Javadoc) * * @see org.irods.jargon.datautils.datacache.AccountCacheService# * retrieveObjectFromCache(java.lang.String, java.lang.String) */ @Override public Object retrieveObjectFromCache(final String userName, final String key) throws JargonException { if (key == null || key.isEmpty()) { throw new IllegalArgumentException("null key"); } if (userName == null || userName.isEmpty()) { throw new IllegalArgumentException("null userName"); } log.info("retrieveObjectFromCache() user name:{}", userName); log.info("key", key); checkContracts(); if (getCacheServiceConfiguration().isDoCleanupDuringRequests()) { purgeOldRequests(); } // build hash of key and look for file int keyHash = key.hashCode(); log.info("generated hash for key:{}", keyHash); String irodsFileAbsolutePath = buildIRODSFileAbsolutePath(keyHash, irodsAccount.getUserName()); log.info("looking for cache file at path:{}", irodsFileAbsolutePath); IRODSFile cacheFile = getIrodsAccessObjectFactory() .getIRODSFileFactory(irodsAccount) .instanceIRODSFile(irodsFileAbsolutePath); Stream2StreamAO stream2StreamAO = getIrodsAccessObjectFactory().getStream2StreamAO(irodsAccount); byte[] fileBytes = stream2StreamAO.streamFileToByte(cacheFile); log.info("decrypting data based on provided key...."); CacheEncryptor cacheEncryptor = new CacheEncryptor(key); fileBytes = cacheEncryptor.decrypt(fileBytes); log.info("streamed file into bytes for length of: {}", fileBytes.length); log.info("deserialzing..."); return deserializeStreamToObject(fileBytes, key); }