@Nullable @Override public Service lookup(@Nonnull final String serviceURL) { ServiceableComponent<ServiceRegistry> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("ServiceRegistry '{}': error looking up service registry: Invalid configuration.", getId()); return null; } return component.getComponent().lookup(serviceURL); } finally { if (null != component) { component.unpinComponent(); } } } }
/** * Get the serviceable component. We do this under interlock and grab the lock on the component. * * @return the <em>pinned</em> component. */ @Override public synchronized ServiceableComponent<T> getServiceableComponent() { if (null == cachedComponent) { return null; } cachedComponent.pinComponent(); return cachedComponent; }
/** {@inheritDoc} */ @Override protected void doDestroy() { final ServiceableComponent<T> oldComponent = cachedComponent; cachedComponent = null; // And tear down. Note that we are synchronized on this right now // and this will grab the lock - but that is OK because the ranking // is to lock this object, then the ServicableComponent. if (null != oldComponent) { oldComponent.unloadComponent(); } super.doDestroy(); }
service.pinComponent(); final T theComponent = service.getComponent(); service.unpinComponent(); service.unloadComponent(); throw new ServiceException("Class was not the same or a superclass of configured class"); oldComponent = cachedComponent; cachedComponent = service; service.unpinComponent(); oldComponent.unloadComponent();
/** {@inheritDoc} */ @Override protected void doInitialize() throws ComponentInitializationException { super.doInitialize(); final ServiceableComponent component = getService().getServiceableComponent(); if (component != null) { try { if (component instanceof MetadataResolver) { return; } } finally { component.unpinComponent(); } } throw new ComponentInitializationException("Injected service was null or not a MetadataResolver"); }
/** {@inheritDoc} */ @Override protected void doInitialize() throws ComponentInitializationException { super.doInitialize(); final ServiceableComponent component = getService().getServiceableComponent(); if (component != null) { try { if (component instanceof AttributeResolver) { return; } } finally { component.unpinComponent(); } } throw new ComponentInitializationException("Injected service was null or not an AttributeResolver"); }
/** * Helper method to invoke an AttributeResolver service using this context. * * @param attributeResolverService the service to invoke * * @since 3.3.0 */ public void resolveAttributes(@Nonnull final ReloadableService<AttributeResolver> attributeResolverService) { final Logger log = LoggerFactory.getLogger(AttributeResolutionContext.class); ServiceableComponent<AttributeResolver> component = null; try { component = attributeResolverService.getServiceableComponent(); if (null == component) { log.error("Error resolving attributes: Invalid Attribute resolver configuration"); } else { final AttributeResolver attributeResolver = component.getComponent(); attributeResolver.resolveAttributes(this); } } catch (final ResolutionException e) { log.error("Error resolving attributes", e); } finally { if (null != component) { component.unpinComponent(); } } } }
/** {@inheritDoc} */ @Nonnull public Iterable<Credential> resolve(@Nullable final CriteriaSet criteria) throws ResolverException { ServiceableComponent<RelyingPartyConfigurationResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("EncryptionCredentialsResolver '{}': error looking up relying party configuration service:" + " Invalid configuration.", getId()); } else { final RelyingPartyConfigurationResolver resolver = component.getComponent(); if (resolver instanceof DefaultRelyingPartyConfigurationResolver) { log.trace("Saw expected instance of DefaultRelyingPartyConfigurationResolver"); return ((DefaultRelyingPartyConfigurationResolver)resolver).getEncryptionCredentials(); } else { log.trace("Did NOT see expected instance of DefaultRelyingPartyConfigurationResolver"); return Collections.emptyList(); } } } finally { if (null != component) { component.unpinComponent(); } } return null; }
/** {@inheritDoc} */ @Nonnull public Iterable<Credential> resolve(@Nullable final CriteriaSet criteria) throws ResolverException { ServiceableComponent<RelyingPartyConfigurationResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("SigningCredentialsResolver '{}': error looking up relying party configuration service:" + " Invalid configuration.", getId()); } else { final RelyingPartyConfigurationResolver resolver = component.getComponent(); if (resolver instanceof DefaultRelyingPartyConfigurationResolver) { log.trace("Saw expected instance of DefaultRelyingPartyConfigurationResolver"); return ((DefaultRelyingPartyConfigurationResolver)resolver).getSigningCredentials(); } else { log.trace("Did NOT see expected instance of DefaultRelyingPartyConfigurationResolver"); return Collections.emptyList(); } } } finally { if (null != component) { component.unpinComponent(); } } return null; }
/** {@inheritDoc} */ @Override @Nullable public NameIdentifier generate(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull @NotEmpty final String format) throws SAMLException { ServiceableComponent<NameIdentifierGenerationService> component = null; try { component = generatorService.getServiceableComponent(); if (component == null) { throw new SAMLException("Invalid NameIdentifierGenerationService configuration"); } return component.getComponent().getSAML1NameIdentifierGenerator().generate(profileRequestContext, format); } finally { if (null != component) { component.unpinComponent(); } } }
/** {@inheritDoc} */ @Override public MetadataFilter getMetadataFilter() { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ServiceableComponent<MetadataResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("RelyingPartyMetadataProvider '{}': Error accessing underlying metadata source: " + "Invalid configuration.", getId()); } else { final MetadataResolver resolver = component.getComponent(); return resolver.getMetadataFilter(); } } finally { if (null != component) { component.unpinComponent(); } } throw new IllegalAccessError("Could not find a valid MetadataResolver"); }
/** {@inheritDoc} */ @Override @Nullable public NameID generate(@Nonnull final ProfileRequestContext profileRequestContext, @Nonnull @NotEmpty final String format) throws SAMLException { ServiceableComponent<NameIdentifierGenerationService> component = null; try { component = generatorService.getServiceableComponent(); if (component == null) { throw new SAMLException("Invalid NameIdentifierGenerationService configuration"); } return component.getComponent().getSAML2NameIDGenerator().generate(profileRequestContext, format); } finally { if (null != component) { component.unpinComponent(); } } }
public Map<String,DateTime> getValue() { final Builder mapBuilder = ImmutableMap.<String,DateTime>builder(); final ServiceableComponent<MetadataResolver> component = getService().getServiceableComponent(); if (component != null) { try { for (final MetadataResolver resolver : getMetadataResolvers(component.getComponent())) { if (resolver instanceof RefreshableMetadataResolver && ((RefreshableMetadataResolver) resolver).getLastUpdate() != null) { mapBuilder.put(resolver.getId(), ((RefreshableMetadataResolver) resolver).getLastUpdate()); } } } finally { component.unpinComponent(); } } return mapBuilder.build(); } });
public Map<String,DateTime> getValue() { final Builder mapBuilder = ImmutableMap.<String,DateTime>builder(); final ServiceableComponent<MetadataResolver> component = getService().getServiceableComponent(); if (component != null) { try { for (final MetadataResolver resolver : getMetadataResolvers(component.getComponent())) { if (resolver instanceof RefreshableMetadataResolver && ((RefreshableMetadataResolver) resolver).getLastRefresh() != null) { mapBuilder.put(resolver.getId(), ((RefreshableMetadataResolver) resolver).getLastRefresh()); } } } finally { component.unpinComponent(); } } return mapBuilder.build(); } });
/** {@inheritDoc} */ @Override public SecurityConfiguration getDefaultSecurityConfiguration(final String profileId) { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ServiceableComponent<RelyingPartyConfigurationResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("RelyingPartyResolver '{}': error looking up default security config:" + " Invalid configuration.", getId()); } else { final RelyingPartyConfigurationResolver resolver = component.getComponent(); return resolver.getDefaultSecurityConfiguration(profileId); } } finally { if (null != component) { component.unpinComponent(); } } return null; }
/** {@inheritDoc} */ @Override @Nullable public RelyingPartyConfiguration resolveSingle(@Nullable final ProfileRequestContext context) throws ResolverException { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ServiceableComponent<RelyingPartyConfigurationResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("RelyingPartyResolver '{}': error looking up Relying Party: Invalid configuration.", getId()); } else { final RelyingPartyConfigurationResolver resolver = component.getComponent(); return resolver.resolveSingle(context); } } catch (final ResolverException e) { log.error("RelyingPartyResolver '{}': error in resolution", getId(), e); } finally { if (null != component) { component.unpinComponent(); } } return null; }
public Map<String,DateTime> getValue() { final Builder mapBuilder = ImmutableMap.<String,DateTime>builder(); final ServiceableComponent<AttributeResolver> component = getService().getServiceableComponent(); if (component != null) { try { final AttributeResolver resolver = component.getComponent(); final Collection<DataConnector> connectors = resolver.getDataConnectors().values(); for (final DataConnector connector: connectors) { if (connector instanceof DataConnectorEx) { final long lastFail = ((DataConnectorEx) connector).getLastFail(); if (lastFail > 0) { mapBuilder.put(connector.getId(), new DateTime(lastFail)); } } } } finally { component.unpinComponent(); } } return mapBuilder.build(); } });
/** {@inheritDoc} */ @Override public boolean isRequireValidMetadata() { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ServiceableComponent<MetadataResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("RelyingPartyMetadataProvider '{}': Error accessing underlying metadata source: " + "Invalid configuration.", getId()); } else { final MetadataResolver resolver = component.getComponent(); return resolver.isRequireValidMetadata(); } } finally { if (null != component) { component.unpinComponent(); } } throw new IllegalAccessError("Could not find a valid MetadataResolver"); }
/** {@inheritDoc} */ @Override @Nonnull public Iterable<EntityDescriptor> resolve(final CriteriaSet criteria) throws ResolverException { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ServiceableComponent<MetadataResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("RelyingPartyMetadataProvider '{}': Error accessing underlying metadata source: " + "Invalid configuration.", getId()); } else { final MetadataResolver resolver = component.getComponent(); return resolver.resolve(criteria); } } catch (final ResolverException e) { log.error("RelyingPartyMetadataProvider '{}': Error during resolution", getId(), e); } finally { if (null != component) { component.unpinComponent(); } } return Collections.EMPTY_SET; }
/** {@inheritDoc} */ @Override @Nonnull @NonnullElements public Iterable<RelyingPartyConfiguration> resolve( @Nullable final ProfileRequestContext context) throws ResolverException { ComponentSupport.ifNotInitializedThrowUninitializedComponentException(this); ServiceableComponent<RelyingPartyConfigurationResolver> component = null; try { component = service.getServiceableComponent(); if (null == component) { log.error("RelyingPartyResolver '{}': error looking up Relying Party: Invalid configuration.", getId()); } else { final RelyingPartyConfigurationResolver resolver = component.getComponent(); final List<RelyingPartyConfiguration> results = new ArrayList<>(); for (final RelyingPartyConfiguration result : resolver.resolve(context)) { results.add(result); } return results; } } catch (final ResolverException e) { log.error("RelyingPartyResolver '{}': error in resolution", getId(), e); } finally { if (null != component) { component.unpinComponent(); } } return Collections.emptySet(); }