[java-opensaml] branch main updated: OSJ-382 - Support for legacy class transitions in getSubcontext(String)
Scott Cantor
cantor.2 at osu.edu
Thu Jun 1 21:14:31 UTC 2023
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=6f4f018eb34669e2fc0f666ffad0e5acf325ec75
The following commit(s) were added to refs/heads/main by this push:
new 6f4f018eb OSJ-382 - Support for legacy class transitions in getSubcontext(String)
6f4f018eb is described below
commit 6f4f018eb34669e2fc0f666ffad0e5acf325ec75
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Jun 1 17:14:28 2023 -0400
OSJ-382 - Support for legacy class transitions in getSubcontext(String)
https://shibboleth.atlassian.net/browse/OSJ-382
Add a lookaside mechanism that lives in the Configuration service.
---
.../opensaml/messaging/context/BaseContext.java | 59 +++++++++++++++++++++-
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java
index 309265caf..3bbbcb2e7 100644
--- a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/BaseContext.java
@@ -19,6 +19,7 @@ package org.opensaml.messaging.context;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
+import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -27,9 +28,13 @@ import javax.annotation.concurrent.NotThreadSafe;
import net.shibboleth.shared.annotation.constraint.NonnullElements;
import net.shibboleth.shared.annotation.constraint.NotEmpty;
import net.shibboleth.shared.collection.ClassIndexedSet;
+import net.shibboleth.shared.collection.CollectionSupport;
import net.shibboleth.shared.logic.Constraint;
+import net.shibboleth.shared.primitive.DeprecationSupport;
+import net.shibboleth.shared.primitive.DeprecationSupport.ObjectType;
import net.shibboleth.shared.primitive.LoggerFactory;
+import org.opensaml.core.config.ConfigurationService;
import org.opensaml.messaging.MessageRuntimeException;
import org.slf4j.Logger;
@@ -200,6 +205,17 @@ public abstract class BaseContext implements Iterable<BaseContext> {
try {
return getSubcontext(Class.forName(className).asSubclass(BaseContext.class), autocreate);
} catch (final ClassNotFoundException e) {
+
+ // Check for a deprecated class name.
+ final DeprecatedContextClassNameLookAside lookaside =
+ ConfigurationService.get(DeprecatedContextClassNameLookAside.class);
+ if (lookaside != null) {
+ final Class<? extends BaseContext> claz = lookaside.get(className);
+ if (claz != null) {
+ return getSubcontext(claz, autocreate);
+ }
+ }
+
if (!autocreate) {
for (final BaseContext child : this) {
if (child.getClass().getSimpleName().equals(className)) {
@@ -328,7 +344,7 @@ public abstract class BaseContext implements Iterable<BaseContext> {
* Clear the subcontexts of the current context.
*/
public void clearSubcontexts() {
- log.trace("Clearing all subcontexts from context with type '{}'", this.getClass().getName());
+ log.trace("Clearing all subcontexts from context with type '{}'", getClass().getName());
for (final BaseContext subcontext : subcontexts) {
subcontext.setParent(null);
}
@@ -394,5 +410,44 @@ public abstract class BaseContext implements Iterable<BaseContext> {
}
}
+
+ /**
+ * A facade for a map of class names to class types that allows string-based access to renamed classes.
+ *
+ * @since 5.0.0
+ */
+ public static class DeprecatedContextClassNameLookAside {
+
+ /** Map of renamed classes. */
+ @Nonnull private final Map<String,Class<? extends BaseContext>> lookAsideMap;
+
+ /**
+ * Constructor.
+ *
+ * @param map look aside map of class name strings to classes
+ */
+ public DeprecatedContextClassNameLookAside(@Nullable final Map<String,Class<? extends BaseContext>> map) {
+ if (map != null) {
+ lookAsideMap = CollectionSupport.copyToMap(map);
+ } else {
+ lookAsideMap = CollectionSupport.emptyMap();
+ }
+ }
+
+ /**
+ * Get the relocated class object if it exists.
+ *
+ * @param name class name
+ *
+ * @return relocated class object
+ */
+ @Nullable public Class<? extends BaseContext> get(@Nonnull final String name) {
+ final Class<? extends BaseContext> claz = lookAsideMap.get(name);
+ if (claz != null) {
+ DeprecationSupport.warn(ObjectType.CLASS, name, null, claz.getName());
+ }
+ return claz;
+ }
+ }
-}
+}
\ 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