private String getXML(DeploymentUnit deploymentUnit) throws XMLStreamException { ModelNode node = Configuration.INSTANCE.getSecureDeployment(deploymentUnit); if (node != null) { KeycloakSubsystemParser writer = new KeycloakSubsystemParser(); ByteArrayOutputStream output = new ByteArrayOutputStream(); XMLExtendedStreamWriter streamWriter = new FormattingXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(output)); try { streamWriter.writeStartElement("keycloak-saml-adapter"); writer.writeSps(streamWriter, node); streamWriter.writeEndElement(); } finally { streamWriter.close(); } return new String(output.toByteArray(), Charset.forName("utf-8")); } return null; }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) != null) { addKeycloakSamlAuthData(phaseContext); } addConfigurationListener(phaseContext); }
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"); }
@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); }