[java-identity-provider] branch main updated: IDP-2032 - Add version to .idpnew file names
Scott Cantor
cantor.2 at osu.edu
Wed Apr 26 16:57:56 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=883f6e8156e39f484a392e932a2d9f2c330b7377
The following commit(s) were added to refs/heads/main by this push:
new 883f6e815 IDP-2032 - Add version to .idpnew file names
883f6e815 is described below
commit 883f6e8156e39f484a392e932a2d9f2c330b7377
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Apr 26 12:57:52 2023 -0400
IDP-2032 - Add version to .idpnew file names
https://shibboleth.atlassian.net/browse/IDP-2032
Used convention of filename.idpnew-NNN to allow proper sort.
---
.../net/shibboleth/idp/module/AbstractIdPModule.java | 20 ++++++++++++++++----
.../net/shibboleth/idp/module/IdPModuleTest.java | 18 +++++++++++-------
2 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java b/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
index 89413ffdf..1a724c9e0 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/module/AbstractIdPModule.java
@@ -48,6 +48,7 @@ import org.slf4j.Logger;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils;
+import net.shibboleth.idp.Version;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.annotation.constraint.NotLive;
@@ -65,15 +66,26 @@ import net.shibboleth.shared.spring.httpclient.resource.ConnectionClosingInputSt
*/
public abstract class AbstractIdPModule implements IdPModule {
+ /** Extension for preserving user files. */
+ @Nonnull @NotEmpty public static final String IDPSAVE_EXT = ".idpsave";
+
+ /** Base extension for adding new default files. */
+ @Nonnull @NotEmpty public static final String IDPNEW_EXT_BASE = ".idpnew";
+
/** Class logger. */
@Nonnull private Logger log = LoggerFactory.getLogger(AbstractIdPModule.class);
/** Module resources. */
@Nonnull private Collection<ModuleResource> moduleResources;
+ /** Version-aware extension for new files added. */
+ @Nonnull private String idpNewExt;
+
/** Constructor. */
public AbstractIdPModule() {
moduleResources = CollectionSupport.emptyList();
+ final String version = Version.getVersion();
+ idpNewExt = version != null ? IDPNEW_EXT_BASE + "-" + version : IDPNEW_EXT_BASE;
}
/** {@inheritDoc} */
@@ -450,7 +462,7 @@ public abstract class AbstractIdPModule implements IdPModule {
if (hasChanged) {
if (isReplace()) {
destPath = Path.of(moduleContext.getInstallLocation()).resolve(destination);
- final Path savedPath = destPath.resolveSibling(destPath.getFileName() + ".idpsave");
+ final Path savedPath = destPath.resolveSibling(destPath.getFileName() + IDPSAVE_EXT);
if (savedPath.toFile().exists()) {
throw new IOException(savedPath + " exists, aborting");
}
@@ -459,7 +471,7 @@ public abstract class AbstractIdPModule implements IdPModule {
result = ResourceResult.REPLACED;
} else {
final Path basePath = Path.of(moduleContext.getInstallLocation()).resolve(destination);
- destPath = basePath.resolveSibling(basePath.getFileName() + ".idpnew");
+ destPath = basePath.resolveSibling(basePath.getFileName() + idpNewExt);
result = ResourceResult.ADDED;
}
@@ -518,11 +530,11 @@ public abstract class AbstractIdPModule implements IdPModule {
result = ResourceResult.REMOVED;
} else {
log.debug("Module {} backing up resource {}", getId(), resolved);
- Files.move(resolved, resolved.resolveSibling(resolved.getFileName() + ".idpsave"),
+ Files.move(resolved, resolved.resolveSibling(resolved.getFileName() + IDPSAVE_EXT),
StandardCopyOption.REPLACE_EXISTING);
result = ResourceResult.SAVED;
}
- final Path idpnewVersion = resolved.resolveSibling(resolved.getFileName() + ".idpnew");
+ final Path idpnewVersion = resolved.resolveSibling(resolved.getFileName() + idpNewExt);
if (Files.exists(idpnewVersion)) {
Files.delete(idpnewVersion);
}
diff --git a/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java b/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java
index d74f1f24c..e7aa19656 100644
--- a/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java
+++ b/idp-admin-api/src/test/java/net/shibboleth/idp/module/IdPModuleTest.java
@@ -39,6 +39,8 @@ import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.ServiceLoader.Provider;
+import javax.annotation.Nonnull;
+
import org.opensaml.security.credential.impl.StaticCredentialResolver;
import org.opensaml.security.httpclient.HttpClientSecurityParameters;
import org.opensaml.security.httpclient.impl.SecurityEnhancedHttpClientSupport;
@@ -294,13 +296,15 @@ public class IdPModuleTest {
Assert.assertEquals(vel, VEL_DATA);
}
- private static TrustEngine<? super X509Credential> buildExplicitKeyTrustEngine() throws URISyntaxException, CertificateException, IOException {
-
- final InputStream certStream = IdPModuleTest.class.getResourceAsStream("/net/shibboleth/idp/module/repo-entity.crt");
- final X509Certificate entityCert = X509Support.decodeCertificate(ByteStreams.toByteArray(certStream));
- assert entityCert != null;
- final X509Credential entityCredential = new BasicX509Credential(entityCert);
- return new ExplicitKeyTrustEngine(new StaticCredentialResolver(entityCredential));
+ @Nonnull private static TrustEngine<? super X509Credential> buildExplicitKeyTrustEngine()
+ throws URISyntaxException, CertificateException, IOException {
+ try (final InputStream certStream = IdPModuleTest.class.getResourceAsStream("/net/shibboleth/idp/module/repo-entity.crt")) {
+ final X509Certificate entityCert = X509Support.decodeCertificate(ByteStreams.toByteArray(certStream));
+ assert entityCert != null;
+ final X509Credential entityCredential = new BasicX509Credential(entityCert);
+ return new ExplicitKeyTrustEngine(new StaticCredentialResolver(entityCredential));
+ }
}
+
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list