Search in sources :

Example 1 with EJBInvocation

use of org.glassfish.ejb.api.EJBInvocation in project Payara by payara.

the class EjbContainerPostHandler method handleRequest.

@Override
public boolean handleRequest(MessageContext context) {
    EJBInvocation inv = null;
    try {
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        InvocationManager invManager = wscImpl.getInvocationManager();
        inv = EJBInvocation.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) {
        wsUtil.throwSOAPFaultException(e.getMessage(), context);
    }
    return true;
}
Also used : UnmarshalException(java.rmi.UnmarshalException) InvocationManager(org.glassfish.api.invocation.InvocationManager) EJBInvocation(org.glassfish.ejb.api.EJBInvocation) Method(java.lang.reflect.Method) UnmarshalException(java.rmi.UnmarshalException)

Example 2 with EJBInvocation

use of org.glassfish.ejb.api.EJBInvocation in project Payara by payara.

the class EjbContainerPreHandler method handleRequest.

@Override
public boolean handleRequest(MessageContext context) {
    EJBInvocation inv = null;
    try {
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        InvocationManager invManager = wscImpl.getInvocationManager();
        inv = EJBInvocation.class.cast(invManager.getCurrentInvocation());
        Method method = wsUtil.getInvMethod((com.sun.xml.rpc.spi.runtime.Tie) inv.getWebServiceTie(), context);
        inv.setWebServiceMethod(method);
        if (!inv.authorizeWebService(method)) {
            throw new Exception(format(logger.getResourceBundle().getString(LogUtils.CLIENT_UNAUTHORIZED), method.toString()));
        }
    } catch (Exception e) {
        wsUtil.throwSOAPFaultException(e.getMessage(), context);
    }
    return true;
}
Also used : InvocationManager(org.glassfish.api.invocation.InvocationManager) EJBInvocation(org.glassfish.ejb.api.EJBInvocation) Method(java.lang.reflect.Method)

Example 3 with EJBInvocation

use of org.glassfish.ejb.api.EJBInvocation in project Payara by payara.

the class ImplementorCacheDelegateImpl method getImplementorFor.

public Implementor getImplementorFor(RuntimeEndpointInfo targetEndpoint) {
    Implementor implementor = null;
    try {
        synchronized (targetEndpoint) {
            implementor = (Implementor) implementorCache_.get(targetEndpoint);
            if (implementor == null) {
                implementor = createImplementor(targetEndpoint);
                implementorCache_.put(targetEndpoint, implementor);
            }
        }
        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
        InvocationManager invManager = wscImpl.getInvocationManager();
        ComponentInvocation inv = invManager.getCurrentInvocation();
        if (inv instanceof EJBInvocation)
            ((EJBInvocation) inv).setWebServiceTie(implementor.getTie());
    } catch (Throwable t) {
        RuntimeException re = new RuntimeException();
        re.initCause(t);
        throw re;
    }
    return implementor;
}
Also used : Implementor(com.sun.xml.rpc.spi.runtime.Implementor) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) InvocationManager(org.glassfish.api.invocation.InvocationManager) EJBInvocation(org.glassfish.ejb.api.EJBInvocation)

Example 4 with EJBInvocation

use of org.glassfish.ejb.api.EJBInvocation in project Payara by payara.

the class BasicPasswordAuthenticationService method doMap.

/**
 * Performs the actual mapping of the principal/userGroup to the
 * backendPrincipal by checking at the connector registry for all the
 * existing mapping. If a map is found the backendPrincipal is
 * returned else null is returned .
 */
private Principal doMap(String principalName, List groupNames, String roleName, RuntimeSecurityMap runtimeSecurityMap) {
    // Policy:
    // user_1, user_2, ... user_n
    // group_1/role_1, group_2/role_2, ... group_n/role_n
    // user contains *
    // role/group contains *
    HashMap userNameSecurityMap = (HashMap) runtimeSecurityMap.getUserMap();
    HashMap groupNameSecurityMap = (HashMap) runtimeSecurityMap.getGroupMap();
    // Check if caller's user-name is preset in the User Map
    if (userNameSecurityMap.containsKey(principalName)) {
        return (Principal) userNameSecurityMap.get(principalName);
    }
    // Check if caller's role is present in the Group Map
    if (isContainerContextAWebModuleObject() && roleName != null) {
        if (groupNameSecurityMap.containsKey(roleName)) {
            return (Principal) groupNameSecurityMap.get(roleName);
        }
    }
    // If ejb, use isCallerInRole
    if (isContainerContextAEJBContainerObject() && roleName == null) {
        ComponentInvocation componentInvocation = ConnectorRuntime.getRuntime().getInvocationManager().getCurrentInvocation();
        EJBInvocation ejbInvocation = (EJBInvocation) componentInvocation;
        EJBContext ejbcontext = ejbInvocation.getEJBContext();
        Set<Map.Entry> s = (Set<Map.Entry>) groupNameSecurityMap.entrySet();
        Iterator i = s.iterator();
        while (i.hasNext()) {
            Map.Entry mapEntry = (Map.Entry) i.next();
            String key = (String) mapEntry.getKey();
            Principal entry = (Principal) mapEntry.getValue();
            boolean isInRole = false;
            try {
                isInRole = ejbcontext.isCallerInRole(key);
            } catch (Exception ex) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "BasicPasswordAuthentication::caller not in role " + key);
                }
            }
            if (isInRole) {
                return entry;
            }
        }
    }
    // Check if caller's group(s) is/are present in the Group Map
    for (int j = 0; j < groupNames.size(); j++) {
        String groupName = (String) groupNames.get(j);
        if (groupNameSecurityMap.containsKey(groupName)) {
            return (Principal) groupNameSecurityMap.get(groupName);
        }
    }
    // Check if user name is * in Security Map
    if (userNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
        return (Principal) userNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
    }
    // Check if role/group name is * in Security Map
    if (groupNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
        return (Principal) groupNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
    }
    return null;
}
Also used : EJBContext(javax.ejb.EJBContext) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) EJBInvocation(org.glassfish.ejb.api.EJBInvocation) Principal(java.security.Principal)

Example 5 with EJBInvocation

use of org.glassfish.ejb.api.EJBInvocation in project Payara by payara.

the class EjbRuntimeEndpointInfo method prepareInvocation.

public Object prepareInvocation(boolean doPreInvoke) throws Exception {
    ComponentInvocation inv = null;
    AdapterInvocationInfo adapterInvInfo = new AdapterInvocationInfo();
    // init'ing jaxws is done here - this sequence is important
    if (adapter == null) {
        synchronized (this) {
            if (adapter == null) {
                try {
                    // Set webservice context here
                    // If the endpoint has a WebServiceContext with @Resource then
                    // that has to be used
                    EjbDescriptor ejbDesc = endpoint.getEjbComponentImpl();
                    Iterator<ResourceReferenceDescriptor> it = ejbDesc.getResourceReferenceDescriptors().iterator();
                    while (it.hasNext()) {
                        ResourceReferenceDescriptor r = it.next();
                        if (r.isWebServiceContext()) {
                            Iterator<InjectionTarget> iter = r.getInjectionTargets().iterator();
                            boolean matchingClassFound = false;
                            while (iter.hasNext()) {
                                InjectionTarget target = iter.next();
                                if (ejbDesc.getEjbClassName().equals(target.getClassName())) {
                                    matchingClassFound = true;
                                    break;
                                }
                            }
                            if (!matchingClassFound) {
                                continue;
                            }
                            try {
                                javax.naming.InitialContext ic = new javax.naming.InitialContext();
                                wsCtxt = (WebServiceContextImpl) ic.lookup("java:comp/env/" + r.getName());
                            } catch (Throwable t) {
                                if (logger.isLoggable(Level.FINE)) {
                                    logger.log(Level.FINE, LogUtils.ERROR_EREI, t.getCause());
                                }
                            }
                        }
                    }
                    if (wsCtxt == null) {
                        wsCtxt = new WebServiceContextImpl();
                    }
                } catch (Throwable t) {
                    LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
                    return null;
                }
            }
        }
    }
    if (doPreInvoke) {
        inv = container.startInvocation();
        adapterInvInfo.setInv(inv);
    }
    // Now process handlers and init jaxws RI
    synchronized (this) {
        if (!handlersConfigured && doPreInvoke) {
            try {
                WsUtil wsu = new WsUtil();
                String implClassName = endpoint.getEjbComponentImpl().getEjbClassName();
                Class clazz = container.getEndpointClassLoader().loadClass(implClassName);
                // Get the proper binding using BindingID
                String givenBinding = endpoint.getProtocolBinding();
                // Get list of all wsdls and schema
                SDDocumentSource primaryWsdl = null;
                Collection docs = null;
                if (endpoint.getWebService().hasWsdlFile()) {
                    WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                    ApplicationRegistry appRegistry = wscImpl.getApplicationRegistry();
                    ApplicationInfo appInfo = appRegistry.get(endpoint.getBundleDescriptor().getApplication().getRegistrationName());
                    URI deployedDir = appInfo.getSource().getURI();
                    URL pkgedWsdl;
                    if (deployedDir != null) {
                        if (endpoint.getBundleDescriptor().getApplication().isVirtual()) {
                            pkgedWsdl = deployedDir.resolve(endpoint.getWebService().getWsdlFileUri()).toURL();
                        } else {
                            String moduleUri1 = endpoint.getBundleDescriptor().getModuleDescriptor().getArchiveUri();
                            // Fix for issue 7024099
                            // Only replace the last "." with "_" for moduleDescriptor's archive uri
                            String moduleUri = FileUtils.makeFriendlyFilenameExtension(moduleUri1);
                            pkgedWsdl = deployedDir.resolve(moduleUri + "/" + endpoint.getWebService().getWsdlFileUri()).toURL();
                        }
                    } else {
                        pkgedWsdl = endpoint.getWebService().getWsdlFileUrl();
                    }
                    if (pkgedWsdl != null) {
                        primaryWsdl = SDDocumentSource.create(pkgedWsdl);
                        docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
                    }
                }
                // Create a Container to pass ServletContext and also inserting the pipe
                JAXWSContainer container = new JAXWSContainer(null, endpoint);
                // Get catalog info
                java.net.URL catalogURL = clazz.getResource('/' + endpoint.getBundleDescriptor().getDeploymentDescriptorDir() + File.separator + "jax-ws-catalog.xml");
                // Create Binding and set service side handlers on this binding
                boolean mtomEnabled = wsu.getMtom(endpoint);
                WSBinding binding = null;
                ArrayList<WebServiceFeature> wsFeatures = new ArrayList<WebServiceFeature>();
                // Only if MTOm is enabled create the Binding with the MTOMFeature
                if (mtomEnabled) {
                    int mtomThreshold = endpoint.getMtomThreshold() != null ? Integer.parseInt(endpoint.getMtomThreshold()) : 0;
                    MTOMFeature mtom = new MTOMFeature(true, mtomThreshold);
                    wsFeatures.add(mtom);
                }
                Addressing addressing = endpoint.getAddressing();
                if (endpoint.getAddressing() != null) {
                    AddressingFeature addressingFeature = new AddressingFeature(addressing.isEnabled(), addressing.isRequired(), getResponse(addressing.getResponses()));
                    wsFeatures.add(addressingFeature);
                }
                if (wsFeatures.size() > 0) {
                    binding = BindingID.parse(givenBinding).createBinding(wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
                } else {
                    binding = BindingID.parse(givenBinding).createBinding();
                }
                wsu.configureJAXWSServiceHandlers(endpoint, endpoint.getProtocolBinding(), binding);
                // See if it is configured with JAX-WS extension InstanceResolver annotation like
                // @com.sun.xml.ws.developer.servlet.HttpSessionScope or @com.sun.xml.ws.developer.Stateful
                // #GLASSFISH-21081
                InstanceResolver ir = InstanceResolver.createFromInstanceResolverAnnotation(clazz);
                // TODO - Implement 109 StatefulInstanceResolver ??
                if (ir == null) {
                    // use our own InstanceResolver that does not call @PostConstuct method before
                    // @Resource injections have happened.
                    ir = new InstanceResolverImpl(clazz);
                }
                // Create the jaxws2.1 invoker and use this
                Invoker invoker = ir.createInvoker();
                WSEndpoint wsep = WSEndpoint.create(// The endpoint class
                clazz, // we do not want JAXWS to process @HandlerChain
                false, // the invoker
                new EjbInvokerImpl(clazz, invoker, webServiceEndpointServant, wsCtxt), // the service QName
                endpoint.getServiceName(), // the port
                endpoint.getWsdlPort(), container, // Derive binding
                binding, // primary WSDL
                primaryWsdl, // Collection of imported WSDLs and schema
                docs, catalogURL);
                String uri = endpoint.getEndpointAddressUri();
                String urlPattern = uri.startsWith("/") ? uri : "/" + uri;
                // All set; Create the adapter
                if (adapterList == null) {
                    adapterList = new ServletAdapterList();
                }
                adapter = adapterList.createAdapter(endpoint.getName(), urlPattern, wsep);
                handlersConfigured = true;
            } catch (Throwable t) {
                LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
                adapter = null;
            }
        }
    }
    // set it using this method
    synchronized (this) {
        addWSContextInfo(wsCtxt);
        if (inv != null && inv instanceof EJBInvocation) {
            EJBInvocation ejbInv = (EJBInvocation) inv;
            ejbInv.setWebServiceContext(wsCtxt);
        }
    }
    adapterInvInfo.setAdapter(adapter);
    return adapterInvInfo;
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) AddressingFeature(javax.xml.ws.soap.AddressingFeature) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) URL(java.net.URL) InstanceResolver(com.sun.xml.ws.api.server.InstanceResolver) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ArrayList(java.util.ArrayList) URI(java.net.URI) URL(java.net.URL) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) Invoker(com.sun.xml.ws.api.server.Invoker) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) MTOMFeature(javax.xml.ws.soap.MTOMFeature) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) WebServiceFeature(javax.xml.ws.WebServiceFeature) Collection(java.util.Collection) EJBInvocation(org.glassfish.ejb.api.EJBInvocation)

Aggregations

EJBInvocation (org.glassfish.ejb.api.EJBInvocation)6 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)4 InvocationManager (org.glassfish.api.invocation.InvocationManager)4 Method (java.lang.reflect.Method)2 Principal (java.security.Principal)2 WebModule (com.sun.enterprise.web.WebModule)1 Implementor (com.sun.xml.rpc.spi.runtime.Implementor)1 WSBinding (com.sun.xml.ws.api.WSBinding)1 InstanceResolver (com.sun.xml.ws.api.server.InstanceResolver)1 Invoker (com.sun.xml.ws.api.server.Invoker)1 SDDocumentSource (com.sun.xml.ws.api.server.SDDocumentSource)1 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)1 ServletAdapterList (com.sun.xml.ws.transport.http.servlet.ServletAdapterList)1 URI (java.net.URI)1 URL (java.net.URL)1 UnmarshalException (java.rmi.UnmarshalException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 EJBContext (javax.ejb.EJBContext)1 WebServiceFeature (javax.xml.ws.WebServiceFeature)1