[java-identity-provider] branch main updated: IDP-1866 - Module handling does not work when idpHome is classpath:
Scott Cantor
cantor.2 at osu.edu
Wed Nov 3 22:49:32 UTC 2021
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=9475c2e05e69e5573e44c6a99ec8e0cfbdd9436e
The following commit(s) were added to refs/heads/main by this push:
new 9475c2e05 IDP-1866 - Module handling does not work when idpHome is classpath:
9475c2e05 is described below
commit 9475c2e05e69e5573e44c6a99ec8e0cfbdd9436e
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Nov 3 18:49:24 2021 -0400
IDP-1866 - Module handling does not work when idpHome is classpath:
https://shibboleth.atlassian.net/browse/IDP-1866
Adjust ModuleContext API to defer path construction.
---
.../shibboleth/idp/module/AbstractIdPModule.java | 36 +++++++++++++---------
.../net/shibboleth/idp/module/ModuleContext.java | 23 +++++++++++---
2 files changed, 41 insertions(+), 18 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 5ba6d9516..6a49bb3c6 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
@@ -109,16 +109,24 @@ public abstract class AbstractIdPModule implements IdPModule {
continue;
}
- final Path resolved = moduleContext.getIdPHome().resolve(resource.getDestination());
- log.debug("Module {}: resolved resource destination {}", getId(), resolved);
- if (resolved.toString().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
- final ClassPathResource cp = new ClassPathResource(
- resolved.toString().substring(ResourceUtils.CLASSPATH_URL_PREFIX.length()));
+ if (moduleContext.getInstallLocation().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+ final ClassPathResource cp;
+ if (moduleContext.getInstallLocation().equals(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+ cp = new ClassPathResource(resource.getDestination().toString());
+ } else {
+ cp = (ClassPathResource) new ClassPathResource(
+ moduleContext.getInstallLocation().substring(
+ ResourceUtils.CLASSPATH_URL_PREFIX.length())).createRelative(
+ resource.getDestination().toString());
+ }
+
if (!cp.exists()) {
- log.debug("Module {}: resource destination {} missing, module is disabled", getId(), resolved);
+ log.debug("Module {}: resource destination {} missing, module is disabled", getId(),
+ ResourceUtils.CLASSPATH_URL_PREFIX + cp.getPath());
return false;
}
} else {
+ final Path resolved = Path.of(moduleContext.getInstallLocation()).resolve(resource.getDestination());
if (!resolved.toFile().exists()) {
log.debug("Module {}: resource destination {} missing, module is disabled", getId(), resolved);
return false;
@@ -134,7 +142,7 @@ public abstract class AbstractIdPModule implements IdPModule {
@Nonnull @NonnullElements public Map<ModuleResource, ResourceResult> enable(
@Nonnull final ModuleContext moduleContext) throws ModuleException {
- if (moduleContext.getIdPHome().toString().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+ if (moduleContext.getInstallLocation().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
throw new ModuleException("IdP location is a classpath");
}
@@ -164,7 +172,7 @@ public abstract class AbstractIdPModule implements IdPModule {
@Nonnull @NonnullElements public Map<ModuleResource, ResourceResult> disable(
@Nonnull final ModuleContext moduleContext, final boolean clean) throws ModuleException {
- if (moduleContext.getIdPHome().toString().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
+ if (moduleContext.getInstallLocation().startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
throw new ModuleException("IdP location is a classpath");
}
@@ -400,7 +408,7 @@ public abstract class AbstractIdPModule implements IdPModule {
@Nullable private InputStream getDestinationStream(@Nonnull final ModuleContext moduleContext)
throws IOException {
- final Path destPath = moduleContext.getIdPHome().resolve(destination);
+ final Path destPath = Path.of(moduleContext.getInstallLocation()).resolve(destination);
if (Files.exists(destPath)) {
try {
return Files.newInputStream(destPath, StandardOpenOption.READ);
@@ -436,7 +444,7 @@ public abstract class AbstractIdPModule implements IdPModule {
if (hasChanged) {
if (isReplace()) {
- destPath = moduleContext.getIdPHome().resolve(destination);
+ destPath = Path.of(moduleContext.getInstallLocation()).resolve(destination);
final Path savedPath = destPath.resolveSibling(destPath.getFileName() + ".idpsave");
if (savedPath.toFile().exists()) {
throw new IOException(savedPath + " exists, aborting");
@@ -445,17 +453,17 @@ public abstract class AbstractIdPModule implements IdPModule {
log.debug("Module {} preserved {}", getId(), destPath);
result = ResourceResult.REPLACED;
} else {
- final Path basePath = moduleContext.getIdPHome().resolve(destination);
+ final Path basePath = Path.of(moduleContext.getInstallLocation()).resolve(destination);
destPath = basePath.resolveSibling(basePath.getFileName() + ".idpnew");
result = ResourceResult.ADDED;
}
} else {
- destPath = moduleContext.getIdPHome().resolve(destination);
+ destPath = Path.of(moduleContext.getInstallLocation()).resolve(destination);
result = ResourceResult.CREATED;
}
- if (!destPath.startsWith(moduleContext.getIdPHome())) {
+ if (!destPath.startsWith(moduleContext.getInstallLocation())) {
log.error("Module {} attempted to create file outside of IdP installation: {}", getId(), destPath);
throw new ModuleException("Module asked to create file outside of IdP installation");
}
@@ -495,7 +503,7 @@ public abstract class AbstractIdPModule implements IdPModule {
throws ModuleException {
final ResourceResult result;
- final Path resolved = moduleContext.getIdPHome().resolve(destination);
+ final Path resolved = Path.of(moduleContext.getInstallLocation()).resolve(destination);
log.debug("Module {} resolved resource destination {}", getId(), resolved);
if (Files.exists(resolved)) {
try {
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/module/ModuleContext.java b/idp-admin-api/src/main/java/net/shibboleth/idp/module/ModuleContext.java
index 092877a93..3803beb04 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/module/ModuleContext.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/module/ModuleContext.java
@@ -43,7 +43,7 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
public final class ModuleContext {
/** IdP installation root. */
- @Nonnull private Path idpHome;
+ @Nonnull private String idpHome;
/** HttpClient if needed. */
@Nullable private HttpClient httpClient;
@@ -63,7 +63,7 @@ public final class ModuleContext {
* @param home location of IdP install
*/
public ModuleContext(@Nonnull @NotEmpty final String home) {
- idpHome = Path.of(home);
+ idpHome = Constraint.isNotEmpty(home, "Home location cannot be null or empty");
languageRanges = Collections.emptyList();
}
@@ -73,16 +73,31 @@ public final class ModuleContext {
* @param home location of IdP install
*/
public ModuleContext(@Nonnull final Path home) {
- idpHome = Constraint.isNotNull(home, "IdP home path cannot be null");
- languageRanges = Collections.emptyList();
+ this(home.toString());
}
/**
* Gets software installation location.
*
+ * <p>Use the String variant to avoid Windows borkage.</p>
+ *
* @return install path
+ *
+ * @deprecated
*/
+ @Deprecated(since="4.2", forRemoval=true)
@Nonnull Path getIdPHome() {
+ return Path.of(idpHome);
+ }
+
+ /**
+ * Gets software installation location.
+ *
+ * @return install path
+ *
+ * @since 4.2.0
+ */
+ @Nonnull @NotEmpty String getInstallLocation() {
return idpHome;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list