Search in sources :

Example 1 with TokenResponse

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;
}
Also used : SecretKey(javax.crypto.SecretKey) TokenResponse(com.emc.storageos.geomodel.TokenResponse) TokenKeysBundle(com.emc.storageos.security.authentication.TokenKeyGenerator.TokenKeysBundle) TokenResponseArtifacts(com.emc.storageos.security.geo.TokenResponseBuilder.TokenResponseArtifacts) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SecurityException(com.emc.storageos.security.exceptions.SecurityException)

Example 2 with TokenResponse

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;
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) TokenResponse(com.emc.storageos.geomodel.TokenResponse) TokenResponseArtifacts(com.emc.storageos.security.geo.TokenResponseBuilder.TokenResponseArtifacts) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Aggregations

TokenResponse (com.emc.storageos.geomodel.TokenResponse)2 TokenResponseArtifacts (com.emc.storageos.security.geo.TokenResponseBuilder.TokenResponseArtifacts)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 StorageOSUserDAO (com.emc.storageos.db.client.model.StorageOSUserDAO)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 TokenKeysBundle (com.emc.storageos.security.authentication.TokenKeyGenerator.TokenKeysBundle)1 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 SecretKey (javax.crypto.SecretKey)1