/** Publishes the endpoints declared to the provided WSEndpointDeploymentUnit */
 public List<Endpoint> publish(ServiceTarget target, WSEndpointDeploymentUnit unit)
     throws Exception {
   List<DeploymentAspect> aspects = DeploymentAspectsProvider.getSortedDeploymentAspects();
   ClassLoader origClassLoader = SecurityActions.getContextClassLoader();
   Deployment dep = null;
   try {
     SecurityActions.setContextClassLoader(
         ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
     WSDeploymentBuilder.getInstance().build(unit);
     dep = unit.getAttachment(WSAttachmentKeys.DEPLOYMENT_KEY);
     dep.addAttachment(ServiceTarget.class, target);
     DeploymentAspectManager dam = new DeploymentAspectManagerImpl();
     dam.setDeploymentAspects(aspects);
     dam.deploy(dep);
   } finally {
     if (dep != null) {
       dep.removeAttachment(ServiceTarget.class);
     }
     SecurityActions.setContextClassLoader(origClassLoader);
   }
   Deployment deployment = unit.getAttachment(WSAttachmentKeys.DEPLOYMENT_KEY);
   deployment.addAttachment(
       StandardContext.class,
       startWebApp(host, unit)); // TODO simplify and use findChild later in destroy()/stopWebApp()
   return deployment.getService().getEndpoints();
 }
Beispiel #2
0
  public synchronized void start(StartContext context) throws StartException {
    try {
      final JMSServerManager jmsServer =
          new JMSServerManagerImpl(
              hornetQServer.getValue(),
              new AS7BindingRegistry(context.getController().getServiceContainer()));

      try {
        // FIXME - we also need the TCCL here in case the JMSServerManager starts the HornetQServer
        final ClassLoader loader = getClass().getClassLoader();
        SecurityActions.setContextClassLoader(loader);
        jmsServer.start();

        // FIXME - this check is a work-around for AS7-3658
        if (!hornetQServer.getValue().getConfiguration().isBackup()) {
          hornetQServer
              .getValue()
              .getRemotingService()
              .allowInvmSecurityOverride(
                  new HornetQPrincipal(
                      HornetQDefaultCredentials.getUsername(),
                      HornetQDefaultCredentials.getPassword()));
        } else {
          hornetQServer
              .getValue()
              .registerActivateCallback(
                  new ActivateCallback() {
                    public void preActivate() {}

                    public void activated() {
                      hornetQServer
                          .getValue()
                          .getRemotingService()
                          .allowInvmSecurityOverride(
                              new HornetQPrincipal(
                                  HornetQDefaultCredentials.getUsername(),
                                  HornetQDefaultCredentials.getPassword()));
                    }

                    public void deActivate() {}
                  });
        }
      } finally {
        SecurityActions.setContextClassLoader(null);
      }
      this.jmsServer = jmsServer;
    } catch (Exception e) {
      throw new StartException(e);
    }
  }
 /**
  * Stops the container
  *
  * @throws IllegalStateException if the container is not running
  */
 public synchronized void stop() {
   if (!started) {
     throw WeldMessages.MESSAGES.notStarted("WeldContainer");
   }
   ClassLoader oldTccl = SecurityActions.getContextClassLoader();
   try {
     SecurityActions.setContextClassLoader(deployment.getModule().getClassLoader());
     bootstrap.shutdown();
   } finally {
     SecurityActions.setContextClassLoader(oldTccl);
     ModuleGroupSingletonProvider.removeClassLoader(deployment.getModule().getClassLoader());
   }
   started = false;
 }
Beispiel #4
0
 /**
  * Invokes this method with the provided arguments applying provided mapper
  *
  * @param args object
  * @param mapper if null no mappings are applied method will be invoked using args directly. in
  *     this case the keys of the map gotta be the parameters names as defined in wsdl/wsconsume
  *     generated classes
  * @return {@link InvocationResultImpl}
  * @throws WiseWebServiceException There are 4 known failure conditions - The wsdl (url) could not
  *     be found - The wsdl is password protected - The endpoint (url) could not be found - The
  *     endpoint is password protected
  * @throws InvocationException invocation issue
  * @throws IllegalArgumentException illegal argument
  * @throws MappingException mapping issue
  */
 @SuppressWarnings("unchecked")
 public InvocationResultImpl invoke(Object args, WiseMapper mapper)
     throws WiseWebServiceException, InvocationException, IllegalArgumentException,
         MappingException {
   if (mapper == null) {
     return this.invoke((Map<String, Object>) args);
   }
   ClassLoader oldLoader = SecurityActions.getContextClassLoader();
   Map<String, Object> mappingResults;
   try {
     SecurityActions.setContextClassLoader(this.getEndpoint().getClassLoader());
     mappingResults = mapper.applyMapping(args);
   } finally {
     SecurityActions.setContextClassLoader(oldLoader);
   }
   return this.invoke(mappingResults);
 }
    public void afterCompletion(int status) {
      boolean trace = log.isTraceEnabled();

      // This is an independent point of entry. We need to make sure the
      // thread is associated with the right context class loader
      ClassLoader oldCl = SecurityActions.getContextClassLoader();
      SecurityActions.setContextClassLoader(container.getClassLoader());
      container.pushENC();
      ctx.hasTxSynchronization(false);
      ctx.setTransaction(null);
      try {
        try {
          // If rolled back -> invalidate instance
          if (status != Status.STATUS_ROLLEDBACK) {
            switch (commitOption) {
                // Keep instance cached after tx commit
              case ConfigurationMetaData.A_COMMIT_OPTION:
                throw new IllegalStateException(
                    "Commit option A not allowed with this Interceptor");
                // Keep instance active, but invalidate state
              case ConfigurationMetaData.B_COMMIT_OPTION:
                break;
                // Invalidate everything AND Passivate instance
              case ConfigurationMetaData.C_COMMIT_OPTION:
                break;
              case ConfigurationMetaData.D_COMMIT_OPTION:
                throw new IllegalStateException(
                    "Commit option D not allowed with this Interceptor");
            }
          }
          try {
            if (ctx.getId() != null) container.getPersistenceManager().passivateEntity(ctx);
          } catch (Exception ignored) {
          }
          container.getInstancePool().free(ctx);
        } finally {
          if (trace) log.trace("afterCompletion, clear tx for ctx=" + ctx + ", tx=" + tx);
        }
      } // synchronized(lock)
      finally {
        container.popENC();
        SecurityActions.setContextClassLoader(oldCl);
      }
    }
 /**
  * Starts the weld container
  *
  * @throws IllegalStateException if the container is already running
  */
 public synchronized void start() {
   if (started) {
     throw WeldMessages.MESSAGES.alreadyRunning("WeldContainer");
   }
   ModuleGroupSingletonProvider.addClassLoaders(
       deployment.getModule().getClassLoader(), deployment.getSubDeploymentClassLoaders());
   started = true;
   ClassLoader oldTccl = SecurityActions.getContextClassLoader();
   try {
     SecurityActions.setContextClassLoader(deployment.getModule().getClassLoader());
     bootstrap.startContainer(environment, deployment);
     bootstrap.startInitialization();
     bootstrap.deployBeans();
     bootstrap.validateBeans();
     bootstrap.endInitialization();
   } finally {
     SecurityActions.setContextClassLoader(oldTccl);
   }
 }
  @Override
  public void start(final StartContext context) throws StartException {
    final ClassLoader cl = SecurityActions.getContextClassLoader();
    try {
      SecurityActions.setContextClassLoader(classLoader);
      final BeanManagerImpl beanManager = this.beanManager.getValue();
      for (final Class<?> interceptor : interceptorClasses) {
        interceptorInjections.put(
            interceptor, WeldEEInjection.createWeldEEInjection(interceptor, null, beanManager));
      }

      if (ejbName != null) {
        EjbDescriptor<Object> descriptor = beanManager.getEjbDescriptor(ejbName);
        bean = beanManager.getBean(descriptor);
      }
      injectionTarget = WeldEEInjection.createWeldEEInjection(componentClass, bean, beanManager);
    } finally {
      SecurityActions.setContextClassLoader(cl);
    }
  }
  protected void verifyPassword(VerifyPasswordCallback vpc) throws NamingException {
    String credential = vpc.getValue();

    ClassLoader currentTCCL = SecurityActions.getContextClassLoader();
    if (currentTCCL != null) SecurityActions.setContextClassLoader(null);

    String baseDN = options.get(BASE_CTX_DN);
    String baseFilter = options.get(BASE_FILTER_OPT);

    InitialLdapContext ctx = this.constructInitialLdapContext(bindDN, bindCredential);
    bindDNAuthentication(ctx, userName, credential, baseDN, baseFilter);
    vpc.setVerified(true);
  }
 @Override
 public void destroy(Context context) throws Exception {
   List<Endpoint> eps = context.getEndpoints();
   if (eps == null || eps.isEmpty()) {
     return;
   }
   Deployment deployment = eps.get(0).getService().getDeployment();
   List<DeploymentAspect> aspects = DeploymentAspectsProvider.getSortedDeploymentAspects();
   try {
     stopWebApp(deployment.getAttachment(StandardContext.class));
   } finally {
     ClassLoader origClassLoader = SecurityActions.getContextClassLoader();
     try {
       SecurityActions.setContextClassLoader(
           ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
       DeploymentAspectManager dam = new DeploymentAspectManagerImpl();
       dam.setDeploymentAspects(aspects);
       dam.undeploy(deployment);
     } finally {
       SecurityActions.setContextClassLoader(origClassLoader);
     }
   }
 }
    public void afterCompletion(int status) {
      boolean trace = log.isTraceEnabled();

      // This is an independent point of entry. We need to make sure the
      // thread is associated with the right context class loader
      ClassLoader oldCl = SecurityActions.getContextClassLoader();
      boolean setCl = !oldCl.equals(container.getClassLoader());
      if (setCl) {
        SecurityActions.setContextClassLoader(container.getClassLoader());
      }
      container.pushENC();

      int commitOption =
          ctx.isPassivateAfterCommit()
              ? ConfigurationMetaData.C_COMMIT_OPTION
              : EntitySynchronizationInterceptor.this.commitOption;

      lock.sync();
      // The context is no longer synchronized on the TX
      ctx.hasTxSynchronization(false);
      ctx.setTxAssociation(GlobalTxEntityMap.NONE);
      ctx.setTransaction(null);
      try {
        try {
          // If rolled back -> invalidate instance
          if (status == Status.STATUS_ROLLEDBACK) {
            // remove from the cache
            container.getInstanceCache().remove(ctx.getCacheKey());
          } else {
            switch (commitOption) {
                // Keep instance cached after tx commit
              case ConfigurationMetaData.A_COMMIT_OPTION:
              case ConfigurationMetaData.D_COMMIT_OPTION:
                // The state is still valid (only point of access is us)
                ctx.setValid(true);
                break;

                // Keep instance active, but invalidate state
              case ConfigurationMetaData.B_COMMIT_OPTION:
                // Invalidate state (there might be other points of entry)
                ctx.setValid(false);
                break;
                // Invalidate everything AND Passivate instance
              case ConfigurationMetaData.C_COMMIT_OPTION:
                try {
                  // We weren't removed, passivate
                  // Here we own the lock, so we don't try to passivate
                  // we just passivate
                  if (ctx.getId() != null) {
                    container.getInstanceCache().remove(ctx.getId());
                    container.getPersistenceManager().passivateEntity(ctx);
                  }
                  // If we get this far, we return to the pool
                  container.getInstancePool().free(ctx);
                } catch (Exception e) {
                  log.debug("Exception releasing context", e);
                }
                break;
            }
          }
        } finally {
          if (trace) log.trace("afterCompletion, clear tx for ctx=" + ctx + ", tx=" + tx);
          lock.endTransaction(tx);

          if (trace) log.trace("afterCompletion, sent notify on TxLock for ctx=" + ctx);
        }
      } // synchronized(lock)
      finally {
        lock.releaseSync();
        container.getLockManager().removeLockRef(lock.getId());
        container.popENC();
        if (setCl) {
          SecurityActions.setContextClassLoader(oldCl);
        }
      }
    }
  /**
   * Handle a {@code Callback}
   *
   * @param c callback
   * @throws UnsupportedCallbackException If the callback is not supported by this handler
   * @throws NamingException
   */
  protected void handleCallBack(Callback c) throws UnsupportedCallbackException, NamingException {
    if (c instanceof VerifyPasswordCallback) {
      verifyPassword((VerifyPasswordCallback) c);
      return;
    }

    if (c instanceof PasswordCallback == false) return;

    PasswordCallback passwdCallback = (PasswordCallback) c;

    String bindDN = getBindDN();

    String bindCredential = getBindCredential();

    String tmp = options.get(PASSWORD_ATTRIBUTE_ID);
    if (tmp != null && tmp.length() > 0) {
      passwordAttributeID = tmp;
    }

    InitialLdapContext ctx;
    ClassLoader currentTCCL = SecurityActions.getContextClassLoader();
    try {
      if (currentTCCL != null) SecurityActions.setContextClassLoader(null);
      ctx = this.constructInitialLdapContext(bindDN, bindCredential);
    } catch (NamingException e) {
      throw new RuntimeException(e);
    }

    String timeLimit = (String) options.get(SEARCH_TIME_LIMIT_OPT);
    if (timeLimit != null) {
      try {
        searchTimeLimit = Integer.parseInt(timeLimit);
      } catch (NumberFormatException e) {
      }
    }
    if (searchTimeLimit == 0) searchTimeLimit = 10000;

    String baseDN = options.get(BASE_CTX_DN);
    String baseFilter = options.get(BASE_FILTER_OPT);

    SearchControls constraints = new SearchControls();
    constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);

    constraints.setTimeLimit(searchTimeLimit);

    NamingEnumeration<SearchResult> results = null;

    Object[] filterArgs = {userName};
    try {
      if (baseDN == null) throw PicketBoxMessages.MESSAGES.invalidNullBaseContextDN();
      results = ctx.search(baseDN, baseFilter, filterArgs, constraints);
      if (results.hasMore() == false) {
        safeClose(results);
        throw PicketBoxMessages.MESSAGES.failedToFindBaseContextDN(baseDN);
      }
      SearchResult sr = results.next();
      String name = sr.getName();
      String userDN = null;
      if (sr.isRelative() == true) userDN = name + "," + baseDN;
      else throw PicketBoxMessages.MESSAGES.unableToFollowReferralForAuth(name);
      ;

      safeClose(results);

      // Finished Authentication.  Lets look for the attributes
      filterArgs = new Object[] {userName, userDN};
      results = ctx.search(userDN, baseFilter, filterArgs, constraints);
      try {
        while (results.hasMore()) {
          sr = results.next();
          Attributes attributes = sr.getAttributes();
          NamingEnumeration<? extends javax.naming.directory.Attribute> ne = attributes.getAll();

          while (ne != null && ne.hasMoreElements()) {
            javax.naming.directory.Attribute ldapAtt = ne.next();
            if (passwordAttributeID.equalsIgnoreCase(ldapAtt.getID())) {
              Object thePass = ldapAtt.get();
              setPasswordCallbackValue(thePass, passwdCallback);
            }
          }
        }
      } finally {
        safeClose(results);
        safeClose(ctx);
        if (currentTCCL != null) SecurityActions.setContextClassLoader(currentTCCL);
      }
    } catch (NamingException ne) {
      PicketBoxLogger.LOGGER.error(ne);
    }
  }