protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String redirectURI, Map<String, String> params) throws IOException { if (redirectURI == null) { response.sendError(SC_BAD_REQUEST, "No redirect URI"); return; } String url = URIUtils.addParametersToURIQuery(redirectURI, params); response.sendRedirect(url); } }
/** * Quotes a URI path token. For example, a blob filename. It replaces "/" by "-". * * @since 7.3 * @param s the uri path token to quote */ public static String quoteURIPathToken(String s) { return quoteURIPathComponent(s, "-", "%40"); }
protected String getFlavor() { String queryString = context.getRequest().getQueryString(); if (queryString != null) { Map<String, String> params = URIUtils.getRequestParameters(queryString); if (params != null && params.containsKey("flavor")) { return params.get("flavor"); } } return null; }
public static String addParametersToURIQuery(String uriString, Map<String, String> parameters) { if (uriString == null || parameters == null || parameters.isEmpty()) { return uriString; } String uriPath = getURIPath(uriString); Map<String, String> existingParams = getRequestParameters(uriString.substring(uriPath.length())); if (existingParams == null) { existingParams = new LinkedHashMap<>(); } existingParams.putAll(parameters); String res; if (!existingParams.isEmpty()) { String newQuery = getURIQuery(existingParams); res = uriPath + '?' + newQuery; } else { res = uriPath; } return res; }
/** * Get the url from a DocumentView for a user or a group. */ public String getUrlFromDocumentViewAndID(DocumentView docView, String paramName) { String id = docView.getParameter(paramName); if (id != null) { docView.removeParameter(paramName); List<String> items = new ArrayList<>(); items.add(getPrefix()); items.add(URIUtils.quoteURIPathComponent(id, true, false)); String viewId = docView.getViewId(); if (viewId != null) { items.add(viewId); } String uri = String.join("/", items); Map<String, String> parameters = docView.getParameters(); if (parameters == null) { parameters = new HashMap<>(); } return URIUtils.addParametersToURIQuery(uri, parameters); } return null; }
@Override public String getUrlFromDocumentView(DocumentView docView) { DocumentLocation docLoc = docView.getDocumentLocation(); String filepath = docView.getParameter(FILE_PROPERTY_PATH_KEY); String filename = docView.getParameter(FILENAME_KEY); if (docLoc != null && filepath != null && filename != null) { StringBuilder buf = new StringBuilder(); buf.append(getPrefix()); buf.append("/"); buf.append(docLoc.getServerName()); buf.append("/"); buf.append(docLoc.getDocRef().toString()); buf.append("/"); buf.append(filepath); buf.append("/"); buf.append(URIUtils.quoteURIPathToken(filename)); String uri = buf.toString(); Map<String, String> requestParams = new HashMap<>(docView.getParameters()); requestParams.remove(FILE_PROPERTY_PATH_KEY); requestParams.remove(FILENAME_KEY); return URIUtils.addParametersToURIQuery(uri, requestParams); } return null; }
/** * Extracts document location from a Zope-like URL, eg: server/path_or_docId/view_id/tab_id . */ @Override public DocumentView getDocumentViewFromUrl(String url) { final Pattern pattern = Pattern.compile(getPrefix() + URL_PATTERN); Matcher m = pattern.matcher(url); if (m.matches()) { final String server = m.group(1); String path = m.group(2); if (path != null) { // add leading slash to make it absolute if it's not the root path = "/" + URIUtils.unquoteURIPathComponent(path); } final DocumentRef docRef = path != null ? new PathRef(path) : null; String viewId = m.group(3); int jsessionidIndex = viewId.indexOf(";jsessionid"); if (jsessionidIndex != -1) { viewId = viewId.substring(0, jsessionidIndex); } // get other parameters String query = m.group(4); Map<String, String> params = URIUtils.getRequestParameters(query); final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef); return new DocumentViewImpl(docLoc, viewId, params); } return null; }
params.put(OAUTH_TOKEN_SECRET, rToken.getTokenSecret()); params.put(OAUTH_CALLBACK_CONFIRMED, "true"); String body = URIUtils.getURIQuery(params); response.setStatus(SC_OK); response.setContentType(APPLICATION_X_WWW_FORM_URLENCODED);
items.add(URIUtils.quoteURIPathComponent(path, false)); String uriWithParam = URIUtils.addParametersToURIQuery(uri, docView.getParameters());
String uri = URIUtils.getURIPath(requestPage); Map<String, String> params = URIUtils.getRequestParameters(requestPage); params.remove(FORCE_ANONYMOUS_LOGIN); if (!params.isEmpty()) { uri += '?' + URIUtils.getURIQuery(params);
params.put(OAUTH_TOKEN, aToken.getToken()); params.put(OAUTH_TOKEN_SECRET, aToken.getTokenSecret()); String body = URIUtils.getURIQuery(params); response.getWriter().write(body);
/** * @since 10.3 */ protected String getLogoutRedirectURL(String callbackURL, String baseURL, Map<String, String> parameters) { if (isCallbackURLValid(callbackURL, baseURL)) { return callbackURL; } String url = baseURL + LoginScreenHelper.getStartupPagePath(); return URIUtils.addParametersToURIQuery(url, parameters); }
/** * Quotes a URI path component, with ability to quote "/" and "@" characters or not depending on the URI path * * @since 5.6 * @param s the uri path to quote * @param quoteSlash true if "/" character should be quoted and replaced by %2F * @param quoteAt true if "@" character should be quoted and replaced by %40 */ public static String quoteURIPathComponent(String s, boolean quoteSlash, boolean quoteAt) { return quoteURIPathComponent(s, quoteSlash ? "%2F" : null, quoteAt ? "%40" : null); }
@Override public void sendRedirect(String location) throws IOException { Map<String, String> parameters = URIUtils.getRequestParameters(location); // failed form authentication, fragment is already stored if (parameters.containsKey(LOGIN_MISSING) || parameters.containsKey(LOGIN_FAILED)) { super.sendRedirect(location); return; } HttpServletResponse response = (HttpServletResponse) getResponse(); StringBuilder sb = new StringBuilder(); sb.append("<script type=\"text/javascript\">\n"); sb.append("document.cookie = '" + NXAuthConstants.START_PAGE_FRAGMENT_KEY + "=' + encodeURIComponent(window.location.hash.substring(1) || '') + '; path=/';\n"); sb.append("window.location = '" + location + "';\n"); sb.append("</script>"); String script = sb.toString(); response.setStatus(SC_UNAUTHORIZED); response.setContentType("text/html;charset=UTF-8"); response.setContentLength(script.length()); response.getWriter().write(script); } };
@Override public String getLoginURL(HttpServletRequest request) { PluggableAuthenticationService authService = (PluggableAuthenticationService) Framework.getRuntime() .getComponent( PluggableAuthenticationService.NAME); Map<String, String> urlParameters = new HashMap<>(); urlParameters.put(SECURITY_ERROR, "true"); urlParameters.put(FORCE_ANONYMOUS_LOGIN, "true"); if (request.getAttribute(REQUESTED_URL) != null) { urlParameters.put(REQUESTED_URL, (String) request.getAttribute(REQUESTED_URL)); } else { urlParameters.put(REQUESTED_URL, NuxeoAuthenticationFilter.getRequestedUrl(request)); } String baseURL = authService.getBaseURL(request) + LOGOUT_PAGE; return URIUtils.addParametersToURIQuery(baseURL, urlParameters); }
public static String quoteURIPathComponent(String s, boolean quoteSlash) { return quoteURIPathComponent(s, quoteSlash, true); }
@Override public CacheKey create(HttpServletRequest request) { notNull(request); // this requires a type to be detected for now CacheKey key = super.create(request); if (key != null) { // add additional attributes for request-related info Map<String, String> params = URIUtils.getRequestParameters(request.getQueryString()); if (params != null) { for (Map.Entry<String, String> entry : params.entrySet()) { key.addAttribute(entry.getKey(), entry.getValue()); } } } if (log.isDebugEnabled()) { log.debug(String.format("Cache key for request '%s' '%s': %s", request.getRequestURL(), request.getQueryString(), key)); } return key; }
protected String resolveUrlWithTimestamp(UIComponent component, String url) { boolean doIncludeTimestamp = true; Object includeTimestamp = component.getAttributes().get("includeTimestamp"); if (includeTimestamp instanceof String) { if (!StringUtils.isBlank((String) includeTimestamp)) { doIncludeTimestamp = Boolean.parseBoolean((String) includeTimestamp); } } if (doIncludeTimestamp) { Long timestamp = Framework.getService(WebResourceManager.class).getLastModified(); if (timestamp != null) { return URIUtils.addParametersToURIQuery(url, Collections.singletonMap("ts", String.valueOf(timestamp))); } } return url; }
@Override public String getDownloadUrl(String repositoryName, String docId, String xpath, String filename, String changeToken) { StringBuilder sb = new StringBuilder(); sb.append(NXFILE); sb.append("/").append(repositoryName); sb.append("/").append(docId); if (xpath != null) { sb.append("/").append(xpath); if (filename != null) { // make sure filename doesn't contain path separators filename = getSanitizedFilenameWithoutPath(filename); sb.append("/").append(URIUtils.quoteURIPathComponent(filename, true)); } } if (StringUtils.isNotEmpty(changeToken)) { try { sb.append("?") .append(CoreSession.CHANGE_TOKEN) .append("=") .append(URLEncoder.encode(changeToken, "UTF-8")); } catch (UnsupportedEncodingException e) { log.error("Cannot append changeToken", e); } } return sb.toString(); }
if (m.groupCount() > 6) { String query = m.group(7); params = URIUtils.getRequestParameters(query);