use of org.orcid.pojo.HeaderMismatch in project ORCID-Source by ORCID.
the class InstitutionalSignInManagerImpl method checkHeaders.
@Override
public HeaderCheckResult checkHeaders(Map<String, String> originalHeaders, Map<String, String> currentHeaders) {
HeaderCheckResult result = new HeaderCheckResult();
List<String> headersToCheck = new ArrayList<>();
headersToCheck.addAll(Arrays.asList(POSSIBLE_REMOTE_USER_HEADERS));
headersToCheck.add(EPPN_HEADER);
for (String headerName : headersToCheck) {
String original = originalHeaders.get(headerName);
String current = currentHeaders.get(headerName);
// just be an IdP config change to add/remove the attribute
if (StringUtils.isNoneBlank(original, current)) {
Set<String> originalDeduped = dedupe(original);
Set<String> currentDeduped = dedupe(current);
if (!currentDeduped.equals(originalDeduped)) {
result.addMismatch(new HeaderMismatch(headerName, original, current));
}
}
}
if (!result.isSuccess()) {
String message = String.format("Institutional sign in header check failed: %s, originalHeaders=%s", result, originalHeaders);
LOGGER.info(message);
slackManager.sendSystemAlert(message);
}
return result;
}
use of org.orcid.pojo.HeaderMismatch in project ORCID-Source by ORCID.
the class InstitutionalSignInManagerTest method testCheckHeaders.
@Test
public void testCheckHeaders() throws IOException {
@SuppressWarnings("unchecked") Map<String, String> originalHeaders = JsonUtils.readObjectFromJsonString(IOUtils.toString(getClass().getResource("shibboleth_headers_original.json")), Map.class);
Map<String, String> currentHeaders = new HashMap<>(originalHeaders);
// When all headers are the same
HeaderCheckResult result = institutionalSignInManager.checkHeaders(originalHeaders, currentHeaders);
assertTrue(result.isSuccess());
assertEquals(0, result.getMismatches().size());
// When eppn is different
currentHeaders.put("eppn", "someoneelse@testshib.org");
result = institutionalSignInManager.checkHeaders(originalHeaders, currentHeaders);
assertFalse(result.isSuccess());
assertEquals(1, result.getMismatches().size());
HeaderMismatch mismatch = result.getMismatches().get(0);
assertEquals("eppn", mismatch.getHeaderName());
assertEquals("myself@testshib.org", mismatch.getOriginalValue());
assertEquals("someoneelse@testshib.org", mismatch.getCurrentValue());
// When eppn was originally there, but is not now
currentHeaders.remove("eppn");
result = institutionalSignInManager.checkHeaders(originalHeaders, currentHeaders);
assertTrue(result.isSuccess());
assertEquals(0, result.getMismatches().size());
// When eppn is duplicated but unchanged
currentHeaders.put("eppn", "myself@testshib.org;myself@testshib.org");
result = institutionalSignInManager.checkHeaders(originalHeaders, currentHeaders);
assertTrue(result.isSuccess());
assertEquals(0, result.getMismatches().size());
// When eppn is duplicated and changed
currentHeaders.put("eppn", "someoneelse@testshib.org;someoneelse@testshib.org");
result = institutionalSignInManager.checkHeaders(originalHeaders, currentHeaders);
assertFalse(result.isSuccess());
assertEquals(1, result.getMismatches().size());
mismatch = result.getMismatches().get(0);
assertEquals("eppn", mismatch.getHeaderName());
assertEquals("myself@testshib.org", mismatch.getOriginalValue());
assertEquals("someoneelse@testshib.org;someoneelse@testshib.org", mismatch.getCurrentValue());
// When eppn is duplicated and one of values changed
currentHeaders.put("eppn", "myself@testshib.org;someoneelse@testshib.org");
result = institutionalSignInManager.checkHeaders(originalHeaders, currentHeaders);
assertFalse(result.isSuccess());
assertEquals(1, result.getMismatches().size());
mismatch = result.getMismatches().get(0);
assertEquals("eppn", mismatch.getHeaderName());
assertEquals("myself@testshib.org", mismatch.getOriginalValue());
assertEquals("myself@testshib.org;someoneelse@testshib.org", mismatch.getCurrentValue());
}
Aggregations