[java-opensaml] branch master updated: Avoid unchecked cast in ParentContextLookup.
Scott Cantor
cantor.2 at osu.edu
Wed Jul 31 13:58:48 EDT 2019
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=2006a9f0446bed4d12ddfc84cf3c11b78c12c450
The following commit(s) were added to refs/heads/master by this push:
new 2006a9f Avoid unchecked cast in ParentContextLookup.
2006a9f is described below
commit 2006a9f0446bed4d12ddfc84cf3c11b78c12c450
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Wed Jul 31 13:58:45 2019 -0400
Avoid unchecked cast in ParentContextLookup.
---
.../context/navigate/ParentContextLookup.java | 27 +++++++++++++++++++---
.../RecursiveTypedParentContextLookup.java | 2 +-
...SAMLAddAttributeConsumingServiceHandleTest.java | 2 +-
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/ParentContextLookup.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/ParentContextLookup.java
index 1a1de07..9011ca4 100644
--- a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/ParentContextLookup.java
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/ParentContextLookup.java
@@ -17,10 +17,14 @@
package org.opensaml.messaging.context.navigate;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.opensaml.messaging.context.BaseContext;
+import net.shibboleth.utilities.java.support.annotation.ParameterName;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+
/**
* A {@link ContextDataLookupFunction} that gets the parent of a given context.
*
@@ -29,13 +33,30 @@ import org.opensaml.messaging.context.BaseContext;
*/
public class ParentContextLookup<StartContext extends BaseContext, ParentContext extends BaseContext>
implements ContextDataLookupFunction<StartContext, ParentContext> {
+
+ /** Parent type. */
+ @Nonnull private final Class<ParentContext> parentType;
+
+ /**
+ * Constructor.
+ *
+ * @param type parent context type to look up
+ */
+ public ParentContextLookup(@Nonnull @ParameterName(name="type") final Class<ParentContext> type) {
+ parentType = Constraint.isNotNull(type, "Parent context type cannot be null");
+ }
/** {@inheritDoc} */
@Nullable public ParentContext apply(@Nullable final StartContext input) {
- if (input == null) {
- return null;
+
+ if (input != null) {
+ final BaseContext parent = input.getParent();
+ if (parentType.isInstance(parent)) {
+ return parentType.cast(parent);
+ }
}
- return (ParentContext) input.getParent();
+ return null;
}
+
}
\ No newline at end of file
diff --git a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/RecursiveTypedParentContextLookup.java b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/RecursiveTypedParentContextLookup.java
index 1b392d4..24753af 100644
--- a/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/RecursiveTypedParentContextLookup.java
+++ b/opensaml-messaging-api/src/main/java/org/opensaml/messaging/context/navigate/RecursiveTypedParentContextLookup.java
@@ -58,7 +58,7 @@ public class RecursiveTypedParentContextLookup<StartContext extends BaseContext,
BaseContext current = input.getParent();
while (current != null) {
if (parentClass.isInstance(current)) {
- return (ParentContext) current;
+ return parentClass.cast(current);
}
current = current.getParent();
}
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLAddAttributeConsumingServiceHandleTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLAddAttributeConsumingServiceHandleTest.java
index 1ca08c7..f7ce991 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLAddAttributeConsumingServiceHandleTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/SAMLAddAttributeConsumingServiceHandleTest.java
@@ -155,7 +155,7 @@ public class SAMLAddAttributeConsumingServiceHandleTest extends XMLObjectBaseTes
@Test public void navigate() throws MessageHandlerException, ComponentInitializationException {
final SAMLAddAttributeConsumingServiceHandler navigatedHandler = new SAMLAddAttributeConsumingServiceHandler();
- navigatedHandler.setMetadataContextLookupStrategy(new ParentContextLookup<MessageContext, SAMLMetadataContext>());
+ navigatedHandler.setMetadataContextLookupStrategy(new ParentContextLookup<>(SAMLMetadataContext.class));
final SAMLMetadataContext metadataContext = new SAMLMetadataContext();
final MessageContext messageContext = metadataContext.getSubcontext(MessageContext.class, true);
metadataContext.setRoleDescriptor(withACS);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list