Search in sources :

Example 16 with Token

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

the class CassandraTokenManager method deleteToken.

/**
 * Remove token from database if valid.
 */
@Override
public void deleteToken(String tokenIn) {
    try {
        if (tokenIn == null) {
            _log.error("Null token passed for deletion");
            return;
        }
        URI tkId = _tokenEncoder.decode(tokenIn).getTokenId();
        Token verificationToken = _dbClient.queryObject(Token.class, tkId);
        if (verificationToken == null) {
            _log.error("Could not fetch token from the database: {}", tkId);
            return;
        }
        deleteTokenInternal(verificationToken);
    } catch (DatabaseException ex) {
        throw SecurityException.fatals.databseExceptionDuringTokenDeletion(tokenIn, ex);
    } catch (SecurityException e) {
        _log.error("Token decoding exception during deleteToken.", e);
    }
}
Also used : ProxyToken(com.emc.storageos.db.client.model.ProxyToken) Token(com.emc.storageos.db.client.model.Token) SecurityException(com.emc.storageos.security.exceptions.SecurityException) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 17 with Token

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

the class CassandraTokenManager method deleteAllTokensForUser.

/**
 * Delete all tokens belonging to the user and mark all the user records for this user for deletion.
 */
@Override
public void deleteAllTokensForUser(String userName, boolean includeProxyTokens) {
    try {
        List<StorageOSUserDAO> userRecords = getUserRecords(userName.toLowerCase());
        for (StorageOSUserDAO userRecord : userRecords) {
            List<Token> tokensToDelete = getTokensForUserId(userRecord.getId());
            for (Token token : tokensToDelete) {
                _log.info("Removing token {} using userDAO {} for username {}", new String[] { token.getId().toString(), userRecord.getId().toString(), userName });
                _dbClient.removeObject(token);
                cleanUpRequestedTokenMap(token);
            }
            // making proxy token deletion optional
            List<ProxyToken> pTokensToDelete = getProxyTokensForUserId(userRecord.getId());
            if (includeProxyTokens) {
                for (ProxyToken token : pTokensToDelete) {
                    _log.info("Removing proxy token {} using userDAO {} for username {}", new String[] { token.getId().toString(), userRecord.getId().toString(), userName });
                    _dbClient.removeObject(token);
                }
                _log.info("Marking for deletion: user record {} for username {}", userRecord.getId().toString(), userName);
                _dbClient.markForDeletion(userRecord);
            } else if (pTokensToDelete.isEmpty()) {
                _log.info("No proxy tokens found. Marking for deletion: user record {} for username {}", userRecord.getId().toString(), userName);
                _dbClient.markForDeletion(userRecord);
            }
        }
    } catch (DatabaseException ex) {
        throw SecurityException.fatals.exceptionDuringTokenDeletionForUser(userName, ex);
    }
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) ProxyToken(com.emc.storageos.db.client.model.ProxyToken) ProxyToken(com.emc.storageos.db.client.model.ProxyToken) Token(com.emc.storageos.db.client.model.Token) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 18 with Token

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

the class CassandraTokenManager method createNewToken.

/**
 * create a new token with the user info
 *
 * @param user
 * @return
 */
private Token createNewToken(StorageOSUserDAO user) {
    Token token = new Token();
    token.setId(URIUtil.createId(Token.class));
    // relative index, Id of the userDAO record
    token.setUserId(user.getId());
    long timeNow = getCurrentTimeInMins();
    token.setIssuedTime(timeNow);
    token.setLastAccessTime(timeNow);
    token.setExpirationTime(timeNow + (_maxLifeValuesHolder.getMaxTokenLifeTimeInMins()));
    token.setIndexed(true);
    _dbClient.persistObject(token);
    return token;
}
Also used : ProxyToken(com.emc.storageos.db.client.model.ProxyToken) Token(com.emc.storageos.db.client.model.Token)

Aggregations

Token (com.emc.storageos.db.client.model.Token)18 StorageOSUserDAO (com.emc.storageos.db.client.model.StorageOSUserDAO)15 ProxyToken (com.emc.storageos.db.client.model.ProxyToken)14 BaseToken (com.emc.storageos.db.client.model.BaseToken)10 SignedToken (com.emc.storageos.security.authentication.Base64TokenEncoder.SignedToken)7 URI (java.net.URI)7 Test (org.junit.Test)7 TokenOnWire (com.emc.storageos.security.authentication.TokenOnWire)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 TokenKeysBundle (com.emc.storageos.security.authentication.TokenKeyGenerator.TokenKeysBundle)4 CassandraTokenManager (com.emc.storageos.auth.impl.CassandraTokenManager)3 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)3 Base64TokenEncoder (com.emc.storageos.security.authentication.Base64TokenEncoder)3 TokenKeyGenerator (com.emc.storageos.security.authentication.TokenKeyGenerator)3 TokenMaxLifeValuesHolder (com.emc.storageos.security.authentication.TokenMaxLifeValuesHolder)3 SecurityException (com.emc.storageos.security.exceptions.SecurityException)3 DbClient (com.emc.storageos.db.client.DbClient)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 StringSet (com.emc.storageos.db.client.model.StringSet)2