use of com.emc.storageos.geomodel.TokenResponse in project coprhd-controller by CoprHD.
the class Base64TokenEncoder method getForeignKey.
/**
* Attempts to get a secret key from the provided tokenonwire.
* First attempts from cache, then makes a call to originator vdc if not
* found in cache.
*
* @param tw
* @param encodedToken
* @return
*/
private SecretKey getForeignKey(TokenOnWire tw, String encodedToken) {
String vdcId = URIUtil.parseVdcIdFromURI(tw.getTokenId());
_log.info("Token received from another VDC: {}. Looking in cache for keys", vdcId);
SecretKey foreignKey = interVDCTokenCacheHelper.getForeignSecretKey(vdcId, tw.getEncryptionKeyId());
if (foreignKey == null) {
TokenKeysBundle bundle = interVDCTokenCacheHelper.getTokenKeysBundle(vdcId);
try {
// check if the requested key id falls within reasonable range
if (bundle != null && !interVDCTokenCacheHelper.sanitizeRequestedKeyIds(bundle, tw.getEncryptionKeyId())) {
return null;
}
TokenResponse response = geoClientCacheMgt.getGeoClient(vdcId).getToken(encodedToken, bundle == null ? "0" : bundle.getKeyEntries().get(0), bundle == null ? "0" : bundle.getKeyEntries().size() == 2 ? bundle.getKeyEntries().get(1) : null);
if (response != null) {
TokenResponseArtifacts artifacts = TokenResponseBuilder.parseTokenResponse(response);
interVDCTokenCacheHelper.cacheForeignTokenAndKeys(artifacts, vdcId);
return interVDCTokenCacheHelper.getForeignSecretKey(vdcId, tw.getEncryptionKeyId());
} else {
_log.error("Null response from getForeignToken call. It's possible remote vdc is not reachable.");
}
} catch (Exception e) {
_log.error("Could not validate foreign token ", e);
}
} else {
_log.info("Key found in cache");
}
return foreignKey;
}
use of com.emc.storageos.geomodel.TokenResponse in project coprhd-controller by CoprHD.
the class CassandraTokenValidator method getForeignToken.
/**
* Queries the remote VDC for token and userdao objects
*
* @param tw TokenOnWire object
* @param rawToken the rawToken to send to the remote vdc
* @return
*/
private StorageOSUserDAO getForeignToken(TokenOnWire tw, String rawToken) {
StorageOSUserDAO userFromCache = this.foreignTokenCacheLookup(tw);
if (userFromCache != null) {
return userFromCache;
}
try {
String shortVDCid = URIUtil.parseVdcIdFromURI(tw.getTokenId());
TokenResponse response = geoClientCacheMgt.getGeoClient(shortVDCid).getToken(rawToken, null, null);
if (response != null) {
TokenResponseArtifacts artifacts = TokenResponseBuilder.parseTokenResponse(response);
_log.info("Got username for foreign token: {}", artifacts.getUser().getUserName());
_log.debug("Got token object: {}", artifacts.getToken().getId().toString());
interVDCTokenCacheHelper.cacheForeignTokenAndKeys(artifacts, shortVDCid);
return artifacts.getUser();
} else {
_log.error("Null response from getForeignToken call. It's possible remote vdc is not reachable.");
}
} catch (Exception e) {
_log.error("Could not validate foreign token ", e);
}
return null;
}
Aggregations