@Override
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {

    // Check if we already have an OSGi deployment
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    Deployment deployment = OSGiDeploymentAttachment.getDeployment(deploymentUnit);

    ServiceRegistry serviceRegistry = phaseContext.getServiceRegistry();
    String location =
        DeploymentHolderService.getLocation(serviceRegistry, deploymentUnit.getName());
    VirtualFile virtualFile = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();

    // Check for attached BundleInfo
    BundleInfo info = BundleInfoAttachment.getBundleInfo(deploymentUnit);
    if (deployment == null && info != null) {
      deployment = DeploymentFactory.createDeployment(info);
      deployment.addAttachment(BundleInfo.class, info);
      OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment);
    }

    // Check for attached OSGiMetaData
    OSGiMetaData metadata = OSGiMetaDataAttachment.getOSGiMetaData(deploymentUnit);
    if (deployment == null && metadata != null) {
      String symbolicName = metadata.getBundleSymbolicName();
      Version version = metadata.getBundleVersion();
      deployment =
          DeploymentFactory.createDeployment(
              AbstractVFS.adapt(virtualFile), location, symbolicName, version);
      deployment.addAttachment(OSGiMetaData.class, metadata);
      OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment);
    }

    // Check for attached XModule
    XModule resModule = XModuleAttachment.getXModuleAttachment(deploymentUnit);
    if (deployment == null && resModule != null) {
      String symbolicName = resModule.getName();
      Version version = resModule.getVersion();
      deployment =
          DeploymentFactory.createDeployment(
              AbstractVFS.adapt(virtualFile), location, symbolicName, version);
      deployment.addAttachment(XModule.class, resModule);
      OSGiDeploymentAttachment.attachDeployment(deploymentUnit, deployment);
    }

    // Create the {@link OSGiDeploymentService}
    if (deployment != null) {

      // Prevent garbage collection of the MountHandle which will close the file
      MountHandle mount =
          deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getMountHandle();
      deployment.addAttachment(MountHandle.class, mount);

      // Mark the bundle to start automatically
      deployment.setAutoStart(true);

      OSGiDeploymentService.addService(phaseContext);
    }
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    String deploymentName = deploymentUnit.getName();

    KeycloakAdapterConfigService service =
        KeycloakAdapterConfigService.find(phaseContext.getServiceRegistry());
    // log.info("********* CHECK KEYCLOAK DEPLOYMENT: " + deploymentName);
    if (service.isSecureDeployment(deploymentName)) {
      addKeycloakAuthData(phaseContext, deploymentName, service);
      return;
    }

    // else check to see if KEYCLOAK is specified as login config
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) return;
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) return;

    LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
    if (loginConfig != null && "KEYCLOAK".equalsIgnoreCase(loginConfig.getAuthMethod())) {
      addValve(webMetaData);
    }
  }
  @SuppressWarnings("unchecked")
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit unit = phaseContext.getDeploymentUnit();

    ClojureMetaData metaData = unit.getAttachment(ClojureMetaData.ATTACHMENT_KEY);
    if (metaData == null && !ArchivedDeploymentMarker.isMarked(unit)) {
      return;
    }

    File root = metaData.getRoot();

    JarMountMap mountMap = new JarMountMap();
    unit.putAttachment(JarMountMap.ATTACHMENT_KEY, mountMap);

    try {
      List<File> dependencyJars =
          ApplicationBootstrapUtils.getDependencies(
              root, metaData.resolveDependencies(), metaData.getLeinProfiles());

      boolean clojureProvided = false;

      for (File each : dependencyJars) {
        if (each.getName().matches("^clojure(-\\d.\\d.\\d)?\\.jar$")) {
          clojureProvided = true;
        }
        mount(each, unit, mountMap);
      }

      if (!clojureProvided) {
        Immutant immutant =
            (Immutant)
                phaseContext.getServiceRegistry().getService(CoreServices.IMMUTANT).getValue();

        log.warn(
            "No clojure.jar found within "
                + metaData.getApplicationName()
                + ", Using built-in clojure.jar (v"
                + immutant.getClojureVersion()
                + ")");

        // borrow the shipped clojure.jar
        String jarPath =
            System.getProperty("jboss.home.dir") + "/modules/org/immutant/core/main/clojure.jar";
        mount(new File(jarPath), unit, mountMap);
      }

      // mount the runtime jar
      String runtimePath =
          System.getProperty("jboss.home.dir")
              + "/modules/org/immutant/core/main/immutant-runtime-impl.jar";
      mount(new File(runtimePath), unit, mountMap);

      for (String each : ApplicationBootstrapUtils.resourceDirs(root, metaData.getLeinProfiles())) {
        final ResourceRoot childResource = new ResourceRoot(VFS.getChild(each), null);
        ModuleRootMarker.mark(childResource);
        unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
      }

    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }

    // disable the annotation index, since we're not an EE app and it spits nasty WARNs to the log
    // if
    // ring is included as an app dep in relation to some jetty classes
    unit.putAttachment(Attachments.COMPUTE_COMPOSITE_ANNOTATION_INDEX, false);
    // AS let's us disable the index, but then assumes it's always there, so we give it an empty one
    unit.putAttachment(
        Attachments.COMPOSITE_ANNOTATION_INDEX, new CompositeIndex(Collections.EMPTY_LIST));
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final DeploymentUnit topLevelDeployment =
        deploymentUnit.getParent() == null ? deploymentUnit : deploymentUnit.getParent();
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    if (!WeldDeploymentMarker.isPartOfWeldDeployment(topLevelDeployment)) {
      return;
    }

    final Collection<ServiceName> dependencies =
        deploymentUnit.getAttachment(Attachments.JNDI_DEPENDENCIES);

    BeanDeploymentArchiveImpl rootBda =
        deploymentUnit.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
    if (rootBda == null) {
      // this archive is not actually a bean archive.
      // then use the top level root bda
      rootBda =
          topLevelDeployment.getAttachment(WeldAttachments.DEPLOYMENT_ROOT_BEAN_DEPLOYMENT_ARCHIVE);
    }
    if (rootBda == null) {
      WeldLogger.ROOT_LOGGER.couldNotFindBeanManagerForDeployment(deploymentUnit.getName());
      return;
    }

    final ServiceName weldServiceName =
        topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);

    // add the BeanManager service
    final ServiceName beanManagerServiceName = BeanManagerService.serviceName(deploymentUnit);
    BeanManagerService beanManagerService = new BeanManagerService(rootBda.getId());
    serviceTarget
        .addService(beanManagerServiceName, beanManagerService)
        .addDependency(
            weldServiceName, WeldBootstrapService.class, beanManagerService.getWeldContainer())
        .install();
    ;

    final EEModuleDescription moduleDescription =
        deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);

    if (moduleDescription == null) {
      return;
    }

    // hack to set up a java:comp binding for jar deployments as well as wars
    if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)
        || deploymentUnit.getName().endsWith(".jar")) {
      // bind the bean manager to JNDI
      final ServiceName moduleContextServiceName =
          ContextNames.contextServiceNameOfModule(
              moduleDescription.getApplicationName(), moduleDescription.getModuleName());
      bindBeanManager(
          serviceTarget,
          beanManagerServiceName,
          moduleContextServiceName,
          dependencies,
          phaseContext.getServiceRegistry());
    }

    // bind the bm into java:comp for all components that require it
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
      if (component.getNamingMode() == ComponentNamingMode.CREATE) {
        final ServiceName compContextServiceName =
            ContextNames.contextServiceNameOfComponent(
                moduleDescription.getApplicationName(),
                moduleDescription.getModuleName(),
                component.getComponentName());
        bindBeanManager(
            serviceTarget,
            beanManagerServiceName,
            compContextServiceName,
            dependencies,
            phaseContext.getServiceRegistry());
      }
    }
    deploymentUnit.addToAttachmentList(Attachments.SETUP_ACTIONS, new WeldContextSetup());
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    SipMetaData sipMetaData = deploymentUnit.getAttachment(SipMetaData.ATTACHMENT_KEY);
    if (sipMetaData == null) {
      SipAnnotationMetaData sipAnnotationMetaData =
          deploymentUnit.getAttachment(SipAnnotationMetaData.ATTACHMENT_KEY);
      if (sipAnnotationMetaData == null
          || !sipAnnotationMetaData.isSipApplicationAnnotationPresent()) {
        // http://code.google.com/p/sipservlets/issues/detail?id=168
        // When no sip.xml but annotations only, Application is not recognized as SIP App by AS7

        // In case there is no metadata attached, it means this is not a sip deployment, so we can
        // safely
        // ignore
        // it!
        return;
      }
    }

    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData();

    // lets find default server service:
    final ServiceName defaultServerServiceName = UndertowService.DEFAULT_SERVER;
    ServiceController<?> defaultServerServiceController =
        phaseContext.getServiceRegistry().getService(defaultServerServiceName);
    Server defaultServerService = (Server) defaultServerServiceController.getValue();

    final String defaultServer = defaultServerService.getName();
    final String defaultHost = defaultServerService.getDefaultHost();

    String hostName = UndertowSipDeploymentProcessor.hostNameOfDeployment(warMetaData, defaultHost);
    final String pathName =
        UndertowSipDeploymentProcessor.pathNameOfDeployment(deploymentUnit, metaData);

    String serverInstanceName =
        metaData.getServerInstanceName() == null ? defaultServer : metaData.getServerInstanceName();

    // lets find udertowdeployment service
    final ServiceName deploymentServiceName =
        UndertowService.deploymentServiceName(serverInstanceName, hostName, pathName);
    ServiceController<?> deploymentServiceController =
        phaseContext.getServiceRegistry().getService(deploymentServiceName);
    UndertowDeploymentService deploymentService =
        (UndertowDeploymentService) deploymentServiceController.getValue();

    // lets find udertowdeploymentinfo service
    final ServiceName deploymentInfoServiceName =
        deploymentServiceName.append(UndertowDeploymentInfoService.SERVICE_NAME);
    ServiceController<?> deploymentInfoServiceController =
        phaseContext.getServiceRegistry().getService(deploymentInfoServiceName);
    UndertowDeploymentInfoService deploymentInfoService =
        (UndertowDeploymentInfoService) deploymentInfoServiceController.getService();

    // lets inject undertowdeployment service to sip deploymentinfo service:
    final ServiceName sipDeploymentInfoServiceName =
        deploymentServiceName.append(UndertowSipDeploymentInfoService.SERVICE_NAME);
    ServiceController<?> sipDeplyomentInfoServiceController =
        phaseContext.getServiceRegistry().getService(sipDeploymentInfoServiceName);
    UndertowSipDeploymentInfoService sipDeplyomentInfoService =
        (UndertowSipDeploymentInfoService) sipDeplyomentInfoServiceController.getService();
    sipDeplyomentInfoService
        .getDeploymentInfoServiceInjectedValue()
        .setValue(new ImmediateValue<UndertowDeploymentInfoService>(deploymentInfoService));

    // initiate undertowsipdeployment service:
    final ServiceName sipDeploymentServiceName =
        deploymentServiceName.append(UndertowSipDeploymentService.SERVICE_NAME);
    UndertowSipDeploymentService sipDeploymentService =
        new UndertowSipDeploymentService(deploymentService, deploymentUnit);
    ServiceBuilder<UndertowSipDeploymentService> sipDeploymentServiceBuilder =
        phaseContext.getServiceTarget().addService(sipDeploymentServiceName, sipDeploymentService);

    // this service depends on the base undertowdeployment service:
    sipDeploymentServiceBuilder.addDependency(deploymentServiceName);
    sipDeploymentServiceBuilder.install();
  }