org.jboss.as.web.common.WarMetaData Java Examples

The following examples show how to use org.jboss.as.web.common.WarMetaData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!KeycloakAdapterConfigService.getInstance().isSecureDeployment(deploymentUnit)) {
        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) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) return;
    }

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(phaseContext, moduleSpecification, moduleLoader);
}
 
Example #2
Source File: Elytron.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private static String getSecurityDomain(DeploymentUnit deploymentUnit) {
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);

    if (warMetaData != null) {
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();

        if (webMetaData != null) {
            String configuredSecurityDomain = webMetaData.getSecurityDomain();

            if (configuredSecurityDomain != null) {
                return configuredSecurityDomain;
            }
        }
    }

    return DEFAULT_SECURITY_DOMAIN;
}
 
Example #3
Source File: KeycloakAdapterConfigService.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private String preferredDeploymentName(DeploymentUnit deploymentUnit) {
    String deploymentName = deploymentUnit.getName();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return deploymentName;
    }
    
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return deploymentName;
    }
    
    String moduleName = webMetaData.getModuleName();
    if (moduleName != null) return moduleName + ".war";
    
    return deploymentName;
}
 
Example #4
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
protected void addSecurityDomain(DeploymentUnit deploymentUnit, KeycloakAdapterConfigService service) {
    if (!service.isSecureDeployment(deploymentUnit)) {
        return;
    }
    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 || !loginConfig.getAuthMethod().equalsIgnoreCase("KEYCLOAK")) {
        return;
    }

    webMetaData.setSecurityDomain("keycloak");
}
 
Example #5
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void addKeycloakAuthData(DeploymentPhaseContext phaseContext, KeycloakAdapterConfigService service) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        throw new DeploymentUnitProcessingException("WarMetaData not found for " + deploymentUnit.getName() + ".  Make sure you have specified a WAR as your secure-deployment in the Keycloak subsystem.");
    }

    addJSONData(service.getJSON(deploymentUnit), warMetaData);
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
    if (loginConfig == null) {
        loginConfig = new LoginConfigMetaData();
        webMetaData.setLoginConfig(loginConfig);
    }
    loginConfig.setAuthMethod("KEYCLOAK");
    loginConfig.setRealmName(service.getRealmName(deploymentUnit));
    KeycloakLogger.ROOT_LOGGER.deploymentSecured(deploymentUnit.getName());
}
 
Example #6
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void addJSONData(String json, WarMetaData warMetaData) {
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    if (contextParams == null) {
        contextParams = new ArrayList<ParamValueMetaData>();
    }

    ParamValueMetaData param = new ParamValueMetaData();
    param.setParamName(AUTH_DATA_PARAM_NAME);
    param.setParamValue(json);
    contextParams.add(param);

    webMetaData.setContextParams(contextParams);
}
 
Example #7
Source File: KeycloakDependencyProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) == null) {
        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) return;
        if (loginConfig.getAuthMethod() == null) return;
        if (!loginConfig.getAuthMethod().equals("KEYCLOAK-SAML")) return;
    }

     // Next phase, need to detect if this is a Keycloak deployment.  If not, don't add the modules.

    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    addCommonModules(moduleSpecification, moduleLoader);
    addPlatformSpecificModules(phaseContext, moduleSpecification, moduleLoader);
}
 
Example #8
Source File: KeycloakClusteredSsoDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public static boolean isKeycloakSamlAuthMethod(final DeploymentUnit deploymentUnit) {
    if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) != null) {
        return true;
    }

    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return false;
    }
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return false;
    }

    LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();

    return loginConfig != null && Objects.equals(loginConfig.getAuthMethod(), "KEYCLOAK-SAML");
}
 
Example #9
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void addXMLData(String xml, WarMetaData warMetaData) {
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    if (contextParams == null) {
        contextParams = new ArrayList<>();
    }

    ParamValueMetaData param = new ParamValueMetaData();
    param.setParamName(AdapterConstants.AUTH_DATA_PARAM_NAME);
    param.setParamValue(xml);
    contextParams.add(param);

    webMetaData.setContextParams(contextParams);
}
 
Example #10
Source File: Elytron.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private static String getSecurityDomain(DeploymentUnit deploymentUnit) {
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);

    if (warMetaData != null) {
        JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();

        if (webMetaData != null) {
            String configuredSecurityDomain = webMetaData.getSecurityDomain();

            if (configuredSecurityDomain != null) {
                return configuredSecurityDomain;
            }
        }
    }

    return DEFAULT_SECURITY_DOMAIN;
}
 
Example #11
Source File: Configuration.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private String preferredDeploymentName(DeploymentUnit deploymentUnit) {
    String deploymentName = deploymentUnit.getName();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return deploymentName;
    }
    
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return deploymentName;
    }
    
    String moduleName = webMetaData.getModuleName();
    if (moduleName != null) return moduleName + ".war";
    
    return deploymentName;
}
 
Example #12
Source File: KeycloakServerDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addConfiguration(DeploymentUnit deploymentUnit, KeycloakAdapterConfigService configService) throws DeploymentUnitProcessingException {
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        throw new DeploymentUnitProcessingException("WarMetaData not found for KeycloakServer.");
    }
    
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    if (contextParams == null) {
        contextParams = new ArrayList<>();
    }

    ParamValueMetaData param = new ParamValueMetaData();
    param.setParamName(KEYCLOAK_CONFIG_PARAM_NAME);
    param.setParamValue(configService.getConfig().toString());
    contextParams.add(param);

    // Prefer ResteasyJackson2Provider over JsonBindingProvider
    param = new ParamValueMetaData();
    param.setParamName("resteasy.preferJacksonOverJsonB"); // Corresponds to ResteasyContextParameters.RESTEASY_PREFER_JACKSON_OVER_JSONB
    param.setParamValue(Boolean.TRUE.toString());
    contextParams.add(param);

    webMetaData.setContextParams(contextParams);
}
 
Example #13
Source File: CamelEndpointDeployerProcessor.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    CamelDeploymentSettings depSettings = deploymentUnit.getAttachment(CamelDeploymentSettings.ATTACHMENT_KEY);

    if (!depSettings.isEnabled()) {
        return;
    }
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        /* ignore non-war deployments */
        CamelLogger.LOGGER.debug("{} ignores non-WAR deployment {}",
                CamelEndpointDeployerProcessor.class.getSimpleName(), deploymentUnit.getName());
        return;
    }

    final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit
            .getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
    final ModelNode node = deploymentResourceSupport.getDeploymentSubsystemModel(UndertowExtension.SUBSYSTEM_NAME);
    final String hostName = node.get(DeploymentDefinition.VIRTUAL_HOST.getName()).asString();
    final String serverName = node.get(DeploymentDefinition.SERVER.getName()).asString();
    final String path = node.get(DeploymentDefinition.CONTEXT_ROOT.getName()).asString();

    final ServiceName deploymentServiceName = UndertowService.deploymentServiceName(serverName, hostName, path);
    final ServiceName deploymentInfoServiceName = deploymentServiceName
            .append(UndertowDeploymentInfoService.SERVICE_NAME);
    final ServiceName hostServiceName = UndertowService.virtualHostName(serverName, hostName);

    CamelEndpointDeployerService.addService(deploymentUnit, phaseContext.getServiceTarget(),
            deploymentInfoServiceName, hostServiceName);
}
 
Example #14
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addConfigurationListener(DeploymentPhaseContext phaseContext) {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return;
    }

    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
    if (loginConfig == null) {
        return;
    }
    if (!loginConfig.getAuthMethod().equals("KEYCLOAK-SAML")) {
        return;
    }

    if (isElytronEnabled(phaseContext)) {
        ListenerMetaData listenerMetaData = new ListenerMetaData();

        listenerMetaData.setListenerClass(KeycloakConfigurationServletListener.class.getName());

        webMetaData.getListeners().add(listenerMetaData);
    }
}
 
Example #15
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addKeycloakSamlAuthData(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        throw new DeploymentUnitProcessingException("WarMetaData not found for " + deploymentUnit.getName() + ".  Make sure you have specified a WAR as your secure-deployment in the Keycloak subsystem.");
    }

    try {
        addXMLData(getXML(deploymentUnit), warMetaData);
    } catch (Exception e) {
        throw new DeploymentUnitProcessingException("Failed to configure KeycloakSamlExtension from subsystem model", e);
    }
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
    if (loginConfig == null) {
        loginConfig = new LoginConfigMetaData();
        webMetaData.setLoginConfig(loginConfig);
    }
    loginConfig.setAuthMethod("KEYCLOAK-SAML");

    KeycloakLogger.ROOT_LOGGER.deploymentSecured(deploymentUnit.getName());
}
 
Example #16
Source File: KeycloakClusteredSsoDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static boolean isDistributable(final DeploymentUnit deploymentUnit) {
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return false;
    }
    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        return false;
    }

    return webMetaData.getDistributable() != null || webMetaData.getReplicationConfig() != null;
}
 
Example #17
Source File: KeycloakAdapterConfigDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void addConfigurationListener(DeploymentPhaseContext phaseContext) {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return;
    }

    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    LoginConfigMetaData loginConfig = webMetaData.getLoginConfig();
    if (loginConfig == null) {
        return;
    }
    if (!loginConfig.getAuthMethod().equals("KEYCLOAK")) {
        return;
    }

    if (isElytronEnabled(phaseContext)) {
        ListenerMetaData listenerMetaData = new ListenerMetaData();

        listenerMetaData.setListenerClass(KeycloakConfigurationServletListener.class.getName());

        webMetaData.getListeners().add(listenerMetaData);
    }
}
 
Example #18
Source File: KeycloakClusteredSsoDeploymentProcessor.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private void addSamlReplicationConfiguration(DeploymentUnit deploymentUnit, DeploymentPhaseContext context) {
    WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        return;
    }

    JBossWebMetaData webMetaData = warMetaData.getMergedJBossWebMetaData();
    if (webMetaData == null) {
        webMetaData = new JBossWebMetaData();
        warMetaData.setMergedJBossWebMetaData(webMetaData);
    }

    // Find out default names of cache container and cache
    String cacheContainer = DEFAULT_CACHE_CONTAINER;
    String deploymentSessionCacheName =
      (deploymentUnit.getParent() == null
          ? ""
          : deploymentUnit.getParent().getName() + ".")
      + deploymentUnit.getName();

    // Update names from jboss-web.xml's <replicationConfig>
    if (webMetaData.getReplicationConfig() != null && webMetaData.getReplicationConfig().getCacheName() != null) {
        ServiceName sn = ServiceName.parse(webMetaData.getReplicationConfig().getCacheName());
        cacheContainer = (sn.length() > 1) ? sn.getParent().getSimpleName() : sn.getSimpleName();
        deploymentSessionCacheName = sn.getSimpleName();
    }
    String ssoCacheName = deploymentSessionCacheName + ".ssoCache";

    // Override if they were set in the context parameters
    List<ParamValueMetaData> contextParams = webMetaData.getContextParams();
    if (contextParams == null) {
        contextParams = new ArrayList<>();
    }
    for (ParamValueMetaData contextParam : contextParams) {
        if (Objects.equals(contextParam.getParamName(), SSO_CACHE_CONTAINER_NAME_PARAM_NAME)) {
            cacheContainer = contextParam.getParamValue();
        } else if (Objects.equals(contextParam.getParamName(), SSO_CACHE_NAME_PARAM_NAME)) {
            ssoCacheName = contextParam.getParamValue();
        }
    }

    LOG.debugv("Determined SSO cache container configuration: container: {0}, cache: {1}", cacheContainer, ssoCacheName);
    addCacheDependency(context, deploymentUnit, cacheContainer, ssoCacheName);

    // Set context parameters for SSO cache container/name
    ParamValueMetaData paramContainer = new ParamValueMetaData();
    paramContainer.setParamName(AdapterConstants.REPLICATION_CONFIG_CONTAINER_PARAM_NAME);
    paramContainer.setParamValue(cacheContainer);
    contextParams.add(paramContainer);

    ParamValueMetaData paramSsoCache = new ParamValueMetaData();
    paramSsoCache.setParamName(AdapterConstants.REPLICATION_CONFIG_SSO_CACHE_PARAM_NAME);
    paramSsoCache.setParamValue(ssoCacheName);
    contextParams.add(paramSsoCache);

    webMetaData.setContextParams(contextParams);
}