[KEYCLOAK-4439] - Fixing saml adapter
This commit is contained in:
parent
a8ba3eb7f9
commit
476dd1cef5
6 changed files with 75 additions and 32 deletions
|
@ -103,9 +103,10 @@ class ElytronHttpFacade implements HttpFacade {
|
|||
|
||||
if (anonymousAuthorizationCallback.isAuthorized()) {
|
||||
callbackHandler.handle(new Callback[]{AuthenticationCompleteCallback.SUCCEEDED, new SecurityIdentityCallback()});
|
||||
}
|
||||
|
||||
request.authenticationComplete(response -> response.forward(getRequest().getRelativePath()));
|
||||
} else {
|
||||
request.noAuthenticationInProgress(response -> response.forward(getRequest().getRelativePath()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected error processing callbacks during logout.", e);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,9 @@ public class KeycloakConfigurationServletListener implements ServletContextListe
|
|||
public void contextInitialized(ServletContextEvent sce) {
|
||||
ServletContext servletContext = sce.getServletContext();
|
||||
String configResolverClass = servletContext.getInitParameter("keycloak.config.resolver");
|
||||
SamlDeploymentContext deploymentContext = null;
|
||||
SamlDeploymentContext deploymentContext = (SamlDeploymentContext) servletContext.getAttribute(SamlDeployment.class.getName());
|
||||
|
||||
if (deploymentContext == null) {
|
||||
if (configResolverClass != null) {
|
||||
try {
|
||||
throw new RuntimeException("Not implemented yet");
|
||||
|
@ -86,11 +88,13 @@ public class KeycloakConfigurationServletListener implements ServletContextListe
|
|||
}
|
||||
}
|
||||
deploymentContext = new SamlDeploymentContext(deployment);
|
||||
servletContext.setAttribute(ADAPTER_DEPLOYMENT_CONTEXT_ATTRIBUTE, deploymentContext);
|
||||
log.debug("Keycloak is using a per-deployment configuration.");
|
||||
}
|
||||
}
|
||||
|
||||
servletContext.setAttribute(ADAPTER_DEPLOYMENT_CONTEXT_ATTRIBUTE, deploymentContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
|
||||
|
|
|
@ -101,5 +101,10 @@
|
|||
<artifactId>keycloak-saml-wildfly-adapter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-saml-wildfly-elytron-adapter</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -25,10 +25,12 @@ import org.jboss.as.web.common.WarMetaData;
|
|||
import org.jboss.dmr.ModelNode;
|
||||
import org.jboss.metadata.javaee.spec.ParamValueMetaData;
|
||||
import org.jboss.metadata.web.jboss.JBossWebMetaData;
|
||||
import org.jboss.metadata.web.spec.ListenerMetaData;
|
||||
import org.jboss.metadata.web.spec.LoginConfigMetaData;
|
||||
import org.jboss.staxmapper.FormattingXMLStreamWriter;
|
||||
import org.jboss.staxmapper.XMLExtendedStreamWriter;
|
||||
import org.keycloak.adapters.saml.AdapterConstants;
|
||||
import org.keycloak.adapters.saml.elytron.KeycloakConfigurationServletListener;
|
||||
import org.keycloak.subsystem.adapter.saml.extension.logging.KeycloakLogger;
|
||||
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
|
@ -52,6 +54,8 @@ public class KeycloakAdapterConfigDeploymentProcessor implements DeploymentUnitP
|
|||
if (Configuration.INSTANCE.getSecureDeployment(deploymentUnit) != null) {
|
||||
addKeycloakSamlAuthData(phaseContext);
|
||||
}
|
||||
|
||||
addConfigurationListener(deploymentUnit);
|
||||
}
|
||||
|
||||
private void addKeycloakSamlAuthData(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
|
||||
|
@ -124,4 +128,30 @@ public class KeycloakAdapterConfigDeploymentProcessor implements DeploymentUnitP
|
|||
public void undeploy(DeploymentUnit du) {
|
||||
|
||||
}
|
||||
|
||||
private void addConfigurationListener(DeploymentUnit deploymentUnit) {
|
||||
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;
|
||||
}
|
||||
ListenerMetaData listenerMetaData = new ListenerMetaData();
|
||||
|
||||
listenerMetaData.setListenerClass(KeycloakConfigurationServletListener.class.getName());
|
||||
|
||||
webMetaData.getListeners().add(listenerMetaData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.jboss.modules.ModuleLoader;
|
|||
*/
|
||||
public class KeycloakDependencyProcessorWildFly extends KeycloakDependencyProcessor {
|
||||
|
||||
private static final ModuleIdentifier KEYCLOAK_ELYTRON_ADAPTER = ModuleIdentifier.create("org.keycloak.keycloak-saml-wildfly-elytron-adapter");
|
||||
private static final ModuleIdentifier KEYCLOAK_WILDFLY_ADAPTER = ModuleIdentifier.create("org.keycloak.keycloak-saml-wildfly-adapter");
|
||||
private static final ModuleIdentifier KEYCLOAK_UNDERTOW_ADAPTER = ModuleIdentifier.create("org.keycloak.keycloak-saml-undertow-adapter");
|
||||
|
||||
|
@ -37,5 +38,6 @@ public class KeycloakDependencyProcessorWildFly extends KeycloakDependencyProces
|
|||
// ModuleDependency(ModuleLoader moduleLoader, ModuleIdentifier identifier, boolean optional, boolean export, boolean importServices, boolean userSpecified)
|
||||
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_WILDFLY_ADAPTER, false, false, true, false));
|
||||
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_UNDERTOW_ADAPTER, false, false, false, false));
|
||||
moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, KEYCLOAK_ELYTRON_ADAPTER, true, false, false, false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,5 +41,6 @@
|
|||
<module name="org.jboss.metadata"/>
|
||||
<module name="org.apache.httpcomponents"/>
|
||||
<module name="org.infinispan.cachestore.remote"/>
|
||||
<module name="org.keycloak.keycloak-saml-wildfly-elytron-adapter"/>
|
||||
</dependencies>
|
||||
</module>
|
||||
|
|
Loading…
Reference in a new issue