private InjectionAwareInstanceProvider(
     final InstanceProvider delegate, final Endpoint endpoint, final DeploymentUnit unit) {
   this.delegate = delegate;
   endpointName = endpoint.getShortName();
   endpointClass = endpoint.getTargetBeanName();
   componentPrefix = unit.getServiceName().append("component");
 }
  @Override
  public void handleMessage(SoapMessage msg) throws Fault {
    Endpoint ep = msg.getExchange().get(Endpoint.class);
    sdc.set(ep.getSecurityDomainContext());
    try {
      SecurityToken token = msg.get(SecurityToken.class);
      SecurityContext context = msg.get(SecurityContext.class);
      if (token == null || context == null || context.getUserPrincipal() == null) {
        super.handleMessage(msg);
        return;
      }
      UsernameToken ut = (UsernameToken) token;

      Subject subject =
          createSubject(
              ut.getName(), ut.getPassword(), ut.isHashed(), ut.getNonce(), ut.getCreatedTime());

      SecurityContext sc = doCreateSecurityContext(context.getUserPrincipal(), subject);
      msg.put(SecurityContext.class, sc);
    } finally {
      if (sdc != null) {
        sdc.remove();
      }
    }
  }
 private void setInjectionAwareInstanceProvider(final Endpoint ep) {
   final InstanceProvider stackInstanceProvider = ep.getInstanceProvider();
   final DeploymentUnit unit = ep.getService().getDeployment().getAttachment(DeploymentUnit.class);
   final InstanceProvider injectionAwareInstanceProvider =
       new InjectionAwareInstanceProvider(stackInstanceProvider, ep, unit);
   ep.setInstanceProvider(injectionAwareInstanceProvider);
 }
  /**
   * Creates new Http Web Service endpoint.
   *
   * @param endpointClass endpoint class name
   * @param endpointName endpoint name
   * @param dep deployment
   * @return WS endpoint
   */
  protected final Endpoint newHttpEndpoint(
      final String endpointClass, final String endpointName, final Deployment dep) {
    if (endpointName == null) throw MESSAGES.nullEndpointName();
    if (endpointClass == null) throw MESSAGES.nullEndpointClass();

    final Endpoint endpoint = this.deploymentModelFactory.newHttpEndpoint(endpointClass);
    endpoint.setShortName(endpointName);
    endpoint.setType(endpointType);
    dep.getService().addEndpoint(endpoint);

    return endpoint;
  }
 @Override
 public void stop(final StopContext context) {
   ROOT_LOGGER.stopping(name);
   endpoint.setSecurityDomainContext(null);
   if (hasWebservicesMD(endpoint)) {
     pclWebAppControllerValue.getValue().decrementUsers();
   }
   endpointRegistryValue.getValue().unregister(endpoint);
   final List<RecordProcessor> processors = endpoint.getRecordProcessors();
   for (final RecordProcessor processor : processors) {
     unregisterRecordProcessor(processor, endpoint);
   }
 }
 @Override
 public void start(final StartContext context) throws StartException {
   ROOT_LOGGER.starting(name);
   endpoint.setSecurityDomainContext(
       new SecurityDomainContextAdaptor(securityDomainContextValue.getValue()));
   if (hasWebservicesMD(
       endpoint)) { // basically JAX-RPC deployments require the PortComponentLinkServlet to be
                    // available
     pclWebAppControllerValue.getValue().incrementUsers();
   }
   final List<RecordProcessor> processors = endpoint.getRecordProcessors();
   for (final RecordProcessor processor : processors) {
     registerRecordProcessor(processor, endpoint);
   }
   endpointRegistryValue.getValue().register(endpoint);
 }
 public static void install(
     final ServiceTarget serviceTarget, final Endpoint endpoint, final DeploymentUnit unit) {
   final ServiceName serviceName = getServiceName(unit, endpoint.getShortName());
   final EndpointService service = new EndpointService(endpoint, serviceName);
   final ServiceBuilder<Endpoint> builder = serviceTarget.addService(serviceName, service);
   builder.addDependency(
       DependencyType.REQUIRED,
       SecurityDomainService.SERVICE_NAME.append(getDeploymentSecurityDomainName(endpoint)),
       SecurityDomainContext.class,
       service.getSecurityDomainContextInjector());
   builder.addDependency(
       DependencyType.REQUIRED,
       WSServices.REGISTRY_SERVICE,
       EndpointRegistry.class,
       service.getEndpointRegistryInjector());
   builder.addDependency(
       DependencyType.REQUIRED,
       WSServices.PORT_COMPONENT_LINK_SERVICE,
       WebAppController.class,
       service.getPclWebAppControllerInjector());
   builder.addDependency(
       DependencyType.OPTIONAL,
       MBEAN_SERVER_NAME,
       MBeanServer.class,
       service.getMBeanServerInjector());
   builder.setInitialMode(Mode.ACTIVE);
   builder.install();
 }
 private static String getDeploymentSecurityDomainName(final Endpoint ep) {
   JBossWebMetaData metadata =
       ep.getService().getDeployment().getAttachment(JBossWebMetaData.class);
   String metaDataSecurityDomain = metadata != null ? metadata.getSecurityDomain() : null;
   return metaDataSecurityDomain == null
       ? SecurityConstants.DEFAULT_APPLICATION_POLICY
       : SecurityUtil.unprefixSecurityDomain(metaDataSecurityDomain.trim());
 }
 private void unregisterRecordProcessor(final RecordProcessor processor, final Endpoint ep) {
   MBeanServer mbeanServer = mBeanServerValue.getValue();
   if (mbeanServer != null) {
     try {
       mbeanServer.unregisterMBean(
           ObjectNameFactory.create(ep.getName() + ",recordProcessor=" + processor.getName()));
     } catch (final JMException e) {
       ROOT_LOGGER.cannotUnregisterRecordProcessor();
     }
   } else {
     ROOT_LOGGER.mBeanServerNotAvailable(processor);
   }
 }
 private void registerRecordProcessor(final RecordProcessor processor, final Endpoint ep) {
   MBeanServer mbeanServer = mBeanServerValue.getValue();
   if (mbeanServer != null) {
     try {
       mbeanServer.registerMBean(
           processor,
           ObjectNameFactory.create(ep.getName() + ",recordProcessor=" + processor.getName()));
     } catch (final JMException ex) {
       ROOT_LOGGER.trace(
           "Cannot register endpoint with JMX server, trying with the default ManagedRecordProcessor: "
               + ex.getMessage());
       try {
         mbeanServer.registerMBean(
             new ManagedRecordProcessor(processor),
             ObjectNameFactory.create(ep.getName() + ",recordProcessor=" + processor.getName()));
       } catch (final JMException e) {
         ROOT_LOGGER.cannotRegisterRecordProcessor();
       }
     }
   } else {
     ROOT_LOGGER.mBeanServerNotAvailable(processor);
   }
 }
  /**
   * Invokes WS endpoint.
   *
   * @param endpoint WS endpoint
   * @param wsInvocation web service invocation
   * @throws Exception if any error occurs
   */
  public void invoke(final Endpoint endpoint, final Invocation wsInvocation) throws Exception {
    try {
      // prepare for invocation
      onBeforeInvocation(wsInvocation);
      // prepare invocation data
      final ComponentView componentView = getComponentView();
      Component component = componentView.getComponent();
      // for spring integration and @FactoryType is annotated we don't need to go into ee's
      // interceptors
      if (wsInvocation.getInvocationContext().getTargetBean() != null
              && (endpoint.getProperty("SpringBus") != null)
          || wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null) {
        this.reference =
            new ManagedReference() {
              public void release() {}

              public Object getInstance() {
                return wsInvocation.getInvocationContext().getTargetBean();
              }
            };
        if (component instanceof WSComponent) {
          ((WSComponent) component).setReference(reference);
        }
      }
      final Method method =
          getComponentViewMethod(wsInvocation.getJavaMethod(), componentView.getViewMethods());
      final InterceptorContext context = new InterceptorContext();
      prepareForInvocation(context, wsInvocation);
      context.setMethod(method);
      context.setParameters(wsInvocation.getArgs());
      context.putPrivateData(Component.class, component);
      context.putPrivateData(ComponentView.class, componentView);
      if (wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null) {
        context.putPrivateData(ManagedReference.class, reference);
      }
      // invoke method
      final Object retObj = componentView.invoke(context);
      // set return value
      wsInvocation.setReturnValue(retObj);
    } catch (Throwable t) {
      handleInvocationException(t);
    } finally {
      onAfterInvocation(wsInvocation);
    }
  }
  @Override
  public void customize(Object beanInstance) {
    if (beanInstance instanceof EndpointImpl) {
      configureEndpoint((EndpointImpl) beanInstance);
    }
    if (beanInstance instanceof ServerFactoryBean) {
      ServerFactoryBean factory = (ServerFactoryBean) beanInstance;

      if (factory.getInvoker() instanceof JBossWSInvoker) {
        ((JBossWSInvoker) factory.getInvoker()).setTargetBean(factory.getServiceBean());
      }
      List<Endpoint> depEndpoints = dep.getService().getEndpoints();
      if (depEndpoints != null) {
        final String targetBeanName = factory.getServiceBean().getClass().getName();
        for (Endpoint depEndpoint : depEndpoints) {
          if (depEndpoint.getTargetBeanClass().getName().equals(targetBeanName)) {
            depEndpoint.addAttachment(Object.class, factory.getServiceBean());
          }
        }
      }
    }
    if (beanInstance instanceof ServiceImpl) {
      ServiceImpl service = (ServiceImpl) beanInstance;
      List<Endpoint> depEndpoints = dep.getService().getEndpoints();
      if (depEndpoints != null) {
        final Collection<org.apache.cxf.endpoint.Endpoint> eps = service.getEndpoints().values();
        for (Endpoint depEp : depEndpoints) {
          for (org.apache.cxf.endpoint.Endpoint ep : eps) {
            if (ep.getService().getName().equals(depEp.getProperty(Message.WSDL_SERVICE))
                && ep.getEndpointInfo().getName().equals(depEp.getProperty(Message.WSDL_PORT))) {
              depEp.addAttachment(org.apache.cxf.endpoint.Endpoint.class, ep);
            }
          }
        }
      }
    }
    if (beanInstance instanceof HTTPTransportFactory) {
      HTTPTransportFactory factory = (HTTPTransportFactory) beanInstance;
      DestinationRegistry oldRegistry = factory.getRegistry();
      if (!(oldRegistry instanceof JBossWSDestinationRegistryImpl)) {
        factory.setRegistry(new JBossWSDestinationRegistryImpl());
      }
    }
    super.customize(beanInstance);
  }
 /**
  * Initializes component view name.
  *
  * @param endpoint web service endpoint
  */
 public void init(final Endpoint endpoint) {
   componentViewName = (ServiceName) endpoint.getProperty(COMPONENT_VIEW_NAME);
 }
 public static void uninstall(final Endpoint endpoint, final DeploymentUnit unit) {
   final ServiceName serviceName = getServiceName(unit, endpoint.getShortName());
   WSServices.getContainerRegistry().getRequiredService(serviceName).setMode(Mode.REMOVE);
 }
 private boolean hasWebservicesMD(final Endpoint endpoint) {
   final Deployment dep = endpoint.getService().getDeployment();
   return dep.getAttachment(WebservicesMetaData.class) != null;
 }
  protected void configureEndpoint(EndpointImpl endpoint) {
    // Configure wsdl file publisher
    if (wsdlPublisher != null) {
      endpoint.setWsdlPublisher(wsdlPublisher);
    }
    // Configure according to the specified jaxws endpoint configuration
    if (!endpoint.isPublished()) // before publishing, we set the jaxws conf
    {
      final Object implementor = endpoint.getImplementor();

      // setup our invoker for http endpoints if invoker is not configured in jbossws-cxf.xml DD
      boolean isHttpEndpoint =
          endpoint.getAddress() != null
              && endpoint
                  .getAddress()
                  .substring(0, 5)
                  .toLowerCase(Locale.ENGLISH)
                  .startsWith("http");
      if ((endpoint.getInvoker() == null) && isHttpEndpoint) {
        final AnnotationsInfo ai = dep.getAttachment(AnnotationsInfo.class);
        endpoint.setInvoker(
            new JBossWSInvoker(ai.hasAnnotatedClasses(UseAsyncMethod.class.getName())));
      }

      // ** Endpoint configuration setup **
      final String endpointClassName = implementor.getClass().getName();
      final List<Endpoint> depEndpoints = dep.getService().getEndpoints();
      for (Endpoint depEndpoint : depEndpoints) {
        if (endpointClassName.equals(depEndpoint.getTargetBeanName())) {
          org.jboss.wsf.spi.metadata.config.EndpointConfig config = depEndpoint.getEndpointConfig();
          if (config == null) {
            // the ASIL did not set the endpoint configuration, perhaps because we're processing an
            // Endpoint.publish() API started endpoint or because we're on WildFly 8.0.0.Final or
            // previous version. We compute the config here then (clearly no container injection
            // will be performed on optional handlers attached to the config)
            BasicConfigResolver bcr = new BasicConfigResolver(dep, implementor.getClass());
            config = bcr.resolveEndpointConfig();
            depEndpoint.setEndpointConfig(config);
          }
          if (config != null) {
            endpoint.setEndpointConfig(config);
          }

          // also save Service QName and Port QName in the endpoint for later matches
          depEndpoint.setProperty(Message.WSDL_PORT, endpoint.getEndpointName());
          depEndpoint.setProperty(Message.WSDL_SERVICE, endpoint.getServiceName());
        }
      }

      // JASPI
      final JASPIAuthenticationProvider jaspiProvider =
          (JASPIAuthenticationProvider)
              ServiceLoader.loadService(
                  JASPIAuthenticationProvider.class.getName(),
                  null,
                  ClassLoaderProvider.getDefaultProvider().getServerIntegrationClassLoader());
      if (jaspiProvider == null) {
        Loggers.DEPLOYMENT_LOGGER.cannotFindJaspiClasses();
      } else {
        if (jaspiProvider.enableServerAuthentication(endpoint, depEndpoints.get(0))) {
          endpoint.getInInterceptors().add(new AuthenticationMgrSubjectCreatingInterceptor());
        }
      }
    }
  }