final ReadWriteLock rwlock = keyAuthorityObjectMetadata.getReadWriteLock(); keyAuthorityObjectMetadata.get(PKIXValidationInformation.class); if (!cachedPKIXInfo.isEmpty()) { log.debug("Resolved cached PKIXValidationInformation from KeyAuthority object metadata"); keyAuthorityObjectMetadata.get(PKIXValidationInformation.class); if (!cachedPKIXInfo.isEmpty()) { log.debug("PKIXValidationInformation was resolved and cached by another thread " if (pkixInfo != null) { keyAuthorityObjectMetadata.put(pkixInfo);
/** * Creates a new instance that wraps the given CAS service. * * @param service CAS service metadata object. */ public ServiceEntityDescriptor(@Nonnull final Service service) { svc = Constraint.isNotNull(service, "Service cannot be null"); objectMetadata = new LockableClassToInstanceMultiMap<>(true); if (StringSupport.trimOrNull(service.getGroup()) != null) { objectMetadata.put(new EntityGroupName(service.getGroup())); } }
/** {@inheritDoc} */ public void releaseDOM() { log.trace("Releasing cached DOM reprsentation for {}", getElementQName()); setDOM(null); if (getObjectMetadata().containsKey(XMLObjectSource.class)) { log.trace("Releasing cached XMLObjectSource for {}", getElementQName()); getObjectMetadata().remove(XMLObjectSource.class); } }
/** {@inheritDoc} */ public T load(String key) throws IOException { File file = buildFile(key); if (!file.exists()) { log.debug("Target file with key '{}' does not exist, path: {}", key, file.getAbsolutePath()); return null; } try (FileInputStream fis = new FileInputStream(file)) { byte[] source = ByteStreams.toByteArray(fis); try (ByteArrayInputStream bais = new ByteArrayInputStream(source)) { XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, bais); xmlObject.getObjectMetadata().put(new XMLObjectSource(source)); //TODO via ctor, etc, does caller need to supply a Class so we can can test and throw an IOException, // rather than an unchecked ClassCastException? return (T) xmlObject; } catch (XMLParserException|UnmarshallingException e) { throw new IOException(String.format("Error loading file from path: %s", file.getAbsolutePath()), e); } } }
final ReadWriteLock rwlock = keyDescriptorObjectMetadata.getReadWriteLock(); final List<Credential> cachedCreds = keyDescriptorObjectMetadata.get(Credential.class); if (!cachedCreds.isEmpty()) { log.debug("Resolved cached credentials from KeyDescriptor object metadata"); final List<Credential> cachedCreds = keyDescriptorObjectMetadata.get(Credential.class); if (!cachedCreds.isEmpty()) { log.debug("Credentials were resolved and cached by another thread " keyDescriptorObjectMetadata.putAll(newCreds);
/** {@inheritDoc} */ @Override public boolean apply(@Nullable final EntityDescriptor input) { if (input != null) { for (final EntityGroupName group : input.getObjectMetadata().get(EntityGroupName.class)) { if (groupNames.contains(group.getName())) { return true; } } } return false; }
/** * Retrieves validation information from the provided role descriptor. * * @param roleDescriptor the role descriptor from which to resolve information. * @param accumulator accumulator of PKIX validation information to return * @throws ResolverException thrown if the key, certificate, or CRL information is represented in an unsupported * format * */ protected void resolvePKIXInfo(final Collection<PKIXValidationInformation> accumulator, final RoleDescriptor roleDescriptor) throws ResolverException { if (roleDescriptor.getParent() instanceof EntityDescriptor) { final EntityDescriptor entityDescriptor = (EntityDescriptor) roleDescriptor.getParent(); resolvePKIXInfo(accumulator, entityDescriptor.getExtensions()); // These would have been cached on the EntityDescriptor by another mechanism, // for example via pre-processing by the MetadataResolver. final LockableClassToInstanceMultiMap<Object> entityDescriptorObjectMetadata = entityDescriptor.getObjectMetadata(); final ReadWriteLock rwlock = entityDescriptorObjectMetadata.getReadWriteLock(); try { rwlock.readLock().lock(); accumulator.addAll(entityDescriptorObjectMetadata.get(PKIXValidationInformation.class)); } finally { rwlock.readLock().unlock(); } } }
/** * Handle an {@link EntityDescriptor}. * * @param entityDescriptor the entity descriptor being processed * * @throws FilterException if there is a fatal error during processing */ protected void handleEntityDescriptor(final EntityDescriptor entityDescriptor) throws FilterException { XMLObject currentParent = entityDescriptor.getParent(); while (currentParent != null) { if (currentParent instanceof EntitiesDescriptor) { for (final XMLObject keyAuthority : getKeyAuthorities((EntitiesDescriptor) currentParent)) { entityDescriptor.getObjectMetadata().putAll(keyAuthority.getObjectMetadata() .get(PKIXValidationInformation.class)); } } currentParent = currentParent.getParent(); } }
/** * Instantiates a new client entity descriptor. * * @param clientIdentifier the client identifier */ public ClientEntityDescriptor(@Nonnull final String clientIdentifier) { this.clientId = Constraint.isNotNull(clientIdentifier, "Client cannot be null"); this.objectMetadata = new LockableClassToInstanceMultiMap(true); }
/** {@inheritDoc}*/ protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) { if (acsContext == null) { log.trace("{} AttributeConsumingServiceContext not found", getLogPrefix()); return; } final AttributeConsumingService acs = acsContext.getAttributeConsumingService(); if (acs == null) { log.trace("{} no AttributeConsumingService to map", getLogPrefix()); return; } if (acs.getRequestAttributes().isEmpty() || acs.getObjectMetadata().containsKey(AttributesMapContainer.class) || acs.getParent() != null) { log.trace("{} skipping mapping for AttributeConsumingService", getLogPrefix()); // Nothing to map, already mapped, or attached to metadata (and hence already scanned) return; } try { final AttributeMappingNodeProcessor processor = new AttributeMappingNodeProcessor(attributeResolverService); log.debug("{} mapping requested Attributes for generated AttributeConsumingService", getLogPrefix()); processor.process(acs); } catch (final FilterException e) { log.error("{} Error mapping Attributesresponding to request", getLogPrefix(), e); ActionSupport.buildEvent(profileRequestContext, EventIds.RUNTIME_EXCEPTION); } }
/** {@inheritDoc} */ public T load(String key) throws IOException { File file = buildFile(key); if (!file.exists()) { log.debug("Target file with key '{}' does not exist, path: {}", key, file.getAbsolutePath()); return null; } try (FileInputStream fis = new FileInputStream(file)) { byte[] source = ByteStreams.toByteArray(fis); try (ByteArrayInputStream bais = new ByteArrayInputStream(source)) { XMLObject xmlObject = XMLObjectSupport.unmarshallFromInputStream(parserPool, bais); xmlObject.getObjectMetadata().put(new XMLObjectSource(source)); //TODO via ctor, etc, does caller need to supply a Class so we can can test and throw an IOException, // rather than an unchecked ClassCastException? return (T) xmlObject; } catch (XMLParserException|UnmarshallingException e) { throw new IOException(String.format("Error loading file from path: %s", file.getAbsolutePath()), e); } } }
/** * Get the map of requested attributes from the profile request context. * * @param prc the profile request context * @return the map of requested attributes or <code>null</code> */ @Nullable protected Multimap<String, IdPRequestedAttribute> getRequestedAttributes(@Nullable final ProfileRequestContext prc) { if (prc != null) { final SAMLMetadataContext metadataContext = metadataContextLookupStrategy.apply(prc); if (metadataContext != null) { final AttributeConsumingService acs = acsLookupStrategy.apply(metadataContext); if (acs != null) { final List<AttributesMapContainer> maps = acs.getObjectMetadata().get(AttributesMapContainer.class); if (maps != null && !maps.isEmpty()) { if (maps.size() > 1) { log.warn("More than one set of mapped attributes found, using the first."); } return maps.get(0).get(); } } } } return null; }
/** * Constructor. * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents * @param namespacePrefix the prefix for the given namespace */ protected AbstractXMLObject(@Nullable final String namespaceURI, @Nonnull @NotEmpty final String elementLocalName, @Nullable final String namespacePrefix) { nsManager = new NamespaceManager(this); idIndex = new IDIndex(this); elementQname = QNameSupport.constructQName(namespaceURI, elementLocalName, namespacePrefix); if(namespaceURI != null){ setElementNamespacePrefix(namespacePrefix); } objectMetadata = new LockableClassToInstanceMultiMap<>(true); }
/** * Look inside the {@link AttributeConsumingService} for any {@link RequestedAttribute}s and map them. * * @param acs the {@link AttributeConsumingService} to look at */ //CheckStyle: ReturnCount OFF private void handleAttributeConsumingService(final AttributeConsumingService acs) { final List<RequestedAttribute> requestedAttributes = acs.getRequestAttributes(); final RequestedAttributesMapper mapper = getRequestedAttributesMapper(); if (null == requestedAttributes || requestedAttributes.isEmpty() || null == mapper) { return; } final Multimap<String, IdPRequestedAttribute> maps = mapper.mapAttributes(requestedAttributes); if (null == maps || maps.isEmpty()) { return; } acs.getObjectMetadata().put(new AttributesMapContainer<>(maps)); } //CheckStyle: ReturnCount ON
/** {@inheritDoc} */ public void save(String key, T xmlObject, boolean overwrite) throws IOException { if (!overwrite && exists(key)) { throw new IOException( String.format("Target file already exists for key '%s' and overwrite not indicated", key)); } File file = buildFile(key); try (FileOutputStream fos = new FileOutputStream(file)) { List<XMLObjectSource> sources = xmlObject.getObjectMetadata().get(XMLObjectSource.class); if (sources.size() == 1) { log.debug("XMLObject contained 1 XMLObjectSource instance, persisting existing byte[]"); XMLObjectSource source = sources.get(0); fos.write(source.getObjectSource()); } else { log.debug("XMLObject contained {} XMLObjectSource instances, persisting marshalled object", sources.size()); try { XMLObjectSupport.marshallToOutputStream(xmlObject, fos); } catch (MarshallingException e) { throw new IOException(String.format("Error saving target file: %s", file.getAbsolutePath()), e); } } fos.flush(); } }
/** {@inheritDoc} */ public void releaseDOM() { log.trace("Releasing cached DOM reprsentation for {}", getElementQName()); setDOM(null); if (getObjectMetadata().containsKey(XMLObjectSource.class)) { log.trace("Releasing cached XMLObjectSource for {}", getElementQName()); getObjectMetadata().remove(XMLObjectSource.class); } }
/** * Constructor. * * @param namespaceURI the namespace the element is in * @param elementLocalName the local name of the XML element this Object represents * @param namespacePrefix the prefix for the given namespace */ protected AbstractXMLObject(@Nullable final String namespaceURI, @Nonnull @NotEmpty final String elementLocalName, @Nullable final String namespacePrefix) { nsManager = new NamespaceManager(this); idIndex = new IDIndex(this); elementQname = QNameSupport.constructQName(namespaceURI, elementLocalName, namespacePrefix); if(namespaceURI != null){ setElementNamespacePrefix(namespacePrefix); } objectMetadata = new LockableClassToInstanceMultiMap<>(true); }
try (ByteArrayInputStream bais = new ByteArrayInputStream(source)) { XMLObject xmlObject = unmarshallMetadata(bais); xmlObject.getObjectMetadata().put(new XMLObjectSource(source)); return xmlObject;
/** {@inheritDoc} */ public void save(String key, T xmlObject, boolean overwrite) throws IOException { if (!overwrite && exists(key)) { throw new IOException( String.format("Target file already exists for key '%s' and overwrite not indicated", key)); } File file = buildFile(key); try (FileOutputStream fos = new FileOutputStream(file)) { List<XMLObjectSource> sources = xmlObject.getObjectMetadata().get(XMLObjectSource.class); if (sources.size() == 1) { log.debug("XMLObject contained 1 XMLObjectSource instance, persisting existing byte[]"); XMLObjectSource source = sources.get(0); fos.write(source.getObjectSource()); } else { log.debug("XMLObject contained {} XMLObjectSource instances, persisting marshalled object", sources.size()); try { XMLObjectSupport.marshallToOutputStream(xmlObject, fos); } catch (MarshallingException e) { throw new IOException(String.format("Error saving target file: %s", file.getAbsolutePath()), e); } } fos.flush(); } }
return; entity.getObjectMetadata().put(new AttributesMapContainer<>(maps));