Skip to content

Commit

Permalink
[SHIBUI-701]
Browse files Browse the repository at this point in the history
Added a bit of error handing when the specified file doesn't exist,
causing the initialization to fail.
  • Loading branch information
Bill Smith committed Nov 12, 2018
1 parent 5a6f533 commit 9b80bec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringWriter;
import java.net.URI;
Expand Down Expand Up @@ -151,7 +152,13 @@ public ResponseEntity<?> update(@PathVariable String resourceId, @RequestBody Me
MetadataResolver persistedResolver = resolverRepository.save(updatedResolver);

if (persistedResolver.getDoInitialization()) {
org.opensaml.saml.metadata.resolver.MetadataResolver openSamlRepresentation = metadataResolverConverterService.convertToOpenSamlRepresentation(persistedResolver);
org.opensaml.saml.metadata.resolver.MetadataResolver openSamlRepresentation = null;
try {
openSamlRepresentation = metadataResolverConverterService.convertToOpenSamlRepresentation(persistedResolver);
} catch (FileNotFoundException e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "label.file-doesnt-exist"));
}
OpenSamlChainingMetadataResolverUtil.updateChainingMetadataResolver((OpenSamlChainingMetadataResolver) chainingMetadataResolver, openSamlRepresentation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import javax.validation.ConstraintViolationException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;

Expand Down Expand Up @@ -62,6 +63,9 @@ private OpenSamlFileBackedHTTPMetadataResolver convertToOpenSamlRepresentation(F
private OpenSamlFilesystemMetadataResolver convertToOpenSamlRepresentation(FilesystemMetadataResolver resolver) throws IOException, ResolverException, ComponentInitializationException {
IndexWriter indexWriter = indexWriterService.getIndexWriter(resolver.getResourceId());
File metadataFile = new File(resolver.getMetadataFile());
if (resolver.getDoInitialization() && !metadataFile.exists()) {
throw new FileNotFoundException("No file was found on the fileysystem for provided filename: " + resolver.getMetadataFile());
}

OpenSamlFilesystemMetadataResolver openSamlResolver = new OpenSamlFilesystemMetadataResolver(openSamlObjects.getParserPool(),
indexWriter,
Expand Down
1 change: 1 addition & 0 deletions backend/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ label.attribute-employeeNumber=employeeNumber
label.force-authn=Force AuthN

label.do-resolver-initialization=Initialize
label.file-doesnt-exist=The file specified in the resolver does not exist on the file system. Therefore, the resolver cannot be initialized.

message.must-be-unique=Must be unique.
message.name-must-be-unique=Name must be unique.
Expand Down
1 change: 1 addition & 0 deletions backend/src/main/resources/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ label.attribute-employeeNumber=employeeNumber
label.force-authn=Force AuthN

label.do-resolver-initialization=Initialize
label.file-doesnt-exist=The file specified in the resolver does not exist on the file system. Therefore, the resolver cannot be initialized.

message.must-be-unique=Must be unique.
message.name-must-be-unique=Name must be unique.
Expand Down

0 comments on commit 9b80bec

Please sign in to comment.