Search in sources :

Example 1 with EmbPostProc

use of com.tremolosecurity.embedd.EmbPostProc in project OpenUnison by TremoloSecurity.

the class ProxySys method doPush.

public void doPush(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    UrlHolder holder = (UrlHolder) req.getAttribute(ProxyConstants.AUTOIDM_CFG);
    HttpFilterRequest filterReq = new HttpFilterRequestImpl(req, null);
    HttpFilterResponse filterResp = new HttpFilterResponseImpl(resp);
    HashMap<String, String> uriParams = (HashMap<String, String>) req.getAttribute("TREMOLO_URI_PARAMS");
    if (uriParams == null) {
        uriParams = new HashMap<String, String>();
        req.setAttribute("TREMOLO_URI_PARAMS", uriParams);
    }
    uriParams.put("fullURI", req.getRequestURI());
    HashSet<String> queryParams = new HashSet<String>();
    req.setAttribute(ProxySys.QUERY_PARAMS, queryParams);
    String qs = req.getQueryString();
    if (qs != null) {
        StringTokenizer toker = new StringTokenizer(qs, "&", false);
        while (toker.hasMoreTokens()) {
            String qsParam = toker.nextToken();
            int eqIndex = qsParam.indexOf('=');
            String paramName;
            if (eqIndex == -1) {
                paramName = qsParam;
            } else {
                paramName = qsParam.substring(0, eqIndex);
            }
            if (!queryParams.contains(paramName)) {
                queryParams.add(paramName);
            }
        }
    }
    PostProcess postProc = null;
    if (holder.getUrl().getProxyTo() == null || holder.getUrl().getProxyTo().isEmpty()) {
        FilterChain filterChain = (FilterChain) req.getAttribute(ProxyConstants.TREMOLO_FILTER_CHAIN);
        if (filterChain == null) {
            logger.warn("Could not find filter chain");
        }
        postProc = new EmbPostProc(filterChain);
    } else {
        postProc = new PushRequestProcess();
        ;
    }
    HttpFilterChain chain = new HttpFilterChainImpl(holder, postProc);
    try {
        chain.nextFilter(filterReq, filterResp, chain);
    } catch (Exception e) {
        throw new ServletException(e);
    }
    ProxyData pd = new ProxyData();
    pd.setHolder(holder);
    pd.setIns(chain.getIns());
    pd.setPostProc(postProc);
    pd.setRequest(filterReq);
    pd.setResponse(filterResp);
    pd.setText(chain.isText());
    pd.setLogout(chain.isLogout());
    pd.setHttpRequestBase(chain.getHttpRequestBase());
    req.setAttribute(ProxyConstants.TREMOLO_PRXY_DATA, pd);
}
Also used : EmbPostProc(com.tremolosecurity.embedd.EmbPostProc) HashMap(java.util.HashMap) FilterChain(javax.servlet.FilterChain) HttpFilterChain(com.tremolosecurity.proxy.filter.HttpFilterChain) PushRequestProcess(com.tremolosecurity.proxy.postProcess.PushRequestProcess) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UrlHolder(com.tremolosecurity.config.util.UrlHolder) HttpFilterResponse(com.tremolosecurity.proxy.filter.HttpFilterResponse) ServletException(javax.servlet.ServletException) StringTokenizer(java.util.StringTokenizer) PostProcess(com.tremolosecurity.proxy.filter.PostProcess) HttpFilterRequestImpl(com.tremolosecurity.proxy.filter.HttpFilterRequestImpl) HttpFilterResponseImpl(com.tremolosecurity.proxy.filter.HttpFilterResponseImpl) HttpFilterChainImpl(com.tremolosecurity.proxy.filter.HttpFilterChainImpl) HttpFilterChain(com.tremolosecurity.proxy.filter.HttpFilterChain) HttpFilterRequest(com.tremolosecurity.proxy.filter.HttpFilterRequest) HashSet(java.util.HashSet)

Example 2 with EmbPostProc

use of com.tremolosecurity.embedd.EmbPostProc in project OpenUnison by TremoloSecurity.

the class ProxySys method doURI.

public void doURI(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    boolean isText = false;
    UrlHolder holder = (UrlHolder) req.getAttribute(ProxyConstants.AUTOIDM_CFG);
    HashMap<String, String> uriParams = (HashMap<String, String>) req.getAttribute("TREMOLO_URI_PARAMS");
    if (uriParams == null) {
        uriParams = new HashMap<String, String>();
        req.setAttribute("TREMOLO_URI_PARAMS", uriParams);
    }
    uriParams.put("fullURI", req.getRequestURI());
    HttpFilterRequest filterReq = new HttpFilterRequestImpl(req, null);
    HttpFilterResponse filterResp = new HttpFilterResponseImpl(resp);
    PostProcess postProc = null;
    if (holder.getUrl().getProxyTo() == null || holder.getUrl().getProxyTo().isEmpty()) {
        FilterChain filterChain = (FilterChain) req.getAttribute(ProxyConstants.TREMOLO_FILTER_CHAIN);
        if (filterChain == null) {
            logger.warn("Could not find filter chain");
        }
        postProc = new EmbPostProc(filterChain);
    } else {
        postProc = new UriRequestProcess();
    }
    HttpFilterChain chain = new HttpFilterChainImpl(holder, postProc);
    try {
        chain.nextFilter(filterReq, filterResp, chain);
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PrintWriter err = new PrintWriter(new OutputStreamWriter(baos));
        e.printStackTrace(err);
        Throwable t = e.getCause();
        while (t != null) {
            t.printStackTrace(err);
            t = t.getCause();
        }
        logger.error("Error Executing Request : " + new String(baos.toByteArray()));
        throw new ServletException("Could not execute request", e);
    }
    ProxyData pd = new ProxyData();
    pd.setHolder(holder);
    pd.setIns(chain.getIns());
    pd.setPostProc(postProc);
    pd.setRequest(filterReq);
    pd.setResponse(filterResp);
    pd.setText(chain.isText());
    pd.setLogout(chain.isLogout());
    pd.setHttpRequestBase(chain.getHttpRequestBase());
    req.setAttribute(ProxyConstants.TREMOLO_PRXY_DATA, pd);
}
Also used : EmbPostProc(com.tremolosecurity.embedd.EmbPostProc) HashMap(java.util.HashMap) FilterChain(javax.servlet.FilterChain) HttpFilterChain(com.tremolosecurity.proxy.filter.HttpFilterChain) UriRequestProcess(com.tremolosecurity.proxy.postProcess.UriRequestProcess) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) UrlHolder(com.tremolosecurity.config.util.UrlHolder) HttpFilterResponse(com.tremolosecurity.proxy.filter.HttpFilterResponse) ServletException(javax.servlet.ServletException) PostProcess(com.tremolosecurity.proxy.filter.PostProcess) HttpFilterRequestImpl(com.tremolosecurity.proxy.filter.HttpFilterRequestImpl) HttpFilterResponseImpl(com.tremolosecurity.proxy.filter.HttpFilterResponseImpl) HttpFilterChainImpl(com.tremolosecurity.proxy.filter.HttpFilterChainImpl) OutputStreamWriter(java.io.OutputStreamWriter) HttpFilterChain(com.tremolosecurity.proxy.filter.HttpFilterChain) HttpFilterRequest(com.tremolosecurity.proxy.filter.HttpFilterRequest) PrintWriter(java.io.PrintWriter)

Aggregations

UrlHolder (com.tremolosecurity.config.util.UrlHolder)2 EmbPostProc (com.tremolosecurity.embedd.EmbPostProc)2 HttpFilterChain (com.tremolosecurity.proxy.filter.HttpFilterChain)2 HttpFilterChainImpl (com.tremolosecurity.proxy.filter.HttpFilterChainImpl)2 HttpFilterRequest (com.tremolosecurity.proxy.filter.HttpFilterRequest)2 HttpFilterRequestImpl (com.tremolosecurity.proxy.filter.HttpFilterRequestImpl)2 HttpFilterResponse (com.tremolosecurity.proxy.filter.HttpFilterResponse)2 HttpFilterResponseImpl (com.tremolosecurity.proxy.filter.HttpFilterResponseImpl)2 PostProcess (com.tremolosecurity.proxy.filter.PostProcess)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 FilterChain (javax.servlet.FilterChain)2 ServletException (javax.servlet.ServletException)2 PushRequestProcess (com.tremolosecurity.proxy.postProcess.PushRequestProcess)1 UriRequestProcess (com.tremolosecurity.proxy.postProcess.UriRequestProcess)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1