use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.
the class AuthManagerImpl method getGetRedirectURL.
/* (non-Javadoc)
* @see com.tremolosecurity.proxy.auth.sys.AuthManager#getGetRedirectURL(com.tremolosecurity.proxy.auth.RequestHolder)
*/
@Override
public StringBuffer getGetRedirectURL(RequestHolder reqHolder) {
StringBuffer redirURL = new StringBuffer(reqHolder.getURL());
if (reqHolder.isForceAuth() || redirURL.indexOf("?") > 0) {
return redirURL;
}
boolean first = true;
for (NVP p : reqHolder.getQueryStringParams()) {
if (first) {
first = false;
redirURL.append('?');
} else {
redirURL.append('&');
}
try {
redirURL.append(p.getName()).append('=').append(URLEncoder.encode(p.getValue(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
}
}
return redirURL;
}
use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.
the class ProxyRequest method getParameterValues.
@Override
public String[] getParameterValues(String name) {
ArrayList<String> vals = this.reqParams.get(name);
if (vals != null) {
String[] svals = new String[vals.size()];
vals.toArray(svals);
return svals;
} else {
vals = new ArrayList<String>();
for (NVP nvp : this.queryString) {
if (nvp.getName().equals(name)) {
vals.add(nvp.getValue());
}
}
if (vals.size() == 0) {
return null;
} else {
String[] svals = new String[vals.size()];
vals.toArray(svals);
return svals;
}
}
}
use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.
the class ProxyRequest method copyQSParamsToFormParams.
public void copyQSParamsToFormParams() {
for (NVP p : this.queryString) {
ArrayList<String> vals = this.reqParams.get(p.getName());
if (vals == null) {
vals = new ArrayList<String>();
this.paramList.add(p.getName());
this.reqParams.put(p.getName(), vals);
}
vals.add(p.getValue());
}
}
use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.
the class ProxyRequest method removeParameter.
public void removeParameter(String name) {
this.reqParams.remove(name);
ArrayList<NVP> toRM = new ArrayList<NVP>();
for (NVP p : this.orderedList) {
if (p.getName().equalsIgnoreCase(name)) {
toRM.add(p);
}
}
this.orderedList.removeAll(toRM);
}
use of com.tremolosecurity.util.NVP in project OpenUnison by TremoloSecurity.
the class PushRequestProcess method postProcess.
@Override
public void postProcess(HttpFilterRequest req, HttpFilterResponse resp, UrlHolder holder, HttpFilterChain chain) throws Exception {
boolean isText;
HashMap<String, String> uriParams = (HashMap<String, String>) req.getAttribute("TREMOLO_URI_PARAMS");
StringBuffer proxyToURL = new StringBuffer();
proxyToURL.append(holder.getProxyURL(uriParams));
boolean first = true;
for (NVP p : req.getQueryStringParams()) {
if (first) {
proxyToURL.append('?');
first = false;
} else {
proxyToURL.append('&');
}
proxyToURL.append(p.getName()).append('=').append(URLEncoder.encode(p.getValue(), "UTF-8"));
}
HttpEntity entity = null;
if (req.isMultiPart()) {
MultipartEntityBuilder mpeb = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
for (String name : req.getFormParams()) {
for (String val : req.getFormParamVals(name)) {
// ent.addPart(name, new StringBody(val));
mpeb.addTextBody(name, val);
}
}
HashMap<String, ArrayList<FileItem>> files = req.getFiles();
for (String name : files.keySet()) {
for (FileItem fi : files.get(name)) {
// ent.addPart(name, new InputStreamBody(fi.getInputStream(),fi.getContentType(),fi.getName()));
mpeb.addBinaryBody(name, fi.get(), ContentType.create(fi.getContentType()), fi.getName());
}
}
entity = mpeb.build();
} else if (req.isParamsInBody()) {
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
for (String paramName : req.getFormParams()) {
for (String val : req.getFormParamVals(paramName)) {
formparams.add(new BasicNameValuePair(paramName, val));
}
}
entity = new UrlEncodedFormEntity(formparams, "UTF-8");
} else {
byte[] msgData = (byte[]) req.getAttribute(ProxySys.MSG_BODY);
ByteArrayEntity bentity = new ByteArrayEntity(msgData);
bentity.setContentType(req.getContentType());
entity = bentity;
}
CloseableHttpClient httpclient = this.getHttp(proxyToURL.toString(), req.getServletRequest(), holder);
// HttpPost httppost = new HttpPost(proxyToURL.toString());
// this.getHttpMethod(proxyToURL.toString());
HttpEntityEnclosingRequestBase httpMethod = new EntityMethod(req.getMethod(), proxyToURL.toString());
setHeadersCookies(req, holder, httpMethod, proxyToURL.toString());
httpMethod.setEntity(entity);
HttpContext ctx = (HttpContext) req.getSession().getAttribute(ProxySys.HTTP_CTX);
HttpResponse response = httpclient.execute(httpMethod, ctx);
postProcess(req, resp, holder, response, proxyToURL.toString(), chain, httpMethod);
}
Aggregations