/**
   * Overrides writeObject in Serializable.
   *
   * @param out the {@code OutputStream} where the objects will be written.
   * @throws IOException if an error occurs while writing the objects to the stream.
   */
  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    /*
     * For serialization, object references are transformed into strings
     */
    for (Name key : this.contexts.keySet()) {
      org.omg.CORBA.Object o = (org.omg.CORBA.Object) this.contexts.remove(key);
      this.contexts.put(key, orb.object_to_string(o));
    }

    for (Name key : this.names.keySet()) {
      org.omg.CORBA.Object o = (org.omg.CORBA.Object) this.names.remove(key);
      this.names.put(key, orb.object_to_string(o));
    }

    out.defaultWriteObject();
  }
Example #2
0
  public KerberosServer(String[] args) {
    try {
      // initialize the ORB and POA.
      orb = ORB.init(args, null);
      POA rootPOA = (POA) orb.resolve_initial_references("RootPOA");
      org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[3];
      policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
      policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
      Any sasAny = orb.create_any();
      SASPolicyValuesHelper.insert(
          sasAny,
          new SASPolicyValues(EstablishTrustInClient.value, EstablishTrustInClient.value, true));
      policies[2] = orb.create_policy(SAS_POLICY_TYPE.value, sasAny);
      POA securePOA = rootPOA.create_POA("SecurePOA", rootPOA.the_POAManager(), policies);
      rootPOA.the_POAManager().activate();

      // create object and write out IOR
      securePOA.activate_object_with_id("SecureObject".getBytes(), this);
      org.omg.CORBA.Object demo = securePOA.servant_to_reference(this);
      PrintWriter pw = new PrintWriter(new FileWriter(args[0]));
      pw.println(orb.object_to_string(demo));
      pw.flush();
      pw.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  protected void startService() throws Exception {
    Context ctx;
    ORB orb;
    POA rootPOA;

    try {
      ctx = new InitialContext();
    } catch (NamingException e) {
      throw new RuntimeException("Cannot get intial JNDI context: " + e);
    }
    try {
      orb = (ORB) ctx.lookup("java:/" + CorbaORBService.ORB_NAME);
    } catch (NamingException e) {
      throw new RuntimeException("Cannot lookup java:/" + CorbaORBService.ORB_NAME + ": " + e);
    }
    try {
      rootPOA = (POA) ctx.lookup("java:/" + CorbaORBService.POA_NAME);
    } catch (NamingException e) {
      throw new RuntimeException("Cannot lookup java:/" + CorbaORBService.POA_NAME + ": " + e);
    }

    // Create the naming server POA as a child of the root POA
    Policy[] policies = new Policy[2];
    policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
    policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
    namingPOA = rootPOA.create_POA("Naming", null, policies);
    namingPOA.the_POAManager().activate();

    // initialize the static naming service variables.
    JBossNamingContextImpl.init(orb, rootPOA);

    // create and initialize the root context instance according to the configuration.
    JBossNamingContextImpl ns = new JBossNamingContextImpl();
    Configuration configuration = ((org.jacorb.orb.ORB) orb).getConfiguration();
    boolean doPurge = configuration.getAttribute("jacorb.naming.purge", "off").equals("on");
    boolean noPing = configuration.getAttribute("jacorb.naming.noping", "off").equals("on");
    ns.init(namingPOA, doPurge, noPing);

    // create and activate the root context.
    byte[] rootContextId = "root".getBytes();
    namingPOA.activate_object_with_id(rootContextId, ns);
    namingService =
        NamingContextExtHelper.narrow(
            namingPOA.create_reference_with_id(
                rootContextId, "IDL:omg.org/CosNaming/NamingContextExt:1.0"));

    // bind the root context to JNDI.
    bind(NAMING_NAME, "org.omg.CosNaming.NamingContextExt");
    getLog().info("CORBA Naming Started");
    getLog().debug("Naming: [" + orb.object_to_string(namingService) + "]");
  }
Example #4
0
  private ORB getOrbForServer(int port)
      throws InvalidName, AdapterInactive, WrongPolicy, ServantNotActive, IOException {

    System.setProperty("org.omg.CORBA.ORBInitialPort", String.valueOf(port));

    final ORB orb = ORB.init(new String[0], null);

    System.clearProperty("org.omg.CORBA.ORBInitialPort");

    POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
    rootPOA.the_POAManager().activate();

    org.omg.CORBA.Object objref = rootPOA.servant_to_reference(new LibraryImpl(rootPOA));
    iorString = orb.object_to_string(objref);

    return orb;
  }
Example #5
0
 private boolean handleIsIdentical(final org.omg.CORBA.Object val) throws RemoteException {
   // TODO: is this correct?
   return orb.object_to_string(_this_object()).equals(orb.object_to_string(val));
 }
Example #6
0
  /**
   * 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) {

    if (logger.isTraceEnabled()) {
      logger.trace("EJBObject invocation: " + opName);
    }

    SkeletonStrategy op = methodInvokerMap.get(opName);
    if (op == null) {
      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);
      SecurityContext sc = null;
      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 {
          Transaction tx = null;
          if (inboundTxCurrent != null) tx = inboundTxCurrent.getCurrentTransaction();
          if (tx != null) {
            transactionManager.resume(tx);
          }
          try {
            SimplePrincipal principal = null;
            Object credential = null;

            if (sasCurrent != null) {
              final byte[] incomingName = sasCurrent.get_incoming_principal_name();

              if (incomingName != null && incomingName.length > 0) {
                // we have an identity token, which is a trust based mechanism
                if (incomingName.length > 0) {
                  String name = new String(incomingName, StandardCharsets.UTF_8);
                  int domainIndex = name.indexOf('@');
                  if (domainIndex > 0) name = name.substring(0, domainIndex);
                  principal = new SimplePrincipal(name);
                  // we don't have any real way to establish trust here
                  // we just use the SASCurrent as a credential, and a custom login
                  // module can make a decision for us.
                  credential = sasCurrent;
                }
              } else {
                // the client has just sent a username and password
                final byte[] username = sasCurrent.get_incoming_username();
                final byte[] incomingPassword = sasCurrent.get_incoming_password();
                if (username.length > 0) {
                  String name = new String(username, StandardCharsets.UTF_8);
                  int domainIndex = name.indexOf('@');
                  if (domainIndex > 0) {
                    name = name.substring(0, domainIndex);
                  }
                  principal = new SimplePrincipal(name);
                  credential = new String(incomingPassword, StandardCharsets.UTF_8).toCharArray();
                }
              }

              if (securityDomain != null) {
                sc = SecurityContextFactory.createSecurityContext(securityDomain);
                sc.getUtil().createSubjectInfo(principal, credential, null);
              }
            }
            final Object[] params = op.readParams((org.omg.CORBA_2_3.portable.InputStream) in);

            if (!home && opName.equals("isIdentical") && params.length == 1) {
              // handle isIdentical specially
              Object val = params[0];
              if (val instanceof org.omg.CORBA.Object) {
                retVal = handleIsIdentical((org.omg.CORBA.Object) val);
              } else {
                retVal = false;
              }
            } else {

              if (sc != null) {
                setSecurityContextOnAssociation(sc);
              }
              try {
                final InterceptorContext interceptorContext = new InterceptorContext();

                if (sc != null) {
                  interceptorContext.putPrivateData(SecurityContext.class, sc);
                }
                prepareInterceptorContext(op, params, interceptorContext);
                retVal = componentView.invoke(interceptorContext);
              } finally {
                if (sc != null) {
                  clearSecurityContextOnAssociation();
                }
              }
            }
          } finally {
            if (tx != null) {
              if (transactionManager.getStatus() != Status.STATUS_NO_TRANSACTION) {
                transactionManager.suspend();
              }
            }
          }
        }
        out = (org.omg.CORBA_2_3.portable.OutputStream) handler.createReply();
        if (op.isNonVoid()) {
          op.writeRetval(out, retVal);
        }
      } catch (Exception e) {
        if (logger.isTraceEnabled()) {
          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);
    }
  }