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);
}
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));
}
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);
}
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()));
}
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;
}
Aggregations