コード例 #1
0
ファイル: EJBComponent.java プロジェクト: ringerc/jboss-as
 public Object lookup(String name) throws IllegalArgumentException {
   if (name == null) {
     throw MESSAGES.jndiNameCannotBeNull();
   }
   final NamespaceContextSelector namespaceContextSelector =
       NamespaceContextSelector.getCurrentSelector();
   if (namespaceContextSelector == null) {
     throw MESSAGES.noNamespaceContextSelectorAvailable(name);
   }
   Context jndiContext = null;
   String namespaceStrippedJndiName = name;
   // get the appropriate JNDI context and strip the lookup jndi name of the component namespace
   // prefix
   if (name.startsWith("java:app/")) {
     jndiContext = namespaceContextSelector.getContext("app");
     namespaceStrippedJndiName = name.substring("java:app/".length());
   } else if (name.startsWith("java:module/")) {
     jndiContext = namespaceContextSelector.getContext("module");
     namespaceStrippedJndiName = name.substring("java:module/".length());
   } else if (name.startsWith("java:comp/")) {
     jndiContext = namespaceContextSelector.getContext("comp");
     namespaceStrippedJndiName = name.substring("java:comp/".length());
   } else if (!name.startsWith(
       "java:")) { // if it *doesn't* start with java: prefix, then default it to java:comp
     jndiContext = namespaceContextSelector.getContext("comp");
     // no need to strip the name since it doesn't start with java: prefix.
     // Also prefix the "env/" to the jndi name, since a lookup without a java: namespace prefix is
     // effectively
     // a lookup under java:comp/env/<jndi-name>
     namespaceStrippedJndiName = "env/" + name;
   } else if (name.startsWith("java:global/")) {
     // Do *not* strip the jndi name of the prefix because java:global is a global context and
     // doesn't specifically
     // belong to the component's ENC, and hence *isn't* a component ENC relative name and has to
     // be looked up
     // with the absolute name (including the java:global prefix)
     try {
       jndiContext = new InitialContext();
     } catch (NamingException ne) {
       throw MESSAGES.failToLookupJNDI(name, ne);
     }
   } else {
     throw MESSAGES.failToLookupJNDINameSpace(name);
   }
   ROOT_LOGGER.debug(
       "Looking up " + namespaceStrippedJndiName + " in jndi context: " + jndiContext);
   try {
     return jndiContext.lookup(namespaceStrippedJndiName);
   } catch (NamingException ne) {
     throw MESSAGES.failToLookupStrippedJNDI(namespaceContextSelector, jndiContext, ne);
   }
 }
コード例 #2
0
  protected void performRuntime(
      OperationContext context,
      ModelNode operation,
      ModelNode model,
      ServiceVerificationHandler verificationHandler,
      List<ServiceController<?>> newControllers) {

    log.info("Activating Naming Subsystem");

    NamingContext.initializeNamingManager();

    final ServiceBasedNamingStore namingStore =
        new ServiceBasedNamingStore(
            context.getServiceRegistry(false), ContextNames.JAVA_CONTEXT_SERVICE_NAME);

    // Create the Naming Service
    final ServiceTarget target = context.getServiceTarget();
    newControllers.add(
        target
            .addService(NamingService.SERVICE_NAME, new NamingService(namingStore))
            .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME)
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .addListener(verificationHandler)
            .install());

    // Create the java:global namespace
    final ServiceBasedNamingStore globalNamingStore =
        new ServiceBasedNamingStore(
            context.getServiceRegistry(false), ContextNames.GLOBAL_CONTEXT_SERVICE_NAME);
    newControllers.add(
        target
            .addService(
                ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, new NamingStoreService(globalNamingStore))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .addListener(verificationHandler)
            .install());

    // Create the java:jboss vendor namespace
    final ServiceBasedNamingStore jbossNamingStore =
        new ServiceBasedNamingStore(
            context.getServiceRegistry(false), ContextNames.JBOSS_CONTEXT_SERVICE_NAME);
    newControllers.add(
        target
            .addService(
                ContextNames.JBOSS_CONTEXT_SERVICE_NAME, new NamingStoreService(jbossNamingStore))
            .setInitialMode(ServiceController.Mode.ACTIVE)
            .addListener(verificationHandler)
            .install());

    NamespaceContextSelector.setDefault(
        new NamespaceContextSelector() {
          public Context getContext(String identifier) {
            final NamingStore namingStore;
            if (identifier.equals("global")) {
              namingStore = globalNamingStore;
            } else if (identifier.equals("jboss")) {
              namingStore = jbossNamingStore;
            } else {
              namingStore = null;
            }
            if (namingStore != null) {
              try {
                return (Context) namingStore.lookup(EMPTY_NAME);
              } catch (NamingException e) {
                throw new IllegalStateException(e);
              }
            } else {
              return null;
            }
          }
        });

    // Provide the {@link InitialContext} as OSGi service
    newControllers.add(InitialContextFactoryService.addService(target, verificationHandler));

    newControllers.add(
        target
            .addService(JndiViewExtensionRegistry.SERVICE_NAME, new JndiViewExtensionRegistry())
            .install());

    if (context.isBooting()) {
      context.addStep(
          new AbstractDeploymentChainStep() {
            protected void execute(DeploymentProcessorTarget processorTarget) {
              processorTarget.addDeploymentProcessor(
                  Phase.INSTALL,
                  Phase.INSTALL_JNDI_DEPENDENCY_SETUP,
                  new JndiNamingDependencySetupProcessor());
              processorTarget.addDeploymentProcessor(
                  Phase.INSTALL,
                  Phase.INSTALL_JNDI_DEPENDENCIES,
                  new JndiNamingDependencyProcessor());
            }
          },
          OperationContext.Stage.RUNTIME);
    }
  }
コード例 #3
0
ファイル: EjbCorbaServant.java プロジェクト: manovotn/wildfly
  /**
   * 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);
    }
  }