Search in sources :

Example 6 with Endpoint

use of org.opensaml.saml2.metadata.Endpoint in project pac4j by pac4j.

the class SAML2LogoutValidator method validateDestinationEndpoint.

protected void validateDestinationEndpoint(final LogoutResponse logoutResponse, final SAML2MessageContext context) {
    final List<String> expected = new ArrayList<>();
    if (StringUtils.isBlank(this.expectedDestination)) {
        final Endpoint endpoint = Objects.requireNonNull(context.getSPSSODescriptor().getSingleLogoutServices().get(0));
        if (endpoint.getLocation() != null) {
            expected.add(endpoint.getLocation());
        }
        if (endpoint.getResponseLocation() != null) {
            expected.add(endpoint.getResponseLocation());
        }
    } else {
        expected.add(this.expectedDestination);
    }
    final boolean isDestinationMandatory = context.getSAML2Configuration().isResponseDestinationAttributeMandatory();
    verifyEndpoint(expected, logoutResponse.getDestination(), isDestinationMandatory);
}
Also used : Endpoint(org.opensaml.saml.saml2.metadata.Endpoint) ArrayList(java.util.ArrayList)

Example 7 with Endpoint

use of org.opensaml.saml2.metadata.Endpoint in project service-authorization by reportportal.

the class NonAliasHostedServiceProviderService method authenticationRequest.

@Override
public AuthenticationRequest authenticationRequest(IdentityProviderMetadata idp) {
    ExternalIdentityProviderConfiguration configuration = getIdentityProviderConfigurationForMetadata(idp);
    final URI authnBinding = configuration.getAuthenticationRequestBinding();
    Binding preferredBinding = authnBinding == null ? Binding.REDIRECT : Binding.fromUrn(authnBinding);
    Endpoint endpoint = getPreferredEndpoint(idp.getIdentityProvider().getSingleSignOnService(), preferredBinding, 0);
    ServiceProviderMetadata sp = getMetadata();
    AuthenticationRequest request = new AuthenticationRequest().setId("ARQ" + UUID.randomUUID().toString().substring(1)).setIssueInstant(new DateTime(getClock().millis())).setForceAuth(Boolean.FALSE).setPassive(Boolean.FALSE).setBinding(endpoint.getBinding()).setAssertionConsumerService(getPreferredEndpoint(sp.getServiceProvider().getAssertionConsumerService(), null, -1)).setIssuer(new Issuer().setValue(sp.getEntityId())).setDestination(endpoint);
    if (sp.getServiceProvider().isAuthnRequestsSigned()) {
        request.setSigningKey(sp.getSigningKey(), sp.getAlgorithm(), sp.getDigest());
    }
    return authenticationRequestEnhancer.enhance(request);
}
Also used : Binding(org.springframework.security.saml.saml2.metadata.Binding) ServiceProviderMetadata(org.springframework.security.saml.saml2.metadata.ServiceProviderMetadata) Endpoint(org.springframework.security.saml.saml2.metadata.Endpoint) Issuer(org.springframework.security.saml.saml2.authentication.Issuer) AuthenticationRequest(org.springframework.security.saml.saml2.authentication.AuthenticationRequest) URI(java.net.URI) DateTime(org.joda.time.DateTime) ExternalIdentityProviderConfiguration(org.springframework.security.saml.provider.service.config.ExternalIdentityProviderConfiguration)

Example 8 with Endpoint

use of org.opensaml.saml2.metadata.Endpoint in project cas by apereo.

the class SamlIdPUtils method preparePeerEntitySamlEndpointContext.

/**
 * Prepare peer entity saml endpoint.
 *
 * @param outboundContext the outbound context
 * @param adaptor         the adaptor
 * @param binding         the binding
 * @throws SamlException the saml exception
 */
public static void preparePeerEntitySamlEndpointContext(final MessageContext outboundContext, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final String binding) throws SamlException {
    if (!adaptor.containsAssertionConsumerServices()) {
        throw new SamlException("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("SAMLPeerEntityContext could not be defined for entity " + adaptor.getEntityId());
    }
    peerEntityContext.setEntityId(adaptor.getEntityId());
    final SAMLEndpointContext endpointContext = peerEntityContext.getSubcontext(SAMLEndpointContext.class, true);
    if (endpointContext == null) {
        throw new SamlException("SAMLEndpointContext could not be defined for entity " + adaptor.getEntityId());
    }
    final Endpoint endpoint = adaptor.getAssertionConsumerService(binding);
    if (StringUtils.isBlank(endpoint.getBinding()) || StringUtils.isBlank(endpoint.getLocation())) {
        throw new SamlException("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);
}
Also used : SAMLEndpointContext(org.opensaml.saml.common.messaging.context.SAMLEndpointContext) Endpoint(org.opensaml.saml.saml2.metadata.Endpoint) SAMLPeerEntityContext(org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext)

Example 9 with Endpoint

use of org.opensaml.saml2.metadata.Endpoint in project pac4j by pac4j.

the class SAML2DefaultResponseValidator method isValidBearerSubjectConfirmationData.

/**
 * Validate Bearer subject confirmation data
 * - notBefore
 * - NotOnOrAfter
 * - recipient
 *
 * @param data    the data
 * @param context the context
 * @return true if all Bearer subject checks are passing
 */
protected final boolean isValidBearerSubjectConfirmationData(final SubjectConfirmationData data, final SAML2MessageContext context) {
    if (data == null) {
        logger.debug("SubjectConfirmationData cannot be null for Bearer confirmation");
        return false;
    }
    if (data.getNotBefore() != null) {
        logger.debug("SubjectConfirmationData notBefore must be null for Bearer confirmation");
        return false;
    }
    if (data.getNotOnOrAfter() == null) {
        logger.debug("SubjectConfirmationData notOnOrAfter cannot be null for Bearer confirmation");
        return false;
    }
    if (data.getNotOnOrAfter().plusSeconds(acceptedSkew).isBeforeNow()) {
        logger.debug("SubjectConfirmationData notOnOrAfter is too old");
        return false;
    }
    try {
        if (data.getRecipient() == null) {
            logger.debug("SubjectConfirmationData recipient cannot be null for Bearer confirmation");
            return false;
        } else {
            final Endpoint endpoint = context.getSAMLEndpointContext().getEndpoint();
            if (endpoint == null) {
                logger.warn("No endpoint was found in the SAML endpoint context");
                return false;
            }
            final URI recipientUri = new URI(data.getRecipient());
            final URI appEndpointUri = new URI(endpoint.getLocation());
            if (!UriUtils.urisEqualAfterPortNormalization(recipientUri, appEndpointUri)) {
                logger.debug("SubjectConfirmationData recipient {} does not match SP assertion consumer URL, found. " + "SP ACS URL from context: {}", recipientUri, appEndpointUri);
                return false;
            }
        }
    } catch (URISyntaxException use) {
        logger.error("Unable to check SubjectConfirmationData recipient, a URI has invalid syntax.", use);
        return false;
    }
    return true;
}
Also used : Endpoint(org.opensaml.saml.saml2.metadata.Endpoint) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 10 with Endpoint

use of org.opensaml.saml2.metadata.Endpoint in project MaxKey by dromara.

the class EndpointGenerator method generateEndpoint.

public Endpoint generateEndpoint(String location, String responseLocation, QName service) {
    logger.debug("end point service: {}", service);
    logger.debug("end point location: {}", location);
    logger.debug("end point responseLocation: {}", responseLocation);
    Endpoint samlEndpoint;
    if (null == service) {
        service = AssertionConsumerService.DEFAULT_ELEMENT_NAME;
    }
    samlEndpoint = new AssertionConsumerServiceBuilder().buildObject(service);
    samlEndpoint.setLocation(location);
    // this does not have to be set
    if (StringUtils.isNotEmpty(responseLocation)) {
        samlEndpoint.setResponseLocation(responseLocation);
    }
    return samlEndpoint;
}
Also used : Endpoint(org.opensaml.saml2.metadata.Endpoint) AssertionConsumerServiceBuilder(org.opensaml.saml2.metadata.impl.AssertionConsumerServiceBuilder)

Aggregations

Endpoint (org.opensaml.saml.saml2.metadata.Endpoint)6 URI (java.net.URI)3 Endpoint (org.opensaml.saml2.metadata.Endpoint)3 URISyntaxException (java.net.URISyntaxException)2 SAMLEndpointContext (org.opensaml.saml.common.messaging.context.SAMLEndpointContext)2 SAMLPeerEntityContext (org.opensaml.saml.common.messaging.context.SAMLPeerEntityContext)2 Response (org.opensaml.saml2.core.Response)2 AssertionConsumerServiceBuilder (org.opensaml.saml2.metadata.impl.AssertionConsumerServiceBuilder)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)1 SYSTEM_EXTERNAL_SERVICES_ENDPOINTS (com.epam.pipeline.manager.preference.SystemPreferences.SYSTEM_EXTERNAL_SERVICES_ENDPOINTS)1 ExternalServiceEndpoint (com.epam.pipeline.security.ExternalServiceEndpoint)1 File (java.io.File)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1