Search in sources :

Example 1 with OutputStream

use of org.omg.CORBA.portable.OutputStream in project jdk8u_jdk by JetBrains.

the class _HelloImpl_Tie method _invoke.

public OutputStream _invoke(String method, InputStream _in, ResponseHandler reply) throws SystemException {
    try {
        org.omg.CORBA_2_3.portable.InputStream in = (org.omg.CORBA_2_3.portable.InputStream) _in;
        switch(method.length()) {
            case 8:
                if (method.equals("sayHello")) {
                    String arg0 = (String) in.read_value(String.class);
                    String result = target.sayHello(arg0);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 14:
                if (method.equals("sayHelloToTest")) {
                    Test arg0 = (Test) in.read_value(Test.class);
                    String result = target.sayHelloToTest(arg0);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 19:
                if (method.equals("sayHelloWithHashMap")) {
                    ConcurrentHashMap arg0 = (ConcurrentHashMap) in.read_value(ConcurrentHashMap.class);
                    String result = target.sayHelloWithHashMap(arg0);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 20:
                if (method.equals("sayHelloWithHashMap2")) {
                    HashMap arg0 = (HashMap) in.read_value(HashMap.class);
                    String result = target.sayHelloWithHashMap2(arg0);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 23:
                if (method.equals("sayHelloWithInetAddress")) {
                    InetAddress arg0 = (InetAddress) in.read_value(InetAddress.class);
                    String result = target.sayHelloWithInetAddress(arg0);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
            case 25:
                if (method.equals("sayHelloWithReentrantLock")) {
                    ReentrantLock arg0 = (ReentrantLock) in.read_value(ReentrantLock.class);
                    String result = target.sayHelloWithReentrantLock(arg0);
                    org.omg.CORBA_2_3.portable.OutputStream out = (org.omg.CORBA_2_3.portable.OutputStream) reply.createReply();
                    out.write_value(result, String.class);
                    return out;
                }
        }
        throw new BAD_OPERATION();
    } catch (SystemException ex) {
        throw ex;
    } catch (Throwable ex) {
        throw new UnknownException(ex);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) InputStream(org.omg.CORBA.portable.InputStream) OutputStream(org.omg.CORBA.portable.OutputStream) SystemException(org.omg.CORBA.SystemException) UnknownException(org.omg.CORBA.portable.UnknownException) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InetAddress(java.net.InetAddress)

Example 2 with OutputStream

use of org.omg.CORBA.portable.OutputStream 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.
                        SecurityContext legacyContext = null;
                        if (this.legacySecurityDomain != null && (identityPrincipal != null || principal != null)) {
                            // we don't have any real way to establish trust in identity based auth so we just use
                            // the SASCurrent as a credential, and a custom legacy login module can make a decision for us.
                            final Object finalCredential = identityPrincipal != null ? this.sasCurrent : credential;
                            final Principal finalPrincipal = identityPrincipal != null ? identityPrincipal : principal;
                            if (WildFlySecurityManager.isChecking()) {
                                legacyContext = AccessController.doPrivileged((PrivilegedExceptionAction<SecurityContext>) () -> {
                                    SecurityContext sc = SecurityContextFactory.createSecurityContext(this.legacySecurityDomain);
                                    sc.getUtil().createSubjectInfo(finalPrincipal, finalCredential, null);
                                    return sc;
                                });
                            } else {
                                legacyContext = SecurityContextFactory.createSecurityContext(this.legacySecurityDomain);
                                legacyContext.getUtil().createSubjectInfo(finalPrincipal, finalCredential, null);
                            }
                        }
                        if (legacyContext != null) {
                            setSecurityContextOnAssociation(legacyContext);
                        }
                        try {
                            final InterceptorContext interceptorContext = new InterceptorContext();
                            if (legacyContext != null) {
                                interceptorContext.putPrivateData(SecurityContext.class, legacyContext);
                            }
                            prepareInterceptorContext(op, params, interceptorContext);
                            retVal = this.componentView.invoke(interceptorContext);
                        } finally {
                            if (legacyContext != null) {
                                clearSecurityContextOnAssociation();
                            }
                        }
                    }
                }
            }
            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) SecurityContext(org.jboss.security.SecurityContext) MBeanException(javax.management.MBeanException) BAD_OPERATION(org.omg.CORBA.BAD_OPERATION) NamePrincipal(org.wildfly.security.auth.principal.NamePrincipal) Principal(java.security.Principal)

Example 3 with OutputStream

use of org.omg.CORBA.portable.OutputStream in project ACS by ACS-Community.

the class CorbaNullFinderTest method testJacorbNullBehavior.

/**
	 * Tests jacorb's reaction to null data inside structs.
	 * If this test fails after a jacorb update, the logic of the Null Finder must be revisited.
	 */
public void testJacorbNullBehavior() throws Exception {
    // Below we'll need an ORB... 
    AcsLogger logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("testOrbLogger", false);
    AcsCorba acsCorba = new AcsCorba(logger);
    acsCorba.initCorbaForClient(false);
    // Jacorb uses ReplyOutputStream, but its base class ServiceContextTransportingOutputStream is easier to construct
    // and should be similar enough for this test.
    OutputStream out = new ServiceContextTransportingOutputStream(acsCorba.getORB());
    Struct2 myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    // the good data should marshal without exception
    Struct2Helper.write(out, myStruct2);
    // null string
    try {
        myStruct2.mystruct1.mystring = null;
        Struct2Helper.write(out, myStruct2);
        fail("null strings in structs should marshal with exception.");
    } catch (MARSHAL ex) {
        // expected
        assertEquals("org.omg.CORBA.MARSHAL: Cannot marshall null string.", ex.toString());
    }
    // null enum
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        myStruct2.mystruct1.myenum1 = null;
        Struct2Helper.write(out, myStruct2);
        fail("null strings in structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
    // null struct
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        myStruct2.mystruct1 = null;
        Struct2Helper.write(out, myStruct2);
        fail("null structs inside structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
    // top-level struct itself is null
    try {
        Struct2Helper.write(out, null);
        fail("top-level null structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... 
    }
    // null sequence of structs
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        myStruct2.seqOfStruct1 = null;
        Struct2Helper.write(out, myStruct2);
        fail("null sequence of structs inside structs should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
    // sequence with null struct
    myStruct2 = ComponentWithBadNullsImpl.createGoodStruct2();
    try {
        // with null inside
        myStruct2.seqOfStruct1 = new Struct1[1];
        Struct2Helper.write(out, myStruct2);
        fail("sequence of structs with nulls should marshal with NPE.");
    } catch (NullPointerException ex) {
    // expected... this is a really mean case, because we get NPE instead of MARSHAL. Maybe a jacorb bug?
    }
}
Also used : ServiceContextTransportingOutputStream(org.jacorb.orb.giop.ServiceContextTransportingOutputStream) ServiceContextTransportingOutputStream(org.jacorb.orb.giop.ServiceContextTransportingOutputStream) OutputStream(org.omg.CORBA.portable.OutputStream) Struct2(alma.jconttest.ComponentWithBadNullsPackage.Struct2) MARSHAL(org.omg.CORBA.MARSHAL) AcsLogger(alma.acs.logging.AcsLogger)

Aggregations

OutputStream (org.omg.CORBA.portable.OutputStream)3 BAD_OPERATION (org.omg.CORBA.BAD_OPERATION)2 AcsLogger (alma.acs.logging.AcsLogger)1 Struct2 (alma.jconttest.ComponentWithBadNullsPackage.Struct2)1 InetAddress (java.net.InetAddress)1 Principal (java.security.Principal)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 MBeanException (javax.management.MBeanException)1 ServiceContextTransportingOutputStream (org.jacorb.orb.giop.ServiceContextTransportingOutputStream)1 NamespaceContextSelector (org.jboss.as.naming.context.NamespaceContextSelector)1 HandleImplIIOP (org.jboss.ejb.iiop.HandleImplIIOP)1 InterceptorContext (org.jboss.invocation.InterceptorContext)1 SecurityContext (org.jboss.security.SecurityContext)1 MARSHAL (org.omg.CORBA.MARSHAL)1 SystemException (org.omg.CORBA.SystemException)1 InputStream (org.omg.CORBA.portable.InputStream)1