Search in sources :

Example 6 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project spring-security-oauth by spring-projects.

the class AuthorizationEndpoint method append.

private String append(String base, Map<String, ?> query, Map<String, String> keys, boolean fragment) {
    UriComponentsBuilder template = UriComponentsBuilder.newInstance();
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(base);
    URI redirectUri;
    try {
        // assume it's encoded to start with (if it came in over the wire)
        redirectUri = builder.build(true).toUri();
    } catch (Exception e) {
        // ... but allow client registrations to contain hard-coded non-encoded values
        redirectUri = builder.build().toUri();
        builder = UriComponentsBuilder.fromUri(redirectUri);
    }
    template.scheme(redirectUri.getScheme()).port(redirectUri.getPort()).host(redirectUri.getHost()).userInfo(redirectUri.getUserInfo()).path(redirectUri.getPath());
    if (fragment) {
        StringBuilder values = new StringBuilder();
        if (redirectUri.getFragment() != null) {
            String append = redirectUri.getFragment();
            values.append(append);
        }
        for (String key : query.keySet()) {
            if (values.length() > 0) {
                values.append("&");
            }
            String name = key;
            if (keys != null && keys.containsKey(key)) {
                name = keys.get(key);
            }
            values.append(name + "={" + key + "}");
        }
        if (values.length() > 0) {
            template.fragment(values.toString());
        }
        UriComponents encoded = template.build().expand(query).encode();
        builder.fragment(encoded.getFragment());
    } else {
        for (String key : query.keySet()) {
            String name = key;
            if (keys != null && keys.containsKey(key)) {
                name = keys.get(key);
            }
            template.queryParam(name, "{" + key + "}");
        }
        template.fragment(redirectUri.getFragment());
        UriComponents encoded = template.build().expand(query).encode();
        builder.query(encoded.getQuery());
    }
    return builder.build().toUriString();
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) URI(java.net.URI) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) UserDeniedAuthorizationException(org.springframework.security.oauth2.common.exceptions.UserDeniedAuthorizationException) RedirectMismatchException(org.springframework.security.oauth2.common.exceptions.RedirectMismatchException) AuthenticationException(org.springframework.security.core.AuthenticationException) BadClientCredentialsException(org.springframework.security.oauth2.common.exceptions.BadClientCredentialsException) HttpSessionRequiredException(org.springframework.web.HttpSessionRequiredException) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) UnsupportedResponseTypeException(org.springframework.security.oauth2.common.exceptions.UnsupportedResponseTypeException) ClientRegistrationException(org.springframework.security.oauth2.provider.ClientRegistrationException) ClientAuthenticationException(org.springframework.security.oauth2.common.exceptions.ClientAuthenticationException) InvalidClientException(org.springframework.security.oauth2.common.exceptions.InvalidClientException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException) UnapprovedClientAuthenticationException(org.springframework.security.oauth2.common.exceptions.UnapprovedClientAuthenticationException)

Example 7 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project libresonic by Libresonic.

the class HLSController method createStreamUrl.

private String createStreamUrl(HttpServletRequest request, Player player, int id, int offset, int duration, Pair<Integer, Dimension> bitRate) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getContextPath(request) + "ext/stream/stream.ts");
    builder.queryParam("id", id);
    builder.queryParam("hls", "true");
    builder.queryParam("timeOffset", offset);
    builder.queryParam("player", player.getId());
    builder.queryParam("duration", duration);
    if (bitRate != null) {
        builder.queryParam("maxBitRate", bitRate.getFirst());
        Dimension dimension = bitRate.getSecond();
        if (dimension != null) {
            builder.queryParam("size", dimension.width);
            builder.queryParam("x", dimension.height);
        }
    }
    jwtSecurityService.addJWTToken(builder);
    return builder.toUriString();
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 8 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project cloudstack by apache.

the class Force10BaremetalSwitchBackend method buildLink.

private String buildLink(String switchIp, String path) {
    UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
    builder.scheme("http");
    builder.host(switchIp);
    builder.port(8008);
    builder.path(path);
    return builder.build().toUriString();
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 9 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project dhis2-core by dhis2.

the class CorsFilter method isOriginWhitelisted.

private boolean isOriginWhitelisted(HttpServletRequest request, String origin) {
    HttpServletRequestEncodingWrapper encodingWrapper = new HttpServletRequestEncodingWrapper(request);
    UriComponentsBuilder uriBuilder = ServletUriComponentsBuilder.fromContextPath(encodingWrapper).replacePath("");
    String forwardedProto = request.getHeader("X-Forwarded-Proto");
    if (!StringUtils.isEmpty(forwardedProto)) {
        uriBuilder.scheme(forwardedProto);
    }
    String localUrl = uriBuilder.build().toString();
    return !StringUtils.isEmpty(origin) && (localUrl.equals(origin) || configurationService.isCorsWhitelisted(origin));
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder)

Example 10 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project dhis2-core by dhis2.

the class SimplisticHttpGetGateWay method send.

@Override
public OutboundMessageResponse send(String subject, String text, Set<String> recipients, SmsGatewayConfig config) {
    GenericHttpGatewayConfig genericHttpConfiguration = (GenericHttpGatewayConfig) config;
    UriComponentsBuilder uri = buildUrl(genericHttpConfiguration, text, recipients);
    OutboundMessageResponse status = new OutboundMessageResponse();
    try {
        HttpEntity<?> request = new HttpEntity<>(getRequestHeaderParameters(genericHttpConfiguration.getParameters()));
        HttpStatus httpStatus = send(uri.build().encode("ISO-8859-1").toUriString(), request, String.class);
        return wrapHttpStatus(httpStatus);
    } catch (IOException e) {
        log.error("Message failed: " + e.getMessage());
        status.setResponseObject(GatewayResponse.RESULT_CODE_504);
        status.setDescription(GatewayResponse.RESULT_CODE_504.getResponseMessage());
        status.setOk(false);
        return status;
    }
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) OutboundMessageResponse(org.hisp.dhis.outboundmessage.OutboundMessageResponse) IOException(java.io.IOException)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)25 UriComponents (org.springframework.web.util.UriComponents)10 Test (org.junit.Test)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)7 Map (java.util.Map)2 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)2 Claim (com.auth0.jwt.interfaces.Claim)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 IOException (java.io.IOException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1 Res (org.fourthline.cling.support.model.Res)1 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)1 Player (org.libresonic.player.domain.Player)1 MimeType (org.seamless.util.MimeType)1 MockServletContext (org.springframework.mock.web.test.MockServletContext)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)1