Search in sources :

Example 1 with InstitutionTierConfig

use of org.pmiops.workbench.model.InstitutionTierConfig in project workbench by all-of-us.

the class ProfileControllerTest method setUp.

@BeforeEach
@Override
public void setUp() throws IOException {
    super.setUp();
    config.googleDirectoryService.gSuiteDomain = GSUITE_DOMAIN;
    // key UserService logic depends on the existence of the Registered Tier
    registeredTier = TestMockFactory.createRegisteredTierForTests(accessTierDao);
    rtAddressesConfig = new InstitutionTierConfig().membershipRequirement(InstitutionMembershipRequirement.ADDRESSES).eraRequired(false).accessTierShortName(registeredTier.getShortName());
    rtDomainsConfig = new InstitutionTierConfig().membershipRequirement(InstitutionMembershipRequirement.DOMAINS).eraRequired(false).accessTierShortName(registeredTier.getShortName());
    Profile profile = new Profile();
    profile.setContactEmail(CONTACT_EMAIL);
    profile.setFamilyName(FAMILY_NAME);
    profile.setGivenName(GIVEN_NAME);
    profile.setUsername(USER_PREFIX);
    profile.setAreaOfResearch(RESEARCH_PURPOSE);
    profile.setAddress(new Address().streetAddress1(STREET_ADDRESS).city(CITY).state(STATE).country(COUNTRY).zipCode(ZIP_CODE));
    createAccountRequest = new CreateAccountRequest();
    createAccountRequest.setTermsOfServiceVersion(LATEST_AOU_TOS_VERSION);
    createAccountRequest.setProfile(profile);
    createAccountRequest.setCaptchaVerificationToken(CAPTCHA_TOKEN);
    googleUser = new User();
    googleUser.setPrimaryEmail(FULL_USER_NAME);
    googleUser.setChangePasswordAtNextLogin(true);
    googleUser.setPassword("testPassword");
    googleUser.setIsEnrolledIn2Sv(true);
    config.access.currentDuccVersions = ImmutableList.of(CURRENT_DUCC_VERSION);
    when(mockDirectoryService.getUserOrThrow(FULL_USER_NAME)).thenReturn(googleUser);
    when(mockDirectoryService.createUser(GIVEN_NAME, FAMILY_NAME, FULL_USER_NAME, CONTACT_EMAIL)).thenReturn(googleUser);
    when(mockCloudStorageClient.getCaptchaServerKey()).thenReturn("Server_Key");
    try {
        when(mockCaptchaVerificationService.verifyCaptcha(CAPTCHA_TOKEN)).thenReturn(true);
        when(mockCaptchaVerificationService.verifyCaptcha(WRONG_CAPTCHA_TOKEN)).thenReturn(false);
        when(mockFireCloudService.getUserTermsOfServiceStatus()).thenReturn(true);
    } catch (ApiException | org.pmiops.workbench.firecloud.ApiException e) {
        e.printStackTrace();
    }
    accessModules = TestMockFactory.createAccessModules(accessModuleDao);
}
Also used : InstitutionTierConfig(org.pmiops.workbench.model.InstitutionTierConfig) CreateAccountRequest(org.pmiops.workbench.model.CreateAccountRequest) DbUser(org.pmiops.workbench.db.model.DbUser) User(com.google.api.services.directory.model.User) Address(org.pmiops.workbench.model.Address) Profile(org.pmiops.workbench.model.Profile) ApiException(org.pmiops.workbench.captcha.ApiException) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with InstitutionTierConfig

use of org.pmiops.workbench.model.InstitutionTierConfig in project workbench by all-of-us.

the class InstitutionMapperTest method setup.

@BeforeEach
public void setup() {
    sortedModelDomains = Lists.newArrayList("broad.org", "verily.com");
    sortedModelAddresses = Lists.newArrayList("alice@nih.gov", "joel@other-inst.org");
    tierConfigs = Lists.newArrayList(new InstitutionTierConfig().accessTierShortName(TIER_NAME).membershipRequirement(InstitutionMembershipRequirement.DOMAINS).eraRequired(true).emailDomains(sortedModelDomains).emailAddresses(sortedModelAddresses));
}
Also used : InstitutionTierConfig(org.pmiops.workbench.model.InstitutionTierConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with InstitutionTierConfig

use of org.pmiops.workbench.model.InstitutionTierConfig in project workbench by all-of-us.

the class InstitutionTierConfigMapperTest method testDbToModelSuccess.

@Test
public void testDbToModelSuccess() {
    // does not need to match the modelInst; it is simply attached to the
    // DbInstitutionTierRequirement
    final DbInstitution dbInst = new DbInstitution();
    final List<String> emailAddresses = Lists.newArrayList("bar@other-inst.org", "foo@nih.gov");
    final DbInstitutionTierRequirement tierRequirement = new DbInstitutionTierRequirement().setAccessTier(RT_ACCESS_TIER).setInstitution(dbInst).setMembershipRequirement(MembershipRequirement.DOMAINS).setEraRequired(true);
    InstitutionTierConfig expectedTierConfig = new InstitutionTierConfig().accessTierShortName(RT_ACCESS_TIER_SHORT_NAME).membershipRequirement(InstitutionMembershipRequirement.DOMAINS).eraRequired(true).emailAddresses(emailAddresses);
    assertThat(mapper.dbToTierConfigModel(tierRequirement, new TreeSet<>(emailAddresses), null)).isEqualTo(expectedTierConfig);
}
Also used : InstitutionTierConfig(org.pmiops.workbench.model.InstitutionTierConfig) DbInstitution(org.pmiops.workbench.db.model.DbInstitution) DbInstitutionTierRequirement(org.pmiops.workbench.db.model.DbInstitutionTierRequirement) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 4 with InstitutionTierConfig

use of org.pmiops.workbench.model.InstitutionTierConfig in project workbench by all-of-us.

the class UserServiceAccessTest method setUp.

@BeforeEach
public void setUp() {
    providedWorkbenchConfig = WorkbenchConfig.createEmptyConfig();
    providedWorkbenchConfig.access.enableComplianceTraining = true;
    providedWorkbenchConfig.access.enableEraCommons = true;
    providedWorkbenchConfig.access.enforceRasLoginGovLinking = true;
    providedWorkbenchConfig.access.enableRasLoginGovLinking = true;
    // arbitrary
    providedWorkbenchConfig.access.currentDuccVersions = ImmutableList.of(1, 2);
    providedWorkbenchConfig.access.renewal.expiryDays = EXPIRATION_DAYS;
    providedWorkbenchConfig.access.renewal.expiryDaysWarningThresholds = ImmutableList.of(1L, 3L, 7L, 15L, 30L);
    registeredTier = TestMockFactory.createRegisteredTierForTests(accessTierDao);
    controlledTier = TestMockFactory.createControlledTierForTests(accessTierDao);
    accessModules = TestMockFactory.createAccessModules(accessModuleDao);
    dbUser = new DbUser();
    dbUser.setUsername(USERNAME);
    dbUser.setContactEmail("user@domain.com");
    dbUser = userDao.save(dbUser);
    rtTierConfig = new InstitutionTierConfig().accessTierShortName(registeredTier.getShortName());
    ctTierConfig = new InstitutionTierConfig().accessTierShortName(controlledTier.getShortName());
    institution = new Institution().displayName("institution").shortName("shortname").tierConfigs(ImmutableList.of(rtTierConfig.membershipRequirement(InstitutionMembershipRequirement.DOMAINS).addEmailDomainsItem("domain.com").eraRequired(true).accessTierShortName(registeredTier.getShortName()))).organizationTypeEnum(OrganizationType.INDUSTRY).userInstructions("Some user instructions");
    institution = institutionService.createInstitution(institution);
    createAffiliation(dbUser);
    // reset the clock so tests changing this don't affect each other
    PROVIDED_CLOCK.setInstant(START_INSTANT);
    registerUserNow = registerUserWithTime.apply(new Timestamp(PROVIDED_CLOCK.millis()));
}
Also used : InstitutionTierConfig(org.pmiops.workbench.model.InstitutionTierConfig) DbInstitution(org.pmiops.workbench.db.model.DbInstitution) Institution(org.pmiops.workbench.model.Institution) Timestamp(java.sql.Timestamp) DbUser(org.pmiops.workbench.db.model.DbUser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with InstitutionTierConfig

use of org.pmiops.workbench.model.InstitutionTierConfig in project workbench by all-of-us.

the class InstitutionServiceImpl method validateInstitutionalEmail.

@Override
public boolean validateInstitutionalEmail(Institution institution, String contactEmail, String accessTierShortName) {
    try {
        // TODO RW-4489: UserService should handle initial email validation
        new InternetAddress(contactEmail).validate();
    } catch (AddressException e) {
        log.info(String.format("Contact email '%s' validation threw an AddressException: %s", contactEmail, e.getMessage()));
        return false;
    } catch (NullPointerException e) {
        log.info(String.format("Contact email '%s' validation threw a NullPointerException", contactEmail));
        return false;
    }
    Optional<InstitutionTierConfig> tierConfig = getTierConfigByTier(institution, accessTierShortName);
    final boolean validated;
    final String logMsg;
    if (!tierConfig.isPresent()) {
        logMsg = String.format("Cannot validate email because the membership requirement for institution '%s' and " + "tier '%s' not in DB", institution.getShortName(), accessTierShortName);
        validated = false;
    } else {
        switch(tierConfig.get().getMembershipRequirement()) {
            case NO_ACCESS:
                validated = false;
                logMsg = String.format("Cannot validate email because the membership requirement for institution '%s' " + "and tier '%s' is NO_ACCESS", institution.getShortName(), accessTierShortName);
                break;
            case ADDRESSES:
                validated = getEmailAddressesByTierOrEmptySet(institution, accessTierShortName).stream().anyMatch(contactEmail::equalsIgnoreCase);
                logMsg = String.format("Contact email '%s' validated against '%s' tier with ADDRESSES requirement: " + "'%s': address %s", contactEmail, accessTierShortName, institution.getShortName(), validated ? "MATCHED" : "DID NOT MATCH");
                break;
            case DOMAINS:
                final String contactEmailDomain = contactEmail.substring(contactEmail.indexOf("@") + 1);
                validated = getEmailDomainsByTierOrEmptySet(institution, accessTierShortName).stream().anyMatch(contactEmailDomain::equalsIgnoreCase);
                logMsg = String.format("Contact email '%s' validated against '%s' tier with DOMAINS requirement '%s': " + "domain %s %s", contactEmail, accessTierShortName, institution.getShortName(), contactEmailDomain, validated ? "MATCHED" : "DID NOT MATCH");
                break;
            default:
                validated = false;
                logMsg = String.format("Cannot validate email because institution '%s' does not have a membership requirement for tier '%s'", institution.getShortName(), accessTierShortName);
                break;
        }
    }
    if (!validated) {
        log.info(logMsg);
    }
    return validated;
}
Also used : InstitutionTierConfig(org.pmiops.workbench.model.InstitutionTierConfig) InternetAddress(javax.mail.internet.InternetAddress) AddressException(javax.mail.internet.AddressException)

Aggregations

InstitutionTierConfig (org.pmiops.workbench.model.InstitutionTierConfig)9 DbInstitution (org.pmiops.workbench.db.model.DbInstitution)6 Test (org.junit.jupiter.api.Test)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 TreeSet (java.util.TreeSet)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 DbInstitutionTierRequirement (org.pmiops.workbench.db.model.DbInstitutionTierRequirement)3 DbUser (org.pmiops.workbench.db.model.DbUser)3 AddressException (javax.mail.internet.AddressException)2 InternetAddress (javax.mail.internet.InternetAddress)2 DbInstitutionEmailAddress (org.pmiops.workbench.db.model.DbInstitutionEmailAddress)2 DbInstitutionEmailDomain (org.pmiops.workbench.db.model.DbInstitutionEmailDomain)2 User (com.google.api.services.directory.model.User)1 Strings (com.google.common.base.Strings)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1