Search in sources :

Example 1 with WebComponentInvocation

use of com.sun.enterprise.web.WebComponentInvocation in project Payara by payara.

the class J2EEInstanceListener method handleAfterEvent.

private void handleAfterEvent(InstanceEvent event, InstanceEvent.EventType eventType) {
    Wrapper wrapper = event.getWrapper();
    Context context = (Context) wrapper.getParent();
    if (!(context instanceof WebModule)) {
        return;
    }
    WebModule wm = (WebModule) context;
    Object instance;
    if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT) {
        instance = event.getFilter();
    } else {
        instance = event.getServlet();
    }
    if (instance == null) {
        return;
    }
    // Emit monitoring probe event
    if (instance instanceof Servlet) {
        if (eventType == InstanceEvent.EventType.AFTER_INIT_EVENT) {
            wm.servletInitializedEvent(wrapper.getName());
        } else if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
            wm.servletDestroyedEvent(wrapper.getName());
        }
    }
    // EE invocation context
    try {
        if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT && !DefaultServlet.class.equals(instance.getClass()) && !JspServlet.class.equals(instance.getClass())) {
            injectionMgr.destroyManagedObject(instance, false);
        }
    } catch (InjectionException ie) {
        String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
        msg = MessageFormat.format(msg, new Object[] { eventType, wm });
        _logger.log(Level.SEVERE, msg, ie);
    }
    ComponentInvocation inv = new WebComponentInvocation(wm, instance);
    try {
        im.postInvoke(inv);
    } catch (Exception ex) {
        String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
        msg = MessageFormat.format(msg, new Object[] { eventType, wm });
        throw new RuntimeException(msg, ex);
    } finally {
        if (eventType == InstanceEvent.EventType.AFTER_DESTROY_EVENT) {
            if (tm != null) {
                tm.componentDestroyed(instance, inv);
            }
        } else if (eventType == InstanceEvent.EventType.AFTER_FILTER_EVENT || eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
            // Emit monitoring probe event
            if (eventType == InstanceEvent.EventType.AFTER_SERVICE_EVENT) {
                ServletResponse response = event.getResponse();
                int status = -1;
                if (response != null && response instanceof HttpServletResponse) {
                    status = ((HttpServletResponse) response).getStatus();
                }
                wm.afterServiceEvent(wrapper.getName(), status);
            }
            // BEGIN IASRI# 4646060
            if (im.getCurrentInvocation() == null) {
                // END IASRI# 4646060
                try {
                    // clear security context
                    Realm ra = context.getRealm();
                    if (ra != null && (ra instanceof RealmInitializer)) {
                        // cleanup not only securitycontext but also PolicyContext
                        ((RealmInitializer) ra).logout();
                    }
                } catch (Exception ex) {
                    String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
                    msg = MessageFormat.format(msg, new Object[] { eventType, wm });
                    _logger.log(Level.SEVERE, msg, ex);
                }
                if (tm != null) {
                    try {
                        if (tm.getTransaction() != null) {
                            tm.rollback();
                        }
                        tm.cleanTxnTimeout();
                    } catch (Exception ex) {
                    }
                }
            }
            if (tm != null) {
                tm.componentDestroyed(instance, inv);
            }
        }
    }
}
Also used : AppServSecurityContext(com.sun.enterprise.security.integration.AppServSecurityContext) ServerContext(org.glassfish.internal.api.ServerContext) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) RealmInitializer(com.sun.enterprise.security.integration.RealmInitializer) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebModule(com.sun.enterprise.web.WebModule) String(java.lang.String) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) JspServlet(org.apache.jasper.servlet.JspServlet) Servlet(javax.servlet.Servlet) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) DefaultServlet(org.apache.catalina.servlets.DefaultServlet)

Example 2 with WebComponentInvocation

use of com.sun.enterprise.web.WebComponentInvocation in project Payara by payara.

the class WebContainerListener method postInvoke.

private void postInvoke(WebModule ctx) {
    WebModule wm = (WebModule) ctx;
    ComponentInvocation inv = new WebComponentInvocation(wm);
    invocationMgr.postInvoke(inv);
}
Also used : WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebModule(com.sun.enterprise.web.WebModule)

Example 3 with WebComponentInvocation

use of com.sun.enterprise.web.WebComponentInvocation in project Payara by payara.

the class ServletPostHandler method handleRequest.

@Override
public boolean handleRequest(MessageContext context) {
    WebComponentInvocation inv = null;
    try {
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        InvocationManager invManager = wscImpl.getInvocationManager();
        inv = WebComponentInvocation.class.cast(invManager.getCurrentInvocation());
        Method webServiceMethodInPreHandler = inv.getWebServiceMethod();
        if (webServiceMethodInPreHandler != null) {
            // Now that application handlers have run, do another method
            // lookup and compare the results with the original one.  This
            // ensures that the application handlers have not changed
            // the message context in any way that would impact which
            // method is invoked.
            Method postHandlerMethod = wsUtil.getInvMethod((com.sun.xml.rpc.spi.runtime.Tie) inv.getWebServiceTie(), context);
            if (!webServiceMethodInPreHandler.equals(postHandlerMethod)) {
                throw new UnmarshalException("Original method " + webServiceMethodInPreHandler + " does not match post-handler method ");
            }
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, LogUtils.POST_WEBHANDLER_ERROR, e.toString());
        wsUtil.throwSOAPFaultException(e.getMessage(), context);
    }
    return true;
}
Also used : WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) UnmarshalException(java.rmi.UnmarshalException) InvocationManager(org.glassfish.api.invocation.InvocationManager) Method(java.lang.reflect.Method) UnmarshalException(java.rmi.UnmarshalException)

Example 4 with WebComponentInvocation

use of com.sun.enterprise.web.WebComponentInvocation in project Payara by payara.

the class ServletPreHandler method handleRequest.

@Override
public boolean handleRequest(MessageContext context) {
    WebComponentInvocation inv = null;
    try {
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        InvocationManager invManager = wscImpl.getInvocationManager();
        inv = WebComponentInvocation.class.cast(invManager.getCurrentInvocation());
        com.sun.xml.rpc.spi.runtime.Tie tie = (com.sun.xml.rpc.spi.runtime.Tie) inv.getWebServiceTie();
        if (tie == null) {
            Implementor implementor = (Implementor) context.getProperty(MessageContextProperties.IMPLEMENTOR);
            tie = implementor.getTie();
            inv.setWebServiceTie(tie);
        }
        inv.setWebServiceMethod(wsUtil.getInvMethod(tie, context));
    } catch (Exception e) {
        logger.log(Level.WARNING, LogUtils.PRE_WEBHANDLER_ERROR, e.toString());
        wsUtil.throwSOAPFaultException(e.getMessage(), context);
    }
    return true;
}
Also used : Implementor(com.sun.xml.rpc.server.http.Implementor) InvocationManager(org.glassfish.api.invocation.InvocationManager) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation)

Example 5 with WebComponentInvocation

use of com.sun.enterprise.web.WebComponentInvocation in project Payara by payara.

the class J2EEInstanceListener method handleBeforeEvent.

private void handleBeforeEvent(InstanceEvent event, InstanceEvent.EventType eventType) {
    Context context = (Context) event.getWrapper().getParent();
    if (!(context instanceof WebModule)) {
        return;
    }
    WebModule wm = (WebModule) context;
    Object instance;
    if (eventType == InstanceEvent.EventType.BEFORE_FILTER_EVENT) {
        instance = event.getFilter();
    } else {
        instance = event.getServlet();
    }
    // set security context
    // BEGIN IAfSRI 4688449
    // try {
    Realm ra = context.getRealm();
    // START OF IASRI 4713234
    if (ra != null) {
        ServletRequest request = event.getRequest();
        if (request != null && request instanceof HttpServletRequest) {
            HttpServletRequest hreq = (HttpServletRequest) request;
            HttpServletRequest base = hreq;
            Principal prin = hreq.getUserPrincipal();
            Principal basePrincipal = prin;
            boolean wrapped = false;
            while (prin != null) {
                if (base instanceof ServletRequestWrapper) {
                    // unwarp any wrappers to find the base object
                    ServletRequest sr = ((ServletRequestWrapper) base).getRequest();
                    if (sr instanceof HttpServletRequest) {
                        base = (HttpServletRequest) sr;
                        wrapped = true;
                        continue;
                    }
                }
                if (wrapped) {
                    basePrincipal = base.getUserPrincipal();
                } else if (base instanceof RequestFacade) {
                    // when we can identify see we have the texact class.
                    if (base.getClass() != RequestFacade.class) {
                        basePrincipal = ((RequestFacade) base).getUnwrappedCoyoteRequest().getUserPrincipal();
                    }
                } else {
                    basePrincipal = base.getUserPrincipal();
                }
                break;
            }
            if (prin != null && prin == basePrincipal && prin.getClass().getName().equals(SecurityConstants.WEB_PRINCIPAL_CLASS)) {
                securityContext.setSecurityContextWithPrincipal(prin);
            } else if (prin != basePrincipal) {
                // the wrapper has overridden getUserPrincipal
                // reject the request if the wrapper does not have
                // the necessary permission.
                checkObjectForDoAsPermission(hreq);
                securityContext.setSecurityContextWithPrincipal(prin);
            }
        }
    }
    // END OF IASRI 4713234
    // END IASRI 4688449
    ComponentInvocation inv;
    if (eventType == InstanceEvent.EventType.BEFORE_INIT_EVENT) {
        // The servletName is not avaiable from servlet instance before servlet init.
        // We have to pass the servletName to ComponentInvocation so it can be retrieved
        // in RealmAdapter.getServletName().
        inv = new WebComponentInvocation(wm, instance, event.getWrapper().getName());
    } else {
        inv = new WebComponentInvocation(wm, instance);
    }
    try {
        im.preInvoke(inv);
        if (eventType == InstanceEvent.EventType.BEFORE_SERVICE_EVENT) {
            // Emit monitoring probe event
            wm.beforeServiceEvent(event.getWrapper().getName());
            // enlist resources with TM for service method
            if (tm != null) {
                tm.enlistComponentResources();
            }
        }
    } catch (Exception ex) {
        // See CR 6920895
        im.postInvoke(inv);
        String msg = _rb.getString(LogFacade.EXCEPTION_DURING_HANDLE_EVENT);
        msg = MessageFormat.format(msg, new Object[] { eventType, wm });
        throw new RuntimeException(msg, ex);
    }
}
Also used : AppServSecurityContext(com.sun.enterprise.security.integration.AppServSecurityContext) ServerContext(org.glassfish.internal.api.ServerContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) WebModule(com.sun.enterprise.web.WebModule) String(java.lang.String) RequestFacade(org.apache.catalina.connector.RequestFacade) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) HttpServletRequest(javax.servlet.http.HttpServletRequest) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation)

Aggregations

WebComponentInvocation (com.sun.enterprise.web.WebComponentInvocation)7 WebModule (com.sun.enterprise.web.WebModule)5 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)5 InjectionException (com.sun.enterprise.container.common.spi.util.InjectionException)2 AppServSecurityContext (com.sun.enterprise.security.integration.AppServSecurityContext)2 String (java.lang.String)2 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)2 InvocationManager (org.glassfish.api.invocation.InvocationManager)2 ServerContext (org.glassfish.internal.api.ServerContext)2 RealmInitializer (com.sun.enterprise.security.integration.RealmInitializer)1 Implementor (com.sun.xml.rpc.server.http.Implementor)1 Adapter (com.sun.xml.ws.api.server.Adapter)1 TCPAdapter (com.sun.xml.ws.transport.tcp.server.TCPAdapter)1 Method (java.lang.reflect.Method)1 UnmarshalException (java.rmi.UnmarshalException)1 Servlet (javax.servlet.Servlet)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1