use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class SignatureKeyGenerator method getSignatureKey2.
/**
* getSignatureKey2 (keeping the original getSignature() as deprecated because portal uses this method from
* our jar still).
*
* @param relKeyLocation "leaf" node under \getSignatureKeyConfig()\getSignatureKeyId()\
* @param algo algorithm to use for that key
* @return the key
* @throws Exception
*/
protected synchronized SecretKey getSignatureKey2(String relKeyLocation, String algo) throws Exception {
Configuration config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
if (config != null && config.getConfig(relKeyLocation) != null) {
final String encodedKey = config.getConfig(relKeyLocation);
return SignatureHelper.createKey(encodedKey, algo);
} else {
InterProcessLock lock = null;
try {
lock = _coordinator.getLock(getDistributedSignatureKeyLock());
lock.acquire();
config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
ConfigurationImpl cfg = (ConfigurationImpl) config;
if (cfg == null) {
cfg = new ConfigurationImpl();
cfg.setId(getSignatureKeyId());
cfg.setKind(getSignatureKeyConfig());
}
String keyEncoded = SignatureHelper.generateKey(algo);
cfg.setConfig(relKeyLocation, keyEncoded);
_coordinator.persistServiceConfiguration(cfg);
config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
final String encodedKey = config.getConfig(relKeyLocation);
return SignatureHelper.createKey(encodedKey, algo);
} finally {
if (lock != null) {
lock.release();
}
}
}
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class SignatureKeyGenerator method getSignatureKey.
/**
* TODO: DELETE in phase 2 when UI has switched to LoginSignatureKeyGenerator api.
* Used by the UI to get a key.
*
* @param algo
* @return
* @throws Exception
*/
@Deprecated
public synchronized SecretKey getSignatureKey(String algo) throws Exception {
Configuration config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
if (config != null && config.getConfig(getSignatureKey()) != null) {
final String encodedKey = config.getConfig(getSignatureKey());
return new SignatureHelper().createKey(encodedKey, algo);
} else {
InterProcessLock lock = null;
try {
lock = _coordinator.getLock(getDistributedSignatureKeyLock());
lock.acquire();
config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
if (config == null || config.getConfig(getSignatureKey()) == null) {
ConfigurationImpl cfg = new ConfigurationImpl();
cfg.setId(getSignatureKeyId());
cfg.setKind(getSignatureKeyConfig());
String keyEncoded = SignatureHelper.generateKey(algo);
cfg.setConfig(getSignatureKey(), keyEncoded);
_coordinator.persistServiceConfiguration(cfg);
}
config = _coordinator.queryConfiguration(getSignatureKeyConfig(), getSignatureKeyId());
final String encodedKey = config.getConfig(getSignatureKey());
return SignatureHelper.createKey(encodedKey, algo);
} finally {
if (lock != null) {
lock.release();
}
}
}
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class TokenKeyGenerator method createOrUpdateBundle.
// Coordinator client interraction for persistence
/**
* Creates or updates a TokenKeysBundle in coordinator.
*
* @param bundleIn: bundle to persist
* MUST BE CALLED BY A CODE OWNING INTERPROCESS LOCK
* @throws Exception
*/
private synchronized void createOrUpdateBundle(TokenKeysBundle bundleIn) throws Exception {
Configuration config = _coordinator.queryConfiguration(SIGNATURE_KEY_CONFIG, SIGNATURE_KEY_ID);
ConfigurationImpl configImpl = null;
if (config == null) {
configImpl = new ConfigurationImpl();
configImpl.setId(SIGNATURE_KEY_ID);
configImpl.setKind(SIGNATURE_KEY_CONFIG);
_log.debug("Creating new config");
} else {
configImpl = (ConfigurationImpl) config;
_log.debug("Updating existing config");
}
configImpl.setConfig(SIGNATURE_KEY, SerializerUtils.serializeAsBase64EncodedString(bundleIn));
_coordinator.persistServiceConfiguration(configImpl);
_log.debug("Updated keys bundle successfully");
return;
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class TokenKeyGenerator method readBundle.
/**
* Reads the TokenKeysBundle from coordinator and deserializes it.
*
* @return the retrieved bundle or null if not found
* @throws Exception
*/
public TokenKeysBundle readBundle() throws Exception {
Configuration config = _coordinator.queryConfiguration(SIGNATURE_KEY_CONFIG, SIGNATURE_KEY_ID);
if (config == null || config.getConfig(SIGNATURE_KEY) == null) {
_log.warn("Token keys bundle not found");
return null;
}
String serializedBundle = config.getConfig(SIGNATURE_KEY);
_log.debug("Read bundle from coordinator: {}", serializedBundle);
return (TokenKeysBundle) SerializerUtils.deserialize(serializedBundle);
}
use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.
the class StubCoordinatorClientImpl method persistServiceConfiguration.
@Override
public void persistServiceConfiguration(Configuration... config) {
for (int i = 0; i < config.length; i++) {
Configuration c = config[i];
_configMap.put(getKey(c.getKind(), c.getId()), c);
}
}
Aggregations