Skip to content

Commit

Permalink
Display the validation errors for the feed import
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Dec 18, 2024
1 parent 16e8563 commit ca39fd9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 7 additions & 4 deletions manage-server/src/main/java/manage/service/MetaDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import manage.api.Scope;
import manage.conf.MetaDataAutoConfiguration;
import manage.control.DatabaseController;
import manage.exception.CustomValidationException;
import manage.exception.DuplicateEntityIdException;
import manage.exception.EndpointNotAllowed;
import manage.exception.ResourceNotFoundException;
Expand Down Expand Up @@ -179,13 +180,13 @@ public Map<String, List> importFeed(Import importRequest) {

return results;
} catch (IOException | XMLStreamException e) {
LOG.error("Error in client/import/feed", e);
return singletonMap("errors", singletonList(e.getClass().getName()));
}
}

@SneakyThrows
public MetaData doPost(@Validated MetaData metaData, AbstractUser user, boolean excludeFromPushRequired)
{
public MetaData doPost(@Validated MetaData metaData, AbstractUser user, boolean excludeFromPushRequired) {
metaData = metaDataHook.prePost(metaData, user);
checkForDuplicateEntityId(metaData, true);

Expand Down Expand Up @@ -591,7 +592,9 @@ private void sanitizeExcludeFromPush(@RequestBody @Validated MetaData metaData,

private void addNoValid(Map<String, List> results, String entityId, Exception e) {
String msg = e instanceof ValidationException ?
String.join(", ", ValidationException.class.cast(e).getAllMessages()) : e.getClass().getName();
String.join(", ", ValidationException.class.cast(e).getAllMessages()) :
e instanceof CustomValidationException ? String.join(", ", CustomValidationException.class.cast(e).getValidationException().getAllMessages()) :
e.getClass().getName();
List notValid = results.computeIfAbsent("not_valid", s -> new ArrayList());
Map<String, String> result = new HashMap<>();
result.put("validationException", msg);
Expand Down Expand Up @@ -627,7 +630,7 @@ public void addDefaultSpData(Map<String, Object> innerJson) {
}

public void deleteCollection(EntityType entityType) {
this.metaDataRepository.getMongoTemplate().remove(new Query(),entityType.getType());
this.metaDataRepository.getMongoTemplate().remove(new Query(), entityType.getType());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"enum": [
"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
"urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
"urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
"urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
"urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
"urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName"
],
"default": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
"info": "This indicates whether the nameID is set to something random or the same every time the user logs in. Use transient if user does not need to be identified in a new session."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@ public void saveWithNewValidationNameIDFormat() {
Map<String, Object> data = readValueFromFile("/metadata_templates/saml20_idp.template.json");

data.put("entityid", "https://unique_entity_id");
Map.class.cast(data.get("metaDataFields")).put("NameIDFormat", "urn:oasis:names:tc:SAML:2.0:nameid-format:emailAddress");
Map.class.cast(data.get("metaDataFields")).put("NameIDFormat", "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress");

MetaData metaData = new MetaData(EntityType.IDP.getType(), data);
Map<String, Object> results = given()
Expand Down

0 comments on commit ca39fd9

Please sign in to comment.