USER_NAME_ATTRIBUTE, samlSettings.getUserName(),
USER_LOGIN_ATTRIBUTE, samlSettings.getUserLogin());
- return generateMissingMappingMessages(mappings, auth);
+ List<String> mappingErrors = generateMissingMappingMessages(mappings, auth);
+ if (mappingErrors.isEmpty()) {
+ mappingErrors = generateEmptyMappingsMessages(mappings, auth);
+ }
+
+ return mappingErrors;
}
private static List<String> generateMissingMappingMessages(Map<String, String> mappings, Auth auth) {
.toList();
}
+ private static List<String> generateEmptyMappingsMessages(Map<String, String> mappings, Auth auth) {
+ return mappings.entrySet()
+ .stream()
+ .filter(entry -> (auth.getAttribute(entry.getValue()).size() == 1 && auth.getAttribute(entry.getValue()).contains("")))
+ .map(entry -> String.format("Mapping found for the property %s, but the field %s is empty in the SAML response.", entry.getKey(), entry.getValue()))
+ .toList();
+ }
}
@Before
public void setUp() {
- when(auth.getErrors()).thenReturn(new ArrayList<String>());
+ when(auth.getErrors()).thenReturn(new ArrayList<>());
when(auth.getSettings()).thenReturn(new Saml2Settings());
when(auth.getAttributes()).thenReturn(getResponseAttributes());
}
.contains(String.format("Mapping not found for the property %s, the field %s is not available in the SAML response.", USER_NAME_ATTRIBUTE, "wrongNameField")));
}
+ @Test
+ public void authentication_has_errors_when_login_and_name_are_empty() {
+ setSettings();
+ when(auth.getAttributes()).thenReturn(getEmptyAttributes());
+ getEmptyAttributes().forEach((key, value) -> when(auth.getAttribute(key)).thenReturn(value));
+
+ samlAuthenticationStatus = getSamlAuthenticationStatus(auth, new SamlSettings(settings.asConfig()));
+
+ assertEquals("error", samlAuthenticationStatus.getStatus());
+ assertTrue(samlAuthenticationStatus.getWarnings().isEmpty());
+ assertEquals(2, samlAuthenticationStatus.getErrors().size());
+ assertTrue(samlAuthenticationStatus.getErrors()
+ .contains(String.format("Mapping found for the property %s, but the field %s is empty in the SAML response.", USER_LOGIN_ATTRIBUTE, "login")));
+ assertTrue(samlAuthenticationStatus.getErrors()
+ .contains(String.format("Mapping found for the property %s, but the field %s is empty in the SAML response.", USER_NAME_ATTRIBUTE, "name")));
+ }
+
@Test
public void authentication_has_no_warnings_when_optional_mappings_are_not_provided() {
setSettings();