[java-identity-provider] branch master updated: Fix metadata-driven bean lookup to use enclosing Spring context.
Scott Cantor
cantor.2 at osu.edu
Thu Sep 20 21:31:53 EDT 2018
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=a2c5dcf425c419e03e064bd793f0faba6ff28325
The following commit(s) were added to refs/heads/master by this push:
new a2c5dcf Fix metadata-driven bean lookup to use enclosing Spring context.
a2c5dcf is described below
commit a2c5dcf425c419e03e064bd793f0faba6ff28325
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Thu Sep 20 21:31:47 2018 -0400
Fix metadata-driven bean lookup to use enclosing Spring context.
---
.../config/BeanConfigurationLookupStrategy.java | 51 ++++++++++------------
1 file changed, 24 insertions(+), 27 deletions(-)
diff --git a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/BeanConfigurationLookupStrategy.java b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/BeanConfigurationLookupStrategy.java
index 3e874cd..f2bb6cb 100644
--- a/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/BeanConfigurationLookupStrategy.java
+++ b/idp-saml-api/src/main/java/net/shibboleth/idp/saml/profile/config/BeanConfigurationLookupStrategy.java
@@ -30,9 +30,9 @@ import org.opensaml.saml.saml2.core.Attribute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
-import org.springframework.webflow.execution.RequestContext;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
-import net.shibboleth.idp.profile.context.SpringRequestContext;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullAfterInit;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.component.ComponentSupport;
@@ -48,11 +48,15 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
*
* @since 3.4.0
*/
-public class BeanConfigurationLookupStrategy<T> extends AbstractMetadataDrivenConfigurationLookupStrategy<T> {
+public class BeanConfigurationLookupStrategy<T> extends AbstractMetadataDrivenConfigurationLookupStrategy<T>
+ implements ApplicationContextAware {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(BeanConfigurationLookupStrategy.class);
+ /** Enclosing Spring context. */
+ @Nullable private ApplicationContext applicationContext;
+
/** Type of bean to return. */
@NonnullAfterInit private Class<T> propertyType;
@@ -71,14 +75,21 @@ public class BeanConfigurationLookupStrategy<T> extends AbstractMetadataDrivenCo
propertyType = Constraint.isNotNull(type, "Property type cannot be null");
}
-
+
+ /** {@inheritDoc} */
+ public void setApplicationContext(final ApplicationContext context) throws BeansException {
+ ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
+
+ applicationContext = context;
+ }
+
/** {@inheritDoc} */
@Override
protected void doInitialize() throws ComponentInitializationException {
super.doInitialize();
- if (propertyType == null) {
- throw new ComponentInitializationException("Property type cannot be null");
+ if (propertyType == null || applicationContext == null) {
+ throw new ComponentInitializationException("Property type and Spring ApplicationContext cannot be null");
}
}
@@ -94,19 +105,17 @@ public class BeanConfigurationLookupStrategy<T> extends AbstractMetadataDrivenCo
}
log.debug("Converting tag '{}' to Bean property of tyoe '{}'", tag.getName(), propertyType.getSimpleName());
- return xmlObjectToBean(profileRequestContext, values.get(0));
+ return xmlObjectToBean(values.get(0));
}
/**
* Convert an XMLObject to a Spring bean reference if the type is supported.
*
- * @param profileRequestContext current profile request context
* @param object object to convert
*
* @return the converted value, or null
*/
- @Nullable private T xmlObjectToBean(@Nullable final ProfileRequestContext profileRequestContext,
- @Nonnull final XMLObject object) {
+ @Nullable private T xmlObjectToBean(@Nonnull final XMLObject object) {
String value = null;
if (object instanceof XSString) {
value = ((XSString) object).getValue();
@@ -118,24 +127,12 @@ public class BeanConfigurationLookupStrategy<T> extends AbstractMetadataDrivenCo
}
if (value != null) {
- if (profileRequestContext != null) {
- final SpringRequestContext springContext =
- profileRequestContext.getSubcontext(SpringRequestContext.class);
- if (springContext != null) {
- final RequestContext requestContext = springContext.getRequestContext();
- if (requestContext != null) {
- try {
- return requestContext.getActiveFlow().getApplicationContext().getBean(value, propertyType);
- } catch (final BeansException e) {
- log.error("Error locating appropriately typed bean named {}", value, e);
- return null;
- }
- }
- }
+ try {
+ return applicationContext.getBean(value, propertyType);
+ } catch (final BeansException e) {
+ log.error("Error locating appropriately typed bean named {}", value, e);
+ return null;
}
-
- log.error("Unable to access Spring ApplicationContext to search for bean reference");
- return null;
}
log.error("Unsupported conversion to Spring bean from XMLObject type ({})", object.getClass().getName());
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list