public static String urlEncode(String url, boolean keepPathSlash) { String encoded = URLEncodeUtils.encodeUtf8(url); if (keepPathSlash) { encoded = encoded.replace("%2F", "/"); } return encoded; } }
public ScriptResource(Resource resource) { try { this.resource = resource; this.name = resource.getFilename(); this.path = URLEncodeUtils.decodeUtf8(resource.getURL().getPath()); this.dir = StringUtils.substringBeforeLast(this.path, "/"); } catch (IOException e) { throw new RuntimeException(e); } }
protected String getIdpLogoutUrl() { String idpBaseURL = webAuthConfig.getIdpBaseURL(); if (!idpBaseURL.endsWith("/")) { idpBaseURL += "/"; } String idpRedirectUrl = idpBaseURL + "logout?sp=" + URLEncodeUtils.encodeUtf8(getWebAppUrl()); return idpRedirectUrl; }
public File getFile(HttpServletRequest request, HttpServletResponse response) throws IOException { String filePath = URLEncodeUtils.decodeUtf8(request.getParameter("p")); if (filePath != null) { if (isPermittedDirectory(filePath)) { return new File(filePath); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } else { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } return null; }
protected String getIdpRedirectUrl() { String idpBaseURL = webAuthConfig.getIdpBaseURL(); if (!idpBaseURL.endsWith("/")) { idpBaseURL += "/"; } String idpRedirectUrl = idpBaseURL + "?sp=" + URLEncodeUtils.encodeUtf8(getWebAppUrl()); return idpRedirectUrl; }
public List<String> getModuleDirs() { try { Resource[] resources = createAppropriateResourceResolver().getResources(dbScriptsDirectoryForSearch() + "/**/*.*"); String dbDirPath = dbScriptDirectoryPath(); log.trace("DB scripts directory: {}", dbDirPath); List<String> modules = Arrays.stream(resources) .map(resource -> { try { String decodedUrl = URLEncodeUtils.decodeUtf8(resource.getURL().toString()); String resourcePath = decodedUrl.replaceFirst(".+?:", ""); Matcher matcher = Pattern.compile(".*" + Pattern.quote(dbDirPath) + "/?(.+?)/.*").matcher(resourcePath); return matcher.find() ? matcher.group(1) : null; } catch (IOException e) { throw new RuntimeException("An error occurred while detecting modules", e); } }) .filter(element -> element != null) .collect(Collectors.toSet()).stream() .sorted() .collect(Collectors.toList()); if (modules.isEmpty()) { throw new RuntimeException(String.format("No existing modules found. " + "Please check if [%s] contains DB scripts.", dbDirPath)); } log.trace("Found modules: {}", modules); return modules; } catch (IOException e) { throw new RuntimeException("An error occurred while detecting modules", e); } }
/** * Serializes the given {@code id} to string representation. * <p> * String, Integer, Long and UUID ids are only supported. * * @param id id to serialize * @return serialized string representation of id * @throws IllegalArgumentException if null id is passed or it has an unsupported type */ @Nonnull public static String serializeId(Object id) { checkNotNullArgument(id, "Id cannot be null"); String serialized; Class<?> idClass = id.getClass(); if (String.class == idClass || Integer.class == idClass || Long.class == idClass) { serialized = URLEncodeUtils.encodeUtf8(id.toString()); } else if (UUID.class == idClass) { serialized = CrockfordUuidEncoder.encode(((UUID) id)); } else { throw new IllegalArgumentException( String.format("Unable to serialize id '%s' of type '%s'", id, idClass)); } return serialized; }
return; String name = URLEncodeUtils.decodeUtf8(fields[0]); String value = URLEncodeUtils.decodeUtf8(fields[1]); name2value.put(name, value);
@PostMapping(value = "/run/{entityId}") public void runReport(@PathVariable String entityId, @RequestBody(required = false) String body, HttpServletResponse response) { if (Strings.isNullOrEmpty(body)) { throw new RestAPIException("Run report error", "Required request body is missing", HttpStatus.BAD_REQUEST); } ReportRestResult result = controllerManager.runReport(entityId, body); try { String fileName = URLEncodeUtils.encodeUtf8(result.getDocumentName()); response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache"); response.setHeader(HttpHeaders.PRAGMA, "no-cache"); response.setDateHeader(HttpHeaders.EXPIRES, 0); response.setHeader(HttpHeaders.CONTENT_TYPE, getContentType(result.getReportOutputType())); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, (BooleanUtils.isTrue(result.attachment) ? "attachment" : "inline") + "; filename=\"" + fileName + "\""); ServletOutputStream os = response.getOutputStream(); IOUtils.copy(new ByteArrayInputStream(result.getContent()), os); os.flush(); } catch (IOException e) { log.error("Error on downloading the report {}", entityId, e); throw new RestAPIException("Error on downloading the report", "", HttpStatus.INTERNAL_SERVER_ERROR); } }
@RequestMapping(value = "/api/logout", method = RequestMethod.POST) public void logoutByPost(@RequestBody String requestBody, @RequestHeader(value = "Content-Type") MimeType contentType, HttpServletResponse response) throws IOException, JSONException { String sessionUUID; if (contentType.match(JSONConverter.MIME_TYPE_JSON)) { try { JSONObject json = new JSONObject(requestBody); sessionUUID = json.getString("session"); } catch (JSONException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } } else if (contentType.match(FORM_TYPE)) { String[] fields = requestBody.split("="); if (fields.length < 2) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } sessionUUID = URLEncodeUtils.decodeUtf8(fields[1]); } else { throw new IllegalStateException("Unsupported content type: " + contentType); } doLogout(sessionUUID, response); }
return "redirect:login.html" + "?response_type=" + ResponseType.CLIENT_TICKET.getCode() + "&sp=" + URLEncodeUtils.encodeUtf8(serviceProviderUrl); return "redirect:login.html?sp=" + URLEncodeUtils.encodeUtf8(serviceProviderUrl);
String decoded = URLEncodeUtils.decodeUtf8(serializedId);
String url = selectedUrl + fileDownloadContext + "?s=" + userSessionSource.getUserSession().getId() + "&p=" + URLEncodeUtils.encodeUtf8(filePath);
protected void initRememberMe() { loginChangeListener = e -> loginByRememberMe = false; if (!webConfig.getRememberMeEnabled()) { rememberMeCheckBox.setValue(false); rememberMeCheckBox.setVisible(false); return; } String rememberMeCookie = app.getCookieValue(COOKIE_REMEMBER_ME); if (Boolean.parseBoolean(rememberMeCookie)) { String encodedLogin = app.getCookieValue(COOKIE_LOGIN) != null ? app.getCookieValue(COOKIE_LOGIN) : ""; String login = URLEncodeUtils.decodeUtf8(encodedLogin); String rememberMeToken = app.getCookieValue(COOKIE_PASSWORD) != null ? app.getCookieValue(COOKIE_PASSWORD) : ""; if (StringUtils.isNotEmpty(rememberMeToken)) { rememberMeCheckBox.setValue(true); loginField.setValue(login); passwordField.setValue(rememberMeToken); loginByRememberMe = true; } loginField.addValueChangeListener(loginChangeListener); passwordField.addValueChangeListener(loginChangeListener); } }
|| value instanceof Boolean) { sb.append(",").append(param.getKey()).append(":") .append(URLEncodeUtils.encodeUtf8(value.toString()));
return "redirect:login.html" + "?response_type=" + ResponseType.CLIENT_TICKET.getCode() + "&sp=" + URLEncodeUtils.encodeUtf8(serviceProviderUrl); return "redirect:login.html?sp=" + URLEncodeUtils.encodeUtf8(serviceProviderUrl);
String encodedFilePath = URLEncodeUtils.encodeUtf8(file.getPath()); sb.append(encodedFilePath).append("\n"); } else {
@Override public String getLogFileLink(String fileName) throws LogControlException { // check log file exists logControl.getLogFile(fileName); Configuration configuration = AppBeans.get(Configuration.NAME); GlobalConfig globalConfig = configuration.getConfig(GlobalConfig.class); String encodedFileName = URLEncodeUtils.encodeUtf8(fileName); return globalConfig.getDispatcherBaseUrl() + "/log/" + encodedFileName; }
String fileName = URLEncodeUtils.encodeUtf8(fd.getName());
String fileName = URLEncodeUtils.encodeUtf8(fd.getName());