Exemplo n.º 1
0
  protected IDPSSODescriptorType getIdpMetadataFromFile(SPType configuration) {
    InputStream is = this.servletContext.getResourceAsStream(configuration.getIdpMetadataFile());
    if (is == null) {
      return null;
    }

    Object metadata = null;
    try {
      Document samlDocument = DocumentUtil.getDocument(is);
      SAMLParser parser = new SAMLParser();
      metadata = parser.parse(DocumentUtil.getNodeAsStream(samlDocument));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    IDPSSODescriptorType idpSSO = null;
    if (metadata instanceof EntitiesDescriptorType) {
      EntitiesDescriptorType entities = (EntitiesDescriptorType) metadata;
      idpSSO = handleMetadata(entities);
    } else {
      idpSSO = handleMetadata((EntityDescriptorType) metadata);
    }
    if (idpSSO == null) {
      logger.samlSPUnableToGetIDPDescriptorFromMetadata();
      return idpSSO;
    }

    return idpSSO;
  }
Exemplo n.º 2
0
  private void processIdPMetadata(SPType spConfiguration) {
    IDPSSODescriptorType idpssoDescriptorType = null;

    if (isNotNull(spConfiguration.getIdpMetadataFile())) {
      idpssoDescriptorType = getIdpMetadataFromFile(spConfiguration);
    } else {
      idpssoDescriptorType = getIdpMetadataFromProvider(spConfiguration);
    }

    if (idpssoDescriptorType != null) {
      List<EndpointType> endpoints = idpssoDescriptorType.getSingleSignOnService();
      for (EndpointType endpoint : endpoints) {
        String endpointBinding = endpoint.getBinding().toString();
        if (endpointBinding.contains("HTTP-POST")) {
          endpointBinding = "POST";
        } else if (endpointBinding.contains("HTTP-Redirect")) {
          endpointBinding = "REDIRECT";
        }
        if (spConfiguration.getBindingType().equals(endpointBinding)) {
          spConfiguration.setIdentityURL(endpoint.getLocation().toString());
          break;
        }
      }

      this.idpMetadata = idpssoDescriptorType;
    }
  }