[java-opensaml COMMIT] in /trunk/opensaml-saml-impl/src: main/java/org/opensaml/saml/saml2/metadata/provider/Filesyst...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Mar 20 19:28:39 EDT 2013
Author: putmanb
Date: Wed Mar 20 19:28:39 2013
New Revision: 3270
URL: http://svn.shibboleth.net/view/java-opensaml?rev=3270&view=rev
Log:
Porting JOST-205 from v2.
Modified:
trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProvider.java
trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProviderTest.java
Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProvider.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProvider.java?rev=3270&r1=3269&r2=3270&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProvider.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProvider.java Wed Mar 20 19:28:39 2013
@@ -87,17 +87,7 @@
*/
protected void setMetadataFile(File file) throws MetadataProviderException {
- if (!file.exists()) {
- throw new MetadataProviderException("Give metadata file, " + file.getAbsolutePath() + " does not exist");
- }
-
- if (!file.isFile()) {
- throw new MetadataProviderException("Give metadata file, " + file.getAbsolutePath() + " is not a file");
- }
-
- if (!file.canRead()) {
- throw new MetadataProviderException("Give metadata file, " + file.getAbsolutePath() + " is not readable");
- }
+ validateMetadataFile(file);
metadataFile = file;
}
@@ -139,6 +129,7 @@
/** {@inheritDoc} */
protected byte[] fetchMetadata() throws MetadataProviderException {
try {
+ validateMetadataFile(metadataFile);
DateTime metadataUpdateTime = new DateTime(metadataFile.lastModified(), ISOChronology.getInstanceUTC());
if (getLastRefresh() == null || metadataUpdateTime.isAfter(getLastRefresh())) {
return inputstreamToByteArray(new FileInputStream(metadataFile));
@@ -151,4 +142,26 @@
throw new MetadataProviderException(errMsg, e);
}
}
+
+ /**
+ * Validate the basic properties of the specified metadata file, for example that it exists;
+ * that it is a file; and that it is readable.
+ *
+ * @param file the file to evaluate
+ * @throws MetadataProviderException if file does not pass basic properties required of a metadata file
+ */
+ protected void validateMetadataFile(File file) throws MetadataProviderException {
+ if (!file.exists()) {
+ throw new MetadataProviderException("Metadata file '" + file.getAbsolutePath() + "' does not exist");
+ }
+
+ if (!file.isFile()) {
+ throw new MetadataProviderException("Metadata file '" + file.getAbsolutePath() + "' is not a file");
+ }
+
+ if (!file.canRead()) {
+ throw new MetadataProviderException("Metadata file '" + file.getAbsolutePath() + "' is not readable");
+ }
+ }
+
}
Modified: trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProviderTest.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProviderTest.java?rev=3270&r1=3269&r2=3270&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProviderTest.java (original)
+++ trunk/opensaml-saml-impl/src/test/java/org/opensaml/saml/saml2/metadata/provider/FilesystemMetadataProviderTest.java Wed Mar 20 19:28:39 2013
@@ -21,6 +21,7 @@
import org.testng.annotations.BeforeMethod;
import org.testng.Assert;
import java.io.File;
+import java.io.IOException;
import java.net.URL;
import java.util.List;
@@ -32,9 +33,13 @@
import org.opensaml.saml.saml2.metadata.provider.HTTPMetadataProvider;
import org.opensaml.saml.saml2.metadata.provider.MetadataProviderException;
+import com.google.common.io.Files;
+
public class FilesystemMetadataProviderTest extends XMLObjectBaseTestCase {
private FilesystemMetadataProvider metadataProvider;
+
+ private File mdFile;
private String entityID;
@@ -48,7 +53,7 @@
URL mdURL = FilesystemMetadataProviderTest.class
.getResource("/data/org/opensaml/saml/saml2/metadata/InCommon-metadata.xml");
- File mdFile = new File(mdURL.toURI());
+ mdFile = new File(mdURL.toURI());
metadataProvider = new FilesystemMetadataProvider(mdFile);
metadataProvider.setParserPool(parserPool);
@@ -84,4 +89,89 @@
supportedProtocol);
Assert.assertNotNull(role, "Roles for entity descriptor was null");
}
+
+ /**
[... 85 lines stripped ...]
More information about the commits
mailing list