Search in sources :

Example 1 with USER_ID

use of org.sagebionetworks.bridge.AuthEvaluatorField.USER_ID in project BridgeServer2 by Sage-Bionetworks.

the class AccountService method getAccount.

/**
 * Get an account in the context of a app by the user's ID, email address, health code,
 * or phone number. Returns null if the account cannot be found, or the caller does not have
 * the correct permissions to access the account. The account’s enrollments will be filtered
 * so the caller can only see the enrollments in studies they have access to.
 */
public Optional<Account> getAccount(AccountId accountId) {
    checkNotNull(accountId);
    Optional<Account> optional = accountDao.getAccount(accountId);
    if (!optional.isPresent()) {
        return optional;
    }
    if (!canAccessAccount(optional.get())) {
        return Optional.empty();
    }
    Account account = optional.get();
    if (CAN_READ_PARTICIPANTS.check(USER_ID, account.getId(), ORG_ID, account.getOrgMembership())) {
        return optional;
    }
    // This was accessed through study rights, so remove the other studies from what the caller
    // can see.
    RequestContext context = RequestContext.get();
    Set<String> callerStudies = context.getOrgSponsoredStudies();
    Set<Enrollment> removals = account.getEnrollments().stream().filter(en -> !callerStudies.contains(en.getStudyId())).collect(toSet());
    account.getEnrollments().removeAll(removals);
    return optional;
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) BridgeUtils.collectStudyIds(org.sagebionetworks.bridge.BridgeUtils.collectStudyIds) RequestContext(org.sagebionetworks.bridge.RequestContext) MIGRATION_VERSION(org.sagebionetworks.bridge.dao.AccountDao.MIGRATION_VERSION) AuthUtils.canAccessAccount(org.sagebionetworks.bridge.AuthUtils.canAccessAccount) StringUtils(org.apache.commons.lang3.StringUtils) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) AccountDao(org.sagebionetworks.bridge.dao.AccountDao) CANNOT_ACCESS_PARTICIPANTS(org.sagebionetworks.bridge.AuthUtils.CANNOT_ACCESS_PARTICIPANTS) Collectors.toSet(java.util.stream.Collectors.toSet) CAN_READ_PARTICIPANTS(org.sagebionetworks.bridge.AuthUtils.CAN_READ_PARTICIPANTS) AccountSummary(org.sagebionetworks.bridge.models.accounts.AccountSummary) ORG_ID(org.sagebionetworks.bridge.AuthEvaluatorField.ORG_ID) Set(java.util.Set) REAUTH(org.sagebionetworks.bridge.models.accounts.AccountSecretType.REAUTH) Sets(com.google.common.collect.Sets) Account(org.sagebionetworks.bridge.models.accounts.Account) List(java.util.List) DateUtils(org.sagebionetworks.bridge.time.DateUtils) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PasswordAlgorithm(org.sagebionetworks.bridge.models.accounts.PasswordAlgorithm) Optional(java.util.Optional) BridgeUtils(org.sagebionetworks.bridge.BridgeUtils) InvalidKeyException(java.security.InvalidKeyException) UNVERIFIED(org.sagebionetworks.bridge.models.accounts.AccountStatus.UNVERIFIED) ENROLLMENT(org.sagebionetworks.bridge.models.activities.ActivityEventObjectType.ENROLLMENT) CacheProvider(org.sagebionetworks.bridge.cache.CacheProvider) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) TRUE(java.lang.Boolean.TRUE) AccountSecretDao(org.sagebionetworks.bridge.dao.AccountSecretDao) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) Function(java.util.function.Function) PHONE(org.sagebionetworks.bridge.services.AuthenticationService.ChannelType.PHONE) ExternalIdentifierInfo(org.sagebionetworks.bridge.models.accounts.ExternalIdentifierInfo) AccountSummarySearch(org.sagebionetworks.bridge.models.AccountSummarySearch) USER_ID(org.sagebionetworks.bridge.AuthEvaluatorField.USER_ID) App(org.sagebionetworks.bridge.models.apps.App) AccountDisabledException(org.sagebionetworks.bridge.exceptions.AccountDisabledException) BridgeUtils.addToSet(org.sagebionetworks.bridge.BridgeUtils.addToSet) CacheKey(org.sagebionetworks.bridge.cache.CacheKey) StudyActivityEvent(org.sagebionetworks.bridge.models.activities.StudyActivityEvent) DISABLED(org.sagebionetworks.bridge.models.accounts.AccountStatus.DISABLED) Logger(org.slf4j.Logger) ChannelType(org.sagebionetworks.bridge.services.AuthenticationService.ChannelType) ObjectUtils(org.springframework.util.ObjectUtils) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) DateTime(org.joda.time.DateTime) BridgeServiceException(org.sagebionetworks.bridge.exceptions.BridgeServiceException) UnauthorizedException(org.sagebionetworks.bridge.exceptions.UnauthorizedException) Consumer(java.util.function.Consumer) Component(org.springframework.stereotype.Component) DEFAULT_PASSWORD_ALGORITHM(org.sagebionetworks.bridge.models.accounts.PasswordAlgorithm.DEFAULT_PASSWORD_ALGORITHM) TEST_USER_GROUP(org.sagebionetworks.bridge.BridgeConstants.TEST_USER_GROUP) EMAIL(org.sagebionetworks.bridge.services.AuthenticationService.ChannelType.EMAIL) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) AuthUtils.canAccessAccount(org.sagebionetworks.bridge.AuthUtils.canAccessAccount) Account(org.sagebionetworks.bridge.models.accounts.Account) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) RequestContext(org.sagebionetworks.bridge.RequestContext)

Aggregations

Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Sets (com.google.common.collect.Sets)1 TRUE (java.lang.Boolean.TRUE)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1 ORG_ID (org.sagebionetworks.bridge.AuthEvaluatorField.ORG_ID)1 USER_ID (org.sagebionetworks.bridge.AuthEvaluatorField.USER_ID)1 CANNOT_ACCESS_PARTICIPANTS (org.sagebionetworks.bridge.AuthUtils.CANNOT_ACCESS_PARTICIPANTS)1 CAN_READ_PARTICIPANTS (org.sagebionetworks.bridge.AuthUtils.CAN_READ_PARTICIPANTS)1 AuthUtils.canAccessAccount (org.sagebionetworks.bridge.AuthUtils.canAccessAccount)1