Search in sources :

Example 21 with StorageOSUserDAO

use of com.emc.storageos.db.client.model.StorageOSUserDAO 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 22 with StorageOSUserDAO

use of com.emc.storageos.db.client.model.StorageOSUserDAO 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 23 with StorageOSUserDAO

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

the class CustomAuthenticationManager method refreshUser.

@Override
public void refreshUser(String username) throws SecurityException, BadRequestException {
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, "");
    for (AuthenticationProvider provider : getAuthenticationProviders()) {
        StorageOSAuthenticationHandler authenticationHandler = provider.getHandler();
        if (!authenticationHandler.supports(credentials)) {
            continue;
        }
        List<StorageOSUserDAO> userDAOs = _tokenManager.getUserRecords(username);
        if (CollectionUtils.isEmpty(userDAOs)) {
            _log.error("user " + username + "does not exist in database");
            throw APIException.badRequests.invalidParameter("username", username);
        }
        ValidationFailureReason[] failureReason = new ValidationFailureReason[] { ValidationFailureReason.USER_OR_GROUP_NOT_FOUND_FOR_TENANT };
        StorageOSPersonAttributeDao attributeRepository = provider.getAttributeRepository();
        final StorageOSUserDAO userDAO = attributeRepository.getStorageOSUser(credentials, failureReason);
        // anything...
        if (userDAO == null && failureReason[0] == ValidationFailureReason.LDAP_CONNECTION_FAILED) {
            throw SecurityException.fatals.communicationToLDAPResourceFailed();
        } else if (userDAO == null && failureReason[0] == ValidationFailureReason.LDAP_MANAGER_AUTH_FAILED) {
            throw SecurityException.fatals.ldapManagerAuthenticationFailed();
        } else if (userDAO == null) {
            // we coudln't find the user, which means it's no longer valid, so we need
            // to logout the user
            _tokenManager.deleteAllTokensForUser(username, true);
            throw APIException.badRequests.principalSearchFailed(username);
        }
        // update the user records in the DB
        _tokenManager.updateDBWithUser(userDAO, userDAOs);
        return;
    }
    // we don't have a handler that supports the given credentials
    _log.error("Unsupported credentials {}", username);
    _tokenManager.deleteAllTokensForUser(username, true);
    // failed to refresh
    throw APIException.badRequests.principalSearchFailed(username);
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 24 with StorageOSUserDAO

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

the class CustomAuthenticationManager method authenticate.

@Override
public StorageOSUserDAO authenticate(final Credentials credentials) {
    boolean found = false;
    String handlerName;
    for (AuthenticationProvider provider : getAuthenticationProviders()) {
        StorageOSAuthenticationHandler authenticationHandler = provider.getHandler();
        StorageOSPersonAttributeDao attributeRepository = provider.getAttributeRepository();
        if (!authenticationHandler.supports(credentials)) {
            continue;
        }
        found = true;
        handlerName = authenticationHandler.getClass().getName();
        if (authenticationHandler.authenticate(credentials)) {
            _log.info("{} successfully authenticated {}", handlerName, logFormat(credentials));
            final StorageOSUserDAO user = attributeRepository.getStorageOSUser(credentials);
            _log.info("Authenticated {}.", user);
            _log.debug("Attribute map for {}: {}", user, user.getAttributes());
            return user;
        }
        _log.info("{} failed to authenticate {}", handlerName, logFormat(credentials));
    }
    // failed authn
    if (found) {
        _log.error("Failed to authenticate {}", logFormat(credentials));
        return null;
    }
    // we don't have a handler that supports the credentials given
    _log.error("Unsupported credentials {}", logFormat(credentials));
    return null;
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO)

Example 25 with StorageOSUserDAO

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

the class StorageOSLdapPersonAttributeDao method validateUser.

/*
     * @see com.emc.storageos.auth.StorageOSPersonAttributeDao#validateUser(java.lang.String, java.lang.String)
     */
@Override
public void validateUser(final String userId, final String tenantId, final String altTenantId) {
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials(userId, "");
    StorageOSUserDAO user = getStorageOSUser(creds);
    // the user must not be null and it must have tenant id
    boolean belongsToTenant = user.getTenantId().equals(tenantId);
    boolean belongsToAltTenant = (altTenantId != null) && user.getTenantId().equals(altTenantId);
    if (!(belongsToTenant || belongsToAltTenant)) {
        throw APIException.badRequests.principalSearchFailed(userId);
    }
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Aggregations

StorageOSUserDAO (com.emc.storageos.db.client.model.StorageOSUserDAO)37 Token (com.emc.storageos.db.client.model.Token)15 ProxyToken (com.emc.storageos.db.client.model.ProxyToken)12 Test (org.junit.Test)12 TokenOnWire (com.emc.storageos.security.authentication.TokenOnWire)11 URI (java.net.URI)10 BaseToken (com.emc.storageos.db.client.model.BaseToken)9 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)9 SignedToken (com.emc.storageos.security.authentication.Base64TokenEncoder.SignedToken)8 CassandraTokenManager (com.emc.storageos.auth.impl.CassandraTokenManager)7 Base64TokenEncoder (com.emc.storageos.security.authentication.Base64TokenEncoder)7 TokenKeyGenerator (com.emc.storageos.security.authentication.TokenKeyGenerator)7 TokenMaxLifeValuesHolder (com.emc.storageos.security.authentication.TokenMaxLifeValuesHolder)7 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)6 DbClient (com.emc.storageos.db.client.DbClient)6 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)5 UnauthorizedException (com.emc.storageos.svcs.errorhandling.resources.UnauthorizedException)5 StringSet (com.emc.storageos.db.client.model.StringSet)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4