Example usage for org.springframework.web.util UriUtils decode

List of usage examples for org.springframework.web.util UriUtils decode

Introduction

In this page you can find the example usage for org.springframework.web.util UriUtils decode.

Prototype

public static String decode(String source, Charset charset) 

Source Link

Document

Decode the given encoded URI component.

Usage

From source file:springfox.documentation.spring.web.ControllerNamingUtils.java

public static String decode(String path) {
    try {//w  w  w.ja  v  a  2s . c o  m
        path = UriUtils.decode(path, ISO_8859_1);
    } catch (Exception e) {
        log.error("Could not decode:" + path, e);
    }
    return path;
}

From source file:io.dacopancm.jfee.managedController.FacturaAfiliacionBean.java

@PostConstruct
public void postConstruct() {

    try {//from   w  w w  . j  av  a 2s .  c o m
        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
                .getRequestParameterMap();
        if (params.containsKey("r")) {
            returnPage = params.get("r");
        }
        if (params.containsKey("socCi") && params.containsKey("h")) {
            String hash = UriUtils.decode(params.get("h"), "UTF-8");
            String ci = params.get("socCi");
            if (BCrypt.checkpw(ci, hash)) {
                selectedSocio = socioService.getSocioByCi(ci);
            }
        } else {
            //redirect to index
        }
    } catch (UnsupportedEncodingException ex) {
        log.error(ex.getMessage());
        //redirect to index
    }

}

From source file:org.mitre.oauth2.service.impl.UriEncodedClientUserDetailsService.java

@Override
public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException {

    try {//w  ww  .  j  av a 2s.  co m
        String decodedClientId = UriUtils.decode(clientId, "UTF-8");

        ClientDetailsEntity client = clientDetailsService.loadClientByClientId(decodedClientId);

        if (client != null) {

            String encodedPassword = UriUtils.encodeQueryParam(Strings.nullToEmpty(client.getClientSecret()),
                    "UTF-8");

            if (config.isHeartMode() || // if we're running HEART mode turn off all client secrets
                    (client.getTokenEndpointAuthMethod() != null
                            && (client.getTokenEndpointAuthMethod().equals(AuthMethod.PRIVATE_KEY)
                                    || client.getTokenEndpointAuthMethod().equals(AuthMethod.SECRET_JWT)))) {

                // Issue a random password each time to prevent password auth from being used (or skipped)
                // for private key or shared key clients, see #715

                encodedPassword = new BigInteger(512, new SecureRandom()).toString(16);
            }

            boolean enabled = true;
            boolean accountNonExpired = true;
            boolean credentialsNonExpired = true;
            boolean accountNonLocked = true;
            Collection<GrantedAuthority> authorities = new HashSet<>(client.getAuthorities());
            authorities.add(ROLE_CLIENT);

            return new User(decodedClientId, encodedPassword, enabled, accountNonExpired, credentialsNonExpired,
                    accountNonLocked, authorities);
        } else {
            throw new UsernameNotFoundException("Client not found: " + clientId);
        }
    } catch (UnsupportedEncodingException | InvalidClientException e) {
        throw new UsernameNotFoundException("Client not found: " + clientId);
    }

}

From source file:org.jasig.portlet.contacts.control.SetViewController.java

@ResourceMapping("setView")
public String showDomain(ResourceRequest request, ResourceResponse response, @RequestParam("set") String setId,
        @ModelAttribute("domain") ContactDomain domainObj, Model model, PortletSession session)
        throws IOException {

    String setIdDecode = UriUtils.decode(setId, "UTF-8");
    ContactSet contacts = domainObj.getContacts(setIdDecode);
    model.addAttribute("contactList", contacts);

    if (domainObj.getHasPersist()) {
        model.addAttribute("persist", true);
    }/*from   w  ww.  j  a v  a2s. c o  m*/
    log.debug(contacts.size() + " CONTACTS found for " + contacts.getTitle());
    log.debug("Contacts set for domain :: " + domainObj.getName());

    model.addAttribute("domain", domainObj);
    model.addAttribute("source", setId);

    if (viewSelector.isMobile(request))
        return "setView-jQM";
    else
        return "setView";

}

From source file:io.dacopancm.jfee.managedController.EditarSocioBean.java

@PostConstruct
public void postConstruct() {
    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();// w  w w . jav a2 s  .com
    if (params.containsKey("r")) {
        returnPage = params.get("r");
    } else {
        returnPage = "home";
    }
    try {
        HttpServletRequest htpr = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
                .getRequest();
        if (htpr.getRequestURL().toString().contains("editarSocio")) {
            if (params.containsKey("socCi") && params.containsKey("h")) {
                String hash = UriUtils.decode(params.get("h"), "UTF-8");
                String ci = params.get("socCi");
                if (BCrypt.checkpw(ci, hash)) {
                    //TODO si es administrador no pasa nada pero
                    //si es socio probar q current socio login sea el mismo a modificar
                    selectedSocio = socioService.getSocioByCi(ci);
                }
            } else {

                User userDetails = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

                selectedSocio = socioService.getSocioByCi(userDetails.getUsername());

            }
        } else {
            User userDetails = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

            selectedSocio = socioService.getSocioByCi(userDetails.getUsername());
        }
    } catch (Exception ex) {
        log.error(ex.getMessage());
    }

}

From source file:org.cloudfoundry.identity.uaa.login.feature.ImplicitGrantIT.java

@Test
public void testDefaultScopes() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>();
    postBody.add("client_id", "cf");
    postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf");
    postBody.add("response_type", "token");
    postBody.add("source", "credentials");
    postBody.add("username", testAccounts.getUserName());
    postBody.add("password", testAccounts.getPassword());

    ResponseEntity<Void> responseEntity = restOperations.exchange(baseUrl + "/oauth/authorize", HttpMethod.POST,
            new HttpEntity<>(postBody, headers), Void.class);

    Assert.assertEquals(HttpStatus.FOUND, responseEntity.getStatusCode());

    UriComponents locationComponents = UriComponentsBuilder.fromUri(responseEntity.getHeaders().getLocation())
            .build();/*ww w. j  a v  a2s.  c o m*/
    Assert.assertEquals("uaa.cloudfoundry.com", locationComponents.getHost());
    Assert.assertEquals("/redirect/cf", locationComponents.getPath());

    MultiValueMap<String, String> params = parseFragmentParams(locationComponents);

    Assert.assertThat(params.get("jti"), not(empty()));
    Assert.assertEquals("bearer", params.getFirst("token_type"));
    Assert.assertThat(Integer.parseInt(params.getFirst("expires_in")), Matchers.greaterThan(40000));

    String[] scopes = UriUtils.decode(params.getFirst("scope"), "UTF-8").split(" ");
    Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write",
            "cloud_controller.write", "openid", "cloud_controller.read"));

    Jwt access_token = JwtHelper.decode(params.getFirst("access_token"));

    Map<String, Object> claims = new ObjectMapper().readValue(access_token.getClaims(),
            new TypeReference<Map<String, Object>>() {
            });

    Assert.assertThat((String) claims.get("jti"), is(params.getFirst("jti")));
    Assert.assertThat((String) claims.get("client_id"), is("cf"));
    Assert.assertThat((String) claims.get("cid"), is("cf"));
    Assert.assertThat((String) claims.get("user_name"), is(testAccounts.getUserName()));

    Assert.assertThat(((List<String>) claims.get("scope")), containsInAnyOrder(scopes));

    Assert.assertThat(((List<String>) claims.get("aud")),
            containsInAnyOrder("cf", "scim", "openid", "cloud_controller", "password"));
}

From source file:com.tyro.oss.pact.spring4.pact.provider.PactTestBase.java

protected MockHttpServletRequestBuilder createRequestBuilderWithMethodAndUri(Pact.InteractionRequest request)
        throws Exception {
    String uri = request.getUri().contains(getServletContextPathWithoutTrailingSlash())
            ? StringUtils.substringAfter(request.getUri(), getServletContextPathWithoutTrailingSlash())
            : request.getUri();//from  w  ww.j a  v a 2s .  c  o m
    uri = UriUtils.decode(uri, "UTF-8");

    switch (request.getMethod()) {
    case GET:
        return get(uri);
    case POST:
        return post(uri);
    case PUT:
        return put(uri);
    case DELETE:
        return delete(uri);
    default:
        throw new RuntimeException("Unsupported method " + request.getMethod());
    }
}

From source file:eionet.web.action.VocabularyConceptActionBean.java

/**
 * Stripes has a bug that double-decodes the request path info. "+" is converted to " " that makes impossible to distinguish
 * space and '+' This method extracts the original conceptId.
 *//*from w ww. j  a v  a  2s  .c  om*/
private void handleConceptIdentifier() {
    String realRequestPath = getRequestedPath(getContext().getRequest());
    // vocabularyconcept/{vocabularyFolder.folderName}/{vocabularyFolder.identifier}/{vocabularyConcept.identifier}/{$event}
    String[] params = realRequestPath.split("\\/", -1);
    String identifier = params[4];
    try {
        identifier = UriUtils.decode(identifier, "utf-8");
    } catch (UnsupportedEncodingException e) {
        LOGGER.warn("Unsupported Encoding Exception " + e);
    }

    setConceptIdentifier(identifier);
}

From source file:org.cloudfoundry.identity.uaa.integration.OpenIdTokenAuthorizationWithApprovalIntegrationTests.java

@Test
public void testOpenIdTokenUsingLoginClientOauthTokenEndpoint() throws Exception {

    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

    LinkedMultiValueMap<String, String> postBody = new LinkedMultiValueMap<>();
    postBody.add("client_id", "app");
    postBody.add("client_secret", "appclientsecret");
    postBody.add("redirect_uri", "https://uaa.cloudfoundry.com/redirect/cf");
    postBody.add("response_type", "token id_token");
    postBody.add("grant_type", "password");
    postBody.add("source", "login");
    postBody.add("user_id", user.getId());
    postBody.add("add_new", "false");

    ResponseEntity<Map> responseEntity = loginClient.exchange(serverRunning.getBaseUrl() + "/oauth/token",
            HttpMethod.POST, new HttpEntity<>(postBody, headers), Map.class);

    Assert.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());

    Map<String, Object> params = responseEntity.getBody();

    Assert.assertTrue(params.get("jti") != null);
    Assert.assertEquals("bearer", params.get("token_type"));
    Assert.assertThat((Integer) params.get("expires_in"), Matchers.greaterThan(40000));

    String[] scopes = UriUtils.decode((String) params.get("scope"), "UTF-8").split(" ");
    Assert.assertThat(Arrays.asList(scopes), containsInAnyOrder("scim.userids", "password.write",
            "cloud_controller.write", "openid", "cloud_controller.read"));
}

From source file:org.unitedinternet.cosmo.dav.caldav.report.MultigetReport.java

private static boolean isDescendentOrEqual(URL collection, URL test) {
    if (collection == null || test == null) {
        return false;
    }/*  ww  w.  ja v  a 2s  .  co  m*/
    if (collection.toString().equals(test.toString())) {
        return true;
    }

    try {
        String testPathDecoded = UriUtils.decode(test.getPath(), "UTF-8");
        String collectionPathDecoded = UriUtils.decode(collection.getPath(), "UTF-8");

        return testPathDecoded.startsWith(collectionPathDecoded);
    } catch (UnsupportedEncodingException e) {
        return test.getPath().startsWith(collection.getPath());
    }
}