@Test public void testLoginRealmIdsForLEA() { Entity sea = buildEdOrg("SEA1", null, true); Entity lea = buildEdOrg("LEA", sea, false); Entity leaStaff = buildStaff("LEA Staff", lea); Entity seaRealm = buildRealm(sea); Entity leaRealm = buildRealm(lea); RequestUtil.setCurrentRequestId(); assertFalse(helper.isUserAllowedLoginToRealm(leaStaff, seaRealm)); RequestUtil.setCurrentRequestId(); assertTrue(helper.isUserAllowedLoginToRealm(leaStaff, leaRealm)); }
public boolean isUserAllowedLoginToRealm(Entity userEntity, Entity realm) { if (isSandboxEnabled) { return true; } List<String> preferredRealms = getPreferredLoginRealmIds(userEntity); if (preferredRealms.size() > 0) { return preferredRealms.contains(realm.getEntityId()); } Set<String> userEdorgs = edorgHelper.locateDirectEdorgs(userEntity); for (String id : userEdorgs) { Entity edorgEntity = repo.findById("educationOrganization", id); if (isValidForLogin(edorgEntity, realm)) { LOG.debug("User is allowed to login to realm: {} through edorg: {}", realm.getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); return true; } else { LOG.debug("User cannot login to realm: {} through edorg: {}", realm .getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); } } return false; }
RealmHelper { public boolean isUserAllowedLoginToRealm(Entity userEntity, Entity realm) { if (isSandboxEnabled) { return true; } List<String> preferredRealms = getPreferredLoginRealmIds(userEntity); if (preferredRealms.size() > 0) { return preferredRealms.contains(realm.getEntityId()); } Set<String> userEdorgs = edorgHelper.locateDirectEdorgs(userEntity); for (String id : userEdorgs) { Entity edorgEntity = repo.findById("educationOrganization", id); if (isValidForLogin(edorgEntity, realm)) { LOG.debug("User is allowed to login to realm: {} through edorg: {}", realm.getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); return true; } else { LOG.debug("User cannot login to realm: {} through edorg: {}", realm .getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); } } return false; } }
RealmHelper { public boolean isUserAllowedLoginToRealm(Entity userEntity, Entity realm) { if (isSandboxEnabled) { return true; } List<String> preferredRealms = getPreferredLoginRealmIds(userEntity); if (preferredRealms.size() > 0) { return preferredRealms.contains(realm.getEntityId()); } Set<String> userEdorgs = edorgHelper.locateDirectEdorgs(userEntity); for (String id : userEdorgs) { Entity edorgEntity = repo.findById("educationOrganization", id); if (isValidForLogin(edorgEntity, realm)) { LOG.debug("User is allowed to login to realm: {} through edorg: {}", realm.getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); return true; } else { LOG.debug("User cannot login to realm: {} through edorg: {}", realm .getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); } } return false; }  }
RealmHelper { public boolean isUserAllowedLoginToRealm(Entity userEntity, Entity realm) { if (isSandboxEnabled) { return true; } List<String> preferredRealms = getPreferredLoginRealmIds(userEntity); if (preferredRealms.size() > 0) { return preferredRealms.contains(realm.getEntityId()); } Set<String> userEdorgs = edorgHelper.locateDirectEdorgs(userEntity); for (String id : userEdorgs) { Entity edorgEntity = repo.findById("educationOrganization", id); if (isValidForLogin(edorgEntity, realm)) { LOG.debug("User is allowed to login to realm: {} through edorg: {}", realm.getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); return true; } else { LOG.debug("User cannot login to realm: {} through edorg: {}", realm .getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); } } return false; }  String getSandboxRealmId(); String getAdminRealmId(); String getEdOrgIdFromRealm(String realmId); Entity getRealmFromSession(String sessionId); List<String> getPreferredLoginRealmIds(Entity userEntity); Iterable<Entity> getRealms(Entity edOrg); boolean isUserAllowedLoginToRealm(Entity userEntity, Entity realm); Set<String> getAssociatedRealmIds(); Entity findRealmById(String id); }
RealmHelper { public boolean isUserAllowedLoginToRealm(Entity userEntity, Entity realm) { if (isSandboxEnabled) { return true; } List<String> preferredRealms = getPreferredLoginRealmIds(userEntity); if (preferredRealms.size() > 0) { return preferredRealms.contains(realm.getEntityId()); } Set<String> userEdorgs = edorgHelper.locateDirectEdorgs(userEntity); for (String id : userEdorgs) { Entity edorgEntity = repo.findById("educationOrganization", id); if (isValidForLogin(edorgEntity, realm)) { LOG.debug("User is allowed to login to realm: {} through edorg: {}", realm.getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); return true; } else { LOG.debug("User cannot login to realm: {} through edorg: {}", realm .getBody().get("name"), edorgEntity.getBody().get("nameOfInstitution")); } } return false; }  String getSandboxRealmId(); String getAdminRealmId(); String getEdOrgIdFromRealm(String realmId); Entity getRealmFromSession(String sessionId); List<String> getPreferredLoginRealmIds(Entity userEntity); Iterable<Entity> getRealms(Entity edOrg); boolean isUserAllowedLoginToRealm(Entity userEntity, Entity realm); Set<String> getAssociatedRealmIds(); Entity findRealmById(String id); static final String USER_SESSION; }