예제 #1
0
  /**
   * Prepare peer entity saml endpoint.
   *
   * @param outboundContext the outbound context
   * @param adaptor the adaptor
   * @throws SamlException the saml exception
   */
  public static void preparePeerEntitySamlEndpointContext(
      final MessageContext outboundContext,
      final SamlRegisteredServiceServiceProviderMetadataFacade adaptor)
      throws SamlException {
    final List<AssertionConsumerService> assertionConsumerServices =
        adaptor.getAssertionConsumerServices();
    if (assertionConsumerServices.isEmpty()) {
      throw new SamlException(
          SamlException.CODE,
          "No assertion consumer service could be found for entity " + adaptor.getEntityId());
    }

    final SAMLPeerEntityContext peerEntityContext =
        outboundContext.getSubcontext(SAMLPeerEntityContext.class, true);
    if (peerEntityContext == null) {
      throw new SamlException(
          SamlException.CODE,
          "SAMLPeerEntityContext could not be defined for entity " + adaptor.getEntityId());
    }

    final SAMLEndpointContext endpointContext =
        peerEntityContext.getSubcontext(SAMLEndpointContext.class, true);
    if (endpointContext == null) {
      throw new SamlException(
          SamlException.CODE,
          "SAMLEndpointContext could not be defined for entity " + adaptor.getEntityId());
    }
    final Endpoint endpoint = assertionConsumerServices.get(0);
    if (StringUtils.isBlank(endpoint.getBinding()) || StringUtils.isBlank(endpoint.getLocation())) {
      throw new SamlException(
          SamlException.CODE,
          "Assertion consumer service does not define a binding or location for "
              + adaptor.getEntityId());
    }
    LOGGER.debug(
        "Configured peer entity endpoint to be [{}] with binding [{}]",
        endpoint.getLocation(),
        endpoint.getBinding());
    endpointContext.setEndpoint(endpoint);
  }
예제 #2
0
  /**
   * Gets chaining metadata resolver for all saml services.
   *
   * @param servicesManager the services manager
   * @param entityID the entity id
   * @param resolver the resolver
   * @return the chaining metadata resolver for all saml services
   * @throws Exception the exception
   */
  public static MetadataResolver getMetadataResolverForAllSamlServices(
      final ServicesManager servicesManager,
      final String entityID,
      final SamlRegisteredServiceCachingMetadataResolver resolver)
      throws Exception {
    final Predicate p = Predicates.instanceOf(SamlRegisteredService.class);
    final Collection<RegisteredService> registeredServices = servicesManager.findServiceBy(p);
    final List<MetadataResolver> resolvers = new ArrayList<>();
    final ChainingMetadataResolver chainingMetadataResolver = new ChainingMetadataResolver();

    for (final RegisteredService registeredService : registeredServices) {
      final SamlRegisteredService samlRegisteredService =
          SamlRegisteredService.class.cast(registeredService);

      final SamlRegisteredServiceServiceProviderMetadataFacade adaptor =
          SamlRegisteredServiceServiceProviderMetadataFacade.get(
              resolver, samlRegisteredService, entityID);
      resolvers.add(adaptor.getMetadataResolver());
    }
    chainingMetadataResolver.setResolvers(resolvers);
    chainingMetadataResolver.setId(entityID);
    chainingMetadataResolver.initialize();
    return chainingMetadataResolver;
  }