[java-shib-attribute] branch main updated: JSPT-108 ServiceableComponent should implement AutoClose
Rod Widdowson
rdw at steadingsoftware.com
Sat Jul 23 10:23:54 UTC 2022
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-shib-attribute.
View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=2cbab794906887fb96570844fd089b709aa7c08a
The following commit(s) were added to refs/heads/main by this push:
new 2cbab7949 JSPT-108 ServiceableComponent should implement AutoClose
2cbab7949 is described below
commit 2cbab794906887fb96570844fd089b709aa7c08a
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Jul 23 11:23:31 2022 +0100
JSPT-108 ServiceableComponent should implement AutoClose
https://shibboleth.atlassian.net/browse/JSPT-108
Exploit the fact of being AutoClose
---
.../filter/context/AttributeFilterContext.java | 8 +------
.../context/AttributeResolutionContext.java | 9 ++------
.../impl/AttributeResolverServiceGaugeSet.java | 25 +++++++--------------
.../resolver/spring/AttributeMapperTest.java | 8 ++-----
.../resolver/spring/AttributeResolverTest.java | 26 ++++------------------
.../impl/AttributeMappingNodeProcessor.java | 24 ++++++--------------
6 files changed, 24 insertions(+), 76 deletions(-)
diff --git a/shib-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterContext.java b/shib-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterContext.java
index d17a84e2f..d0dd77b60 100644
--- a/shib-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterContext.java
+++ b/shib-attribute-filter-api/src/main/java/net/shibboleth/idp/attribute/filter/context/AttributeFilterContext.java
@@ -550,9 +550,7 @@ public final class AttributeFilterContext extends BaseContext {
public void filterAttributes(@Nonnull final ReloadableService<AttributeFilter> attributeFilterService) {
final Logger log = LoggerFactory.getLogger(AttributeFilterContext.class);
- ServiceableComponent<AttributeFilter> component = null;
- try {
- component = attributeFilterService.getServiceableComponent();
+ try (final ServiceableComponent<AttributeFilter> component = attributeFilterService.getServiceableComponent()) {
if (null == component) {
log.error("Error filtering attributes: Invalid Attribute filter configuration");
} else {
@@ -560,10 +558,6 @@ public final class AttributeFilterContext extends BaseContext {
}
} catch (final AttributeFilterException e) {
log.error("Error filtering attributes", e);
- } finally {
- if (null != component) {
- component.unpinComponent();
- }
}
}
diff --git a/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java b/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java
index e05e4a9fc..9ecbf4a38 100644
--- a/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java
+++ b/shib-attribute-resolver-api/src/main/java/net/shibboleth/idp/attribute/resolver/context/AttributeResolutionContext.java
@@ -363,9 +363,8 @@ public final class AttributeResolutionContext extends BaseContext {
public void resolveAttributes(@Nonnull final ReloadableService<AttributeResolver> attributeResolverService) {
final Logger log = LoggerFactory.getLogger(AttributeResolutionContext.class);
- ServiceableComponent<AttributeResolver> component = null;
- try {
- component = attributeResolverService.getServiceableComponent();
+ try (final ServiceableComponent<AttributeResolver> component
+ = attributeResolverService.getServiceableComponent()) {
if (null == component) {
log.error("Error resolving attributes: Invalid Attribute resolver configuration");
} else {
@@ -374,10 +373,6 @@ public final class AttributeResolutionContext extends BaseContext {
}
} catch (final ResolutionException e) {
log.error("Error resolving attributes", e);
- } finally {
- if (null != component) {
- component.unpinComponent();
- }
}
}
}
\ No newline at end of file
diff --git a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverServiceGaugeSet.java b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverServiceGaugeSet.java
index 1863dc87f..d72276aff 100644
--- a/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverServiceGaugeSet.java
+++ b/shib-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/impl/AttributeResolverServiceGaugeSet.java
@@ -63,10 +63,9 @@ public class AttributeResolverServiceGaugeSet extends ReloadableServiceGaugeSet<
new Gauge<Map<String,Instant>>() {
public Map<String,Instant> getValue() {
final Map<String,Instant> mapBuilder = new HashMap<>();
- final ServiceableComponent<AttributeResolver> component =
- getService().getServiceableComponent();
- if (component != null) {
- try {
+ try (final ServiceableComponent<AttributeResolver> component =
+ getService().getServiceableComponent()) {
+ if (component != null) {
final Object resolver = component.getComponent();
if (resolver instanceof AttributeResolverImpl) {
final Collection<DataConnector> connectors =
@@ -84,8 +83,6 @@ public class AttributeResolverServiceGaugeSet extends ReloadableServiceGaugeSet<
log.warn("{}: Injected Service was not for an AttributeResolver ({})",
getLogPrefix(), resolver.getClass());
}
- } finally {
- component.unpinComponent();
}
}
return Map.copyOf(mapBuilder);
@@ -97,10 +94,9 @@ public class AttributeResolverServiceGaugeSet extends ReloadableServiceGaugeSet<
new Gauge<Map<String,Instant>>() {
public Map<String,Instant> getValue() {
final Map<String,Instant> mapBuilder = new HashMap<>();
- final ServiceableComponent<AttributeResolver> component =
- getService().getServiceableComponent();
- if (component != null) {
- try {
+ try (final ServiceableComponent<AttributeResolver> component =
+ getService().getServiceableComponent()) {
+ if (component != null) {
final Object resolver = component.getComponent();
if (resolver instanceof AttributeResolverImpl) {
final Collection<DataConnector> connectors =
@@ -118,8 +114,6 @@ public class AttributeResolverServiceGaugeSet extends ReloadableServiceGaugeSet<
log.warn("{}: Injected Service was not for an AttributeResolver ({})",
getLogPrefix(), resolver.getClass());
}
- } finally {
- component.unpinComponent();
}
}
return Map.copyOf(mapBuilder);
@@ -134,17 +128,14 @@ public class AttributeResolverServiceGaugeSet extends ReloadableServiceGaugeSet<
protected void doInitialize() throws ComponentInitializationException {
super.doInitialize();
- final ServiceableComponent<?> component = getService().getServiceableComponent();
- if (component != null) {
- try {
+ try (final ServiceableComponent<?> component = getService().getServiceableComponent()) {
+ if (component != null) {
if (component.getComponent() instanceof AttributeResolver) {
return;
}
log.error("{}: Injected service was not for an AttributeResolver ({})",
getLogPrefix(), component.getClass());
throw new ComponentInitializationException("Injected service was not for an AttributeResolver");
- } finally {
- component.unpinComponent();
}
}
}
diff --git a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java
index 0ac6db726..d6fd0fecf 100644
--- a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java
+++ b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeMapperTest.java
@@ -87,10 +87,8 @@ public class AttributeMapperTest extends OpenSAMLInitBaseTestCase {
final ReloadableService<AttributeTranscoderRegistry> transcoderRegistry = context.getBean(ReloadableService.class);
- ServiceableComponent<AttributeTranscoderRegistry> serviceableComponent = null;
- try {
- serviceableComponent = transcoderRegistry.getServiceableComponent();
-
+ try (final ServiceableComponent<AttributeTranscoderRegistry> serviceableComponent = transcoderRegistry.getServiceableComponent()){
+
final IdPAttribute idpattr = new IdPAttribute("eduPersonScopedAffiliation");
Collection<TranscodingRule> rulesets = serviceableComponent.getComponent().getTranscodingRules(
@@ -129,8 +127,6 @@ public class AttributeMapperTest extends OpenSAMLInitBaseTestCase {
assertEquals(descs.size(), 1);
assertEquals(descs.get(Locale.CANADA_FRENCH), "Le Color");
- } finally {
- serviceableComponent.unpinComponent();
}
/*
diff --git a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
index 0bd561a90..7c5891459 100644
--- a/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
+++ b/shib-attribute-resolver-spring/src/test/java/net/shibboleth/idp/attribute/resolver/spring/AttributeResolverTest.java
@@ -207,22 +207,17 @@ public class AttributeResolverTest extends OpenSAMLInitBaseTestCase {
attributeResolverService.initialize();
- ServiceableComponent<AttributeResolver> serviceableComponent = null;
final AttributeResolutionContext resolutionContext =
TestSources.createResolutionContext("PETER_THE_PRINCIPAL", "issuer", "recipient");
- try {
- serviceableComponent = attributeResolverService.getServiceableComponent();
+ try (final ServiceableComponent<AttributeResolver> serviceableComponent = attributeResolverService.getServiceableComponent()) {
final AttributeResolver resolver = serviceableComponent.getComponent();
assertEquals(resolver.getId(), "Shibboleth.Resolver");
resolver.resolveAttributes(resolutionContext);
- } finally {
- if (null != serviceableComponent) {
- serviceableComponent.unpinComponent();
- }
}
+
final Map<String, IdPAttribute> resolvedAttributes = resolutionContext.getResolvedIdPAttributes();
log.debug("resolved attributes '{}'", resolvedAttributes);
@@ -324,20 +319,13 @@ public class AttributeResolverTest extends OpenSAMLInitBaseTestCase {
attributeResolverService.initialize();
- ServiceableComponent<AttributeResolver> serviceableComponent = null;
final AttributeResolutionContext resolutionContext =
TestSources.createResolutionContext("PETER_THE_PRINCIPAL", "issuer", "recipient");
- try {
- serviceableComponent = attributeResolverService.getServiceableComponent();
-
+ try (final ServiceableComponent<AttributeResolver> serviceableComponent = attributeResolverService.getServiceableComponent()) {
final AttributeResolver resolver = serviceableComponent.getComponent();
assertEquals(resolver.getId(), "Shibboleth.Resolver");
resolver.resolveAttributes(resolutionContext);
- } finally {
- if (null != serviceableComponent) {
- serviceableComponent.unpinComponent();
- }
}
final Map<String, IdPAttribute> resolvedAttributes = resolutionContext.getResolvedIdPAttributes();
@@ -465,17 +453,11 @@ public class AttributeResolverTest extends OpenSAMLInitBaseTestCase {
final AttributeResolutionContext resolutionContext =
TestSources.createResolutionContext("PETER_THE_PRINCIPAL", "issuer", "recipient");
- ServiceableComponent<AttributeResolver> serviceableComponent = null;
- try {
- serviceableComponent = attributeResolverService.getServiceableComponent();
+ try (final ServiceableComponent<AttributeResolver> serviceableComponent = attributeResolverService.getServiceableComponent()) {
final AttributeResolver resolver = serviceableComponent.getComponent();
assertEquals(resolver.getId(), "MultiFileResolver");
resolver.resolveAttributes(resolutionContext);
- } finally {
- if (null != serviceableComponent) {
- serviceableComponent.unpinComponent();
- }
}
assertNotNull(resolutionContext.getResolvedIdPAttributes().get("eduPersonAffiliation2"));
diff --git a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/impl/AttributeMappingNodeProcessor.java b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/impl/AttributeMappingNodeProcessor.java
index b48acae79..df640f0b5 100644
--- a/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/impl/AttributeMappingNodeProcessor.java
+++ b/shib-saml-attribute-impl/src/main/java/net/shibboleth/idp/saml/attribute/impl/AttributeMappingNodeProcessor.java
@@ -95,22 +95,16 @@ public class AttributeMappingNodeProcessor implements MetadataNodeProcessor {
/** {@inheritDoc} */
@Override public void process(final XMLObject metadataNode) throws FilterException {
-
- ServiceableComponent<AttributeTranscoderRegistry> component = null;
-
- try {
- if (metadataNode instanceof AttributeConsumingService) {
- component = transcoderRegistry.getServiceableComponent();
+
+ if (metadataNode instanceof AttributeConsumingService || metadataNode instanceof EntityDescriptor) {
+ try (final ServiceableComponent<AttributeTranscoderRegistry>
+ component = transcoderRegistry.getServiceableComponent()) {
if (component == null) {
log.error("Attribute transcoding service unavailable");
- } else {
+ }
+ if (metadataNode instanceof AttributeConsumingService) {
handleAttributeConsumingService(component.getComponent(), (AttributeConsumingService) metadataNode);
- }
- } else if (metadataNode instanceof EntityDescriptor) {
- component = transcoderRegistry.getServiceableComponent();
- if (component == null) {
- log.error("Attribute transcoding service unavailable");
- } else {
+ } else if (metadataNode instanceof EntityDescriptor) {
handleEntityAttributes(component.getComponent(), ((EntityDescriptor) metadataNode).getExtensions());
XMLObject parent = metadataNode.getParent();
while (parent instanceof EntitiesDescriptor) {
@@ -119,10 +113,6 @@ public class AttributeMappingNodeProcessor implements MetadataNodeProcessor {
}
}
}
- } finally {
- if (component != null) {
- component.unpinComponent();
- }
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list