Search in sources :

Example 11 with NVP

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;
}
Also used : NVP(com.tremolosecurity.util.NVP) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 12 with NVP

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;
        }
    }
}
Also used : NVP(com.tremolosecurity.util.NVP)

Example 13 with NVP

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());
    }
}
Also used : NVP(com.tremolosecurity.util.NVP)

Example 14 with NVP

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);
}
Also used : ArrayList(java.util.ArrayList) NVP(com.tremolosecurity.util.NVP)

Example 15 with NVP

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);
}
Also used : EntityMethod(com.tremolosecurity.proxy.http.EntityMethod) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) MultipartEntityBuilder(org.apache.http.entity.mime.MultipartEntityBuilder) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HttpContext(org.apache.http.protocol.HttpContext) NVP(com.tremolosecurity.util.NVP) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) FileItem(org.apache.commons.fileupload.FileItem) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

NVP (com.tremolosecurity.util.NVP)16 ArrayList (java.util.ArrayList)9 Attribute (com.tremolosecurity.saml.Attribute)5 HashMap (java.util.HashMap)5 ProvisioningException (com.tremolosecurity.provisioning.core.ProvisioningException)4 ScaleAttribute (com.tremolosecurity.scalejs.cfg.ScaleAttribute)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 List (java.util.List)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 Gson (com.google.gson.Gson)2 LDAPSearchResults (com.novell.ldap.LDAPSearchResults)2 ScaleJSRegisterConfig (com.tremolosecurity.scalejs.register.cfg.ScaleJSRegisterConfig)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 HttpResponse (org.apache.http.HttpResponse)2 NameValuePair (org.apache.http.NameValuePair)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 LDAPAttribute (com.novell.ldap.LDAPAttribute)1 LDAPEntry (com.novell.ldap.LDAPEntry)1