Search in sources :

Example 1 with BaseToken

use of com.emc.storageos.db.client.model.BaseToken in project coprhd-controller by CoprHD.

the class CassandraTokenValidator method foreignTokenCacheLookup.

/**
 * Looks in the cache for token/user record. Returns null if not found or found but cache expired
 *
 * @param tw
 * @return user record
 */
private StorageOSUserDAO foreignTokenCacheLookup(TokenOnWire tw) {
    BaseToken bToken = fetchTokenLocal(tw);
    if (bToken == null || !Token.class.isInstance(bToken)) {
        _log.info("Token: no hit from cache");
        return null;
    }
    Token token = (Token) bToken;
    Long expirationTime = token.getCacheExpirationTime();
    if (expirationTime != null && expirationTime > getCurrentTimeInMins()) {
        StorageOSUserDAO user = resolveUser(token);
        _log.info("Got user from cached token: {}", user != null ? user.getUserName() : "no hit from cache");
        return user;
    }
    _log.info("Cache expired for foreign token {}", token.getId());
    return null;
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) BaseToken(com.emc.storageos.db.client.model.BaseToken) ProxyToken(com.emc.storageos.db.client.model.ProxyToken) Token(com.emc.storageos.db.client.model.Token) BaseToken(com.emc.storageos.db.client.model.BaseToken)

Example 2 with BaseToken

use of com.emc.storageos.db.client.model.BaseToken in project coprhd-controller by CoprHD.

the class CassandraTokenValidator method fetchTokenLocal.

/**
 * Retrieves a token and checks expiration
 *
 * @param tw
 * @return
 */
private BaseToken fetchTokenLocal(TokenOnWire tw) {
    BaseToken verificationToken = null;
    URI tkId = tw.getTokenId();
    if (!tw.isProxyToken()) {
        verificationToken = _dbClient.queryObject(Token.class, tkId);
        if (null != verificationToken && !checkExpiration(((Token) verificationToken), true)) {
            _log.warn("Token found in database but is expired: {}", verificationToken.getId());
            return null;
        }
    } else {
        verificationToken = _dbClient.queryObject(ProxyToken.class, tkId);
        if (null != verificationToken && !checkExpiration((ProxyToken) verificationToken)) {
            _log.warn("ProxyToken found in database but is expired: {}", verificationToken.getId());
            return null;
        }
    }
    if (verificationToken == null) {
        _log.error("Could not find token with id {} for validation", tkId);
    }
    return verificationToken;
}
Also used : ProxyToken(com.emc.storageos.db.client.model.ProxyToken) BaseToken(com.emc.storageos.db.client.model.BaseToken) ProxyToken(com.emc.storageos.db.client.model.ProxyToken) Token(com.emc.storageos.db.client.model.Token) BaseToken(com.emc.storageos.db.client.model.BaseToken) URI(java.net.URI)

Aggregations

BaseToken (com.emc.storageos.db.client.model.BaseToken)2 ProxyToken (com.emc.storageos.db.client.model.ProxyToken)2 Token (com.emc.storageos.db.client.model.Token)2 StorageOSUserDAO (com.emc.storageos.db.client.model.StorageOSUserDAO)1 URI (java.net.URI)1