Search in sources :

Example 1 with URLBuilder

use of net.shibboleth.utilities.java.support.net.URLBuilder in project cas by apereo.

the class AbstractSamlProfileHandlerController method constructServiceUrl.

/**
     * Construct service url string.
     *
     * @param request  the request
     * @param response the response
     * @param pair     the pair
     * @return the string
     * @throws SamlException the saml exception
     */
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final Pair<? extends SignableSAMLObject, MessageContext> pair) throws SamlException {
    final AuthnRequest authnRequest = AuthnRequest.class.cast(pair.getLeft());
    final MessageContext messageContext = pair.getRight();
    try (StringWriter writer = SamlUtils.transformSamlObject(this.configBean, authnRequest)) {
        final URLBuilder builder = new URLBuilder(this.callbackService.getId());
        builder.getQueryParams().add(new net.shibboleth.utilities.java.support.collection.Pair<>(SamlProtocolConstants.PARAMETER_ENTITY_ID, SamlIdPUtils.getIssuerFromSamlRequest(authnRequest)));
        final String samlRequest = EncodingUtils.encodeBase64(writer.toString().getBytes(StandardCharsets.UTF_8));
        builder.getQueryParams().add(new net.shibboleth.utilities.java.support.collection.Pair<>(SamlProtocolConstants.PARAMETER_SAML_REQUEST, samlRequest));
        builder.getQueryParams().add(new net.shibboleth.utilities.java.support.collection.Pair<>(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, SAMLBindingSupport.getRelayState(messageContext)));
        final String url = builder.buildURL();
        LOGGER.debug("Built service callback url [{}]", url);
        return CommonUtils.constructServiceUrl(request, response, url, this.serverName, CasProtocolConstants.PARAMETER_SERVICE, CasProtocolConstants.PARAMETER_TICKET, false);
    } catch (final Exception e) {
        throw new SamlException(e.getMessage(), e);
    }
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) StringWriter(java.io.StringWriter) SamlException(org.apereo.cas.support.saml.SamlException) MessageContext(org.opensaml.messaging.context.MessageContext) SamlException(org.apereo.cas.support.saml.SamlException) SAMLException(org.opensaml.saml.common.SAMLException) UnauthorizedServiceException(org.apereo.cas.services.UnauthorizedServiceException) URLBuilder(net.shibboleth.utilities.java.support.net.URLBuilder)

Aggregations

StringWriter (java.io.StringWriter)1 URLBuilder (net.shibboleth.utilities.java.support.net.URLBuilder)1 UnauthorizedServiceException (org.apereo.cas.services.UnauthorizedServiceException)1 SamlException (org.apereo.cas.support.saml.SamlException)1 MessageContext (org.opensaml.messaging.context.MessageContext)1 SAMLException (org.opensaml.saml.common.SAMLException)1 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1