Search in sources :

Example 1 with SkeletonStrategy

use of org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy in project wildfly by wildfly.

the class EjbIIOPDeploymentUnitProcessor method processEjb.

private void processEjb(final EJBComponentDescription componentDescription, final DeploymentReflectionIndex deploymentReflectionIndex, final Module module, final ServiceTarget serviceTarget, final IIOPMetaData iiopMetaData) {
    componentDescription.setExposedViaIiop(true);
    // Create bean method mappings for container invoker
    final EJBViewDescription remoteView = componentDescription.getEjbRemoteView();
    final Class<?> remoteClass;
    try {
        remoteClass = ClassLoadingUtils.loadClass(remoteView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    final EJBViewDescription homeView = componentDescription.getEjbHomeView();
    final Class<?> homeClass;
    try {
        homeClass = ClassLoadingUtils.loadClass(homeView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    componentDescription.getEjbHomeView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    componentDescription.getEjbRemoteView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    final InterfaceAnalysis remoteInterfaceAnalysis;
    try {
        // TODO: change all this to use the deployment reflection index
        remoteInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(remoteClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> beanMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] remoteAttrs = remoteInterfaceAnalysis.getAttributes();
    for (int i = 0; i < remoteAttrs.length; i++) {
        final OperationAnalysis op = remoteAttrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            // translate to the deployment reflection index method
            // TODO: this needs to be fixed so it just returns the correct method
            final Method method = translateMethod(deploymentReflectionIndex, op);
            beanMethodMap.put(op.getIDLName(), new SkeletonStrategy(method));
            final OperationAnalysis setop = remoteAttrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                // translate to the deployment reflection index method
                // TODO: this needs to be fixed so it just returns the correct method
                final Method realSetmethod = translateMethod(deploymentReflectionIndex, setop);
                beanMethodMap.put(setop.getIDLName(), new SkeletonStrategy(realSetmethod));
            }
        }
    }
    final OperationAnalysis[] ops = remoteInterfaceAnalysis.getOperations();
    for (int i = 0; i < ops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", ops[i].getJavaName(), ops[i].getIDLName());
        beanMethodMap.put(ops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, ops[i])));
    }
    // Initialize repository ids of remote interface
    final String[] beanRepositoryIds = remoteInterfaceAnalysis.getAllTypeIds();
    // Create home method mappings for container invoker
    final InterfaceAnalysis homeInterfaceAnalysis;
    try {
        // TODO: change all this to use the deployment reflection index
        homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> homeMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] attrs = homeInterfaceAnalysis.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        final OperationAnalysis op = attrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            homeMethodMap.put(op.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, op)));
            final OperationAnalysis setop = attrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                homeMethodMap.put(setop.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, setop)));
            }
        }
    }
    final OperationAnalysis[] homeops = homeInterfaceAnalysis.getOperations();
    for (int i = 0; i < homeops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", homeops[i].getJavaName(), homeops[i].getIDLName());
        homeMethodMap.put(homeops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, homeops[i])));
    }
    // Initialize repository ids of home interface
    final String[] homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
    final EjbIIOPService service = new EjbIIOPService(beanMethodMap, beanRepositoryIds, homeMethodMap, homeRepositoryIds, settingsService.isUseQualifiedName(), iiopMetaData, module);
    final ServiceBuilder<EjbIIOPService> builder = serviceTarget.addService(componentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), service);
    builder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
    builder.addDependency(homeView.getServiceName(), ComponentView.class, service.getHomeView());
    builder.addDependency(remoteView.getServiceName(), ComponentView.class, service.getRemoteView());
    builder.addDependency(CorbaORBService.SERVICE_NAME, ORB.class, service.getOrb());
    builder.addDependency(POARegistry.SERVICE_NAME, POARegistry.class, service.getPoaRegistry());
    builder.addDependency(CorbaPOAService.INTERFACE_REPOSITORY_SERVICE_NAME, POA.class, service.getIrPoa());
    builder.addDependency(CorbaNamingService.SERVICE_NAME, NamingContextExt.class, service.getCorbaNamingContext());
    builder.addDependency(IORSecConfigMetaDataService.SERVICE_NAME, IORSecurityConfigMetaData.class, service.getIORSecConfigMetaDataInjectedValue());
    builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoaderInjectedValue());
    builder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, TransactionManagerService.class, service.getTransactionManagerInjectedValue());
    builder.install();
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) HashMap(java.util.HashMap) SkeletonStrategy(org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy) Method(java.lang.reflect.Method) OperationAnalysis(org.wildfly.iiop.openjdk.rmi.OperationAnalysis) InterfaceAnalysis(org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis) AttributeAnalysis(org.wildfly.iiop.openjdk.rmi.AttributeAnalysis) RMIIIOPViolationException(org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException) EjbIIOPService(org.jboss.as.ejb3.iiop.EjbIIOPService)

Example 2 with SkeletonStrategy

use of org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy in project wildfly by wildfly.

the class EjbCorbaServant method invoke.

// Implementation of the interface LocalIIOPInvoker ------------------------
/**
 * Receives intra-VM invocations on this servant's <code>EJBObject</code>s
 * and forwards them to the bean container, through the JBoss
 * <code>MBean</code>
 * server.
 */
public Object invoke(String opName, Object[] arguments, Transaction tx, Principal identity, Object credential) throws Exception {
    EjbLogger.ROOT_LOGGER.tracef("EJBObject local invocation: %s", opName);
    SkeletonStrategy op = methodInvokerMap.get(opName);
    if (op == null) {
        throw new BAD_OPERATION(opName);
    }
    if (tx != null) {
        transactionManager.resume(tx);
    }
    try {
        final InterceptorContext interceptorContext = new InterceptorContext();
        prepareInterceptorContext(op, arguments, interceptorContext);
        return componentView.invoke(interceptorContext);
    } finally {
        if (tx != null && transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
            transactionManager.suspend();
        }
    }
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) SkeletonStrategy(org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION)

Example 3 with SkeletonStrategy

use of org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy in project wildfly by wildfly.

the class EjbCorbaServant method _invoke.

/**
 * Receives IIOP requests to this servant's <code>EJBObject</code>s
 * and forwards them to the bean container, through the JBoss
 * <code>MBean</code> server.
 */
public OutputStream _invoke(final String opName, final InputStream in, final ResponseHandler handler) {
    EjbLogger.ROOT_LOGGER.tracef("EJBObject invocation: %s", opName);
    SkeletonStrategy op = methodInvokerMap.get(opName);
    if (op == null) {
        EjbLogger.ROOT_LOGGER.debugf("Unable to find opname '%s' valid operations:%s", opName, methodInvokerMap.keySet());
        throw new BAD_OPERATION(opName);
    }
    final NamespaceContextSelector selector = componentView.getComponent().getNamespaceContextSelector();
    final ClassLoader oldCl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
    NamespaceContextSelector.pushCurrentSelector(selector);
    try {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader);
        org.omg.CORBA_2_3.portable.OutputStream out;
        try {
            Object retVal;
            if (!home && opName.equals("_get_handle")) {
                retVal = new HandleImplIIOP(orb.object_to_string(_this_object()));
            } else if (home && opName.equals("_get_homeHandle")) {
                retVal = homeHandle;
            } else if (home && opName.equals("_get_EJBMetaData")) {
                retVal = ejbMetaData;
            } else {
                Principal identityPrincipal = null;
                Principal principal = null;
                Object credential = null;
                if (this.sasCurrent != null) {
                    final byte[] incomingIdentity = this.sasCurrent.get_incoming_principal_name();
                    // we have an identity token, which is a trust based mechanism
                    if (incomingIdentity != null && incomingIdentity.length > 0) {
                        String name = new String(incomingIdentity, StandardCharsets.UTF_8);
                        int domainIndex = name.indexOf('@');
                        if (domainIndex > 0)
                            name = name.substring(0, domainIndex);
                        identityPrincipal = new NamePrincipal(name);
                    }
                    final byte[] incomingUsername = this.sasCurrent.get_incoming_username();
                    if (incomingUsername != null && incomingUsername.length > 0) {
                        final byte[] incomingPassword = this.sasCurrent.get_incoming_password();
                        String name = new String(incomingUsername, StandardCharsets.UTF_8);
                        int domainIndex = name.indexOf('@');
                        if (domainIndex > 0) {
                            name = name.substring(0, domainIndex);
                        }
                        principal = new NamePrincipal(name);
                        credential = new String(incomingPassword, StandardCharsets.UTF_8).toCharArray();
                    }
                }
                final Object[] params = op.readParams((org.omg.CORBA_2_3.portable.InputStream) in);
                if (!this.home && opName.equals("isIdentical") && params.length == 1) {
                    // handle isIdentical specially
                    Object val = params[0];
                    retVal = val instanceof org.omg.CORBA.Object && handleIsIdentical((org.omg.CORBA.Object) val);
                } else {
                    if (this.securityDomain != null) {
                        // an elytron security domain is available: authenticate and authorize the client before invoking the component.
                        SecurityIdentity identity = this.securityDomain.getAnonymousSecurityIdentity();
                        AuthenticationConfiguration authenticationConfiguration = AuthenticationConfiguration.EMPTY;
                        if (identityPrincipal != null) {
                            // permission to run as the identity token principal.
                            if (principal != null) {
                                char[] password = (char[]) credential;
                                authenticationConfiguration = authenticationConfiguration.useName(principal.getName()).usePassword(password);
                                SecurityIdentity authenticatedIdentity = this.authenticate(principal, password);
                                identity = authenticatedIdentity.createRunAsIdentity(identityPrincipal.getName(), true);
                            } else {
                                // no TLS nor initial context token found - check if the anonymous identity has
                                // permission to run as the identity principal.
                                identity = this.securityDomain.getAnonymousSecurityIdentity().createRunAsIdentity(identityPrincipal.getName(), true);
                            }
                        } else if (principal != null) {
                            char[] password = (char[]) credential;
                            // we have an initial context token containing a username/password pair.
                            authenticationConfiguration = authenticationConfiguration.useName(principal.getName()).usePassword(password);
                            identity = this.authenticate(principal, password);
                        }
                        final InterceptorContext interceptorContext = new InterceptorContext();
                        this.prepareInterceptorContext(op, params, interceptorContext);
                        try {
                            final AuthenticationContext context = AuthenticationContext.captureCurrent().with(MatchRule.ALL.matchProtocol("iiop"), authenticationConfiguration);
                            retVal = identity.runAs((PrivilegedExceptionAction<Object>) () -> context.run((PrivilegedExceptionAction<Object>) () -> this.componentView.invoke(interceptorContext)));
                        } catch (PrivilegedActionException e) {
                            throw e.getCause();
                        }
                    } else {
                        // legacy security behavior: setup the security context if a SASCurrent is available and invoke the component.
                        // One of the EJB security interceptors will authenticate and authorize the client.
                        final InterceptorContext interceptorContext = new InterceptorContext();
                        prepareInterceptorContext(op, params, interceptorContext);
                        retVal = this.componentView.invoke(interceptorContext);
                    }
                }
            }
            out = (org.omg.CORBA_2_3.portable.OutputStream) handler.createReply();
            if (op.isNonVoid()) {
                op.writeRetval(out, retVal);
            }
        } catch (Throwable e) {
            EjbLogger.ROOT_LOGGER.trace("Exception in EJBObject invocation", e);
            if (e instanceof MBeanException) {
                e = ((MBeanException) e).getTargetException();
            }
            RmiIdlUtil.rethrowIfCorbaSystemException(e);
            out = (org.omg.CORBA_2_3.portable.OutputStream) handler.createExceptionReply();
            op.writeException(out, e);
        }
        return out;
    } finally {
        NamespaceContextSelector.popCurrentSelector();
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldCl);
    }
}
Also used : ServerAuthenticationContext(org.wildfly.security.auth.server.ServerAuthenticationContext) AuthenticationContext(org.wildfly.security.auth.client.AuthenticationContext) NamePrincipal(org.wildfly.security.auth.principal.NamePrincipal) OutputStream(org.omg.CORBA.portable.OutputStream) NamespaceContextSelector(org.jboss.as.naming.context.NamespaceContextSelector) HandleImplIIOP(org.jboss.ejb.iiop.HandleImplIIOP) InterceptorContext(org.jboss.invocation.InterceptorContext) AuthenticationConfiguration(org.wildfly.security.auth.client.AuthenticationConfiguration) PrivilegedActionException(java.security.PrivilegedActionException) SkeletonStrategy(org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) SecurityIdentity(org.wildfly.security.auth.server.SecurityIdentity) MBeanException(javax.management.MBeanException) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) NamePrincipal(org.wildfly.security.auth.principal.NamePrincipal) Principal(java.security.Principal)

Aggregations

SkeletonStrategy (org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy)3 InterceptorContext (org.jboss.invocation.InterceptorContext)2 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)2 Method (java.lang.reflect.Method)1 Principal (java.security.Principal)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 HashMap (java.util.HashMap)1 MBeanException (javax.management.MBeanException)1 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)1 EjbIIOPService (org.jboss.as.ejb3.iiop.EjbIIOPService)1 NamespaceContextSelector (org.jboss.as.naming.context.NamespaceContextSelector)1 HandleImplIIOP (org.jboss.ejb.iiop.HandleImplIIOP)1 OutputStream (org.omg.CORBA.portable.OutputStream)1 AttributeAnalysis (org.wildfly.iiop.openjdk.rmi.AttributeAnalysis)1 InterfaceAnalysis (org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis)1 OperationAnalysis (org.wildfly.iiop.openjdk.rmi.OperationAnalysis)1 RMIIIOPViolationException (org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException)1 AuthenticationConfiguration (org.wildfly.security.auth.client.AuthenticationConfiguration)1 AuthenticationContext (org.wildfly.security.auth.client.AuthenticationContext)1