Skip to content

Commit

Permalink
Keycloak 25.x compatibility (#69)
Browse files Browse the repository at this point in the history
Compatibility with Keycloak 25.x
  • Loading branch information
nicolabeghin authored Jul 3, 2024
1 parent 57bd897 commit abc9a7e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 322 deletions.
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.lscorcia</groupId>
<artifactId>keycloak-spid-provider</artifactId>
<version>24.0.2</version>
<version>25.0.1</version>
<packaging>jar</packaging>

<name>Keycloak SPID Service Provider</name>
Expand All @@ -19,12 +19,13 @@
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<version.keycloak>24.0.3</version.keycloak>
<version.keycloak>25.0.1</version.keycloak>
<slf4j-api.version>1.7.30</slf4j-api.version>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<mockito.version>4.3.1</mockito.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<resteasy.version>6.2.7.Final</resteasy.version>
</properties>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static List<ProviderConfigProperty> getConfigProperties() {

.property()
.name(METADATA_URL)
.type(ProviderConfigProperty.STRING_TYPE)
.type(ProviderConfigProperty.URL_TYPE)
.defaultValue("/realms/<realm>/" + SpidSpMetadataResourceProviderFactory.ID)
.label("identity-provider.saml.url.metadata")
.helpText("identity-provider.saml.url.metadata.tooltip")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.keycloak.broker.spid;

import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -41,6 +40,7 @@
import org.keycloak.saml.common.constants.JBossSAMLURIConstants;
import org.keycloak.saml.common.exceptions.ParsingException;
import org.keycloak.saml.common.util.DocumentUtil;
import org.keycloak.saml.common.util.StaxParserUtil;
import org.keycloak.saml.processing.core.parsers.saml.SAMLParser;
import org.keycloak.saml.validators.DestinationValidator;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -74,9 +74,9 @@ public SpidIdentityProviderConfig createConfig() {
}

@Override
public Map<String, String> parseConfig(KeycloakSession session, InputStream inputStream) {
public Map<String, String> parseConfig(KeycloakSession session, String config) {
try {
Object parsedObject = SAMLParser.getInstance().parse(inputStream);
Object parsedObject = SAMLParser.getInstance().parse(StaxParserUtil.getXMLEventReader(config));
EntityDescriptorType entityType;

if (EntitiesDescriptorType.class.isInstance(parsedObject)) {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/org/keycloak/broker/spid/SpidSAMLEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
package org.keycloak.broker.spid;

import org.jboss.logging.Logger;
import org.jboss.resteasy.annotations.cache.NoCache;
//import org.jboss.resteasy.reactive.NoCache;

import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.broker.provider.BrokeredIdentityContext;
import org.keycloak.broker.provider.IdentityBrokerException;
import org.keycloak.broker.provider.IdentityProvider;
Expand Down Expand Up @@ -180,7 +179,7 @@ public SpidSAMLEndpoint(KeycloakSession session, SpidIdentityProvider provider,
}

@GET
@NoCache
// @NoCache
@Path("descriptor")
public Response getSPDescriptor() {
return provider.export(session.getContext().getUri(), realm, null);
Expand Down Expand Up @@ -555,7 +554,7 @@ protected Response handleLoginResponse(String samlResponse, SAMLDocumentHolder h
}

//Map<String, String> notes = new HashMap<>();
BrokeredIdentityContext identity = new BrokeredIdentityContext(principal);
BrokeredIdentityContext identity = new BrokeredIdentityContext(principal, config);
identity.getContextData().put(SAML_LOGIN_RESPONSE, responseType);
identity.getContextData().put(SAML_ASSERTION, assertion);
identity.setAuthenticationSession(authSession);
Expand Down Expand Up @@ -606,7 +605,6 @@ protected Response handleLoginResponse(String samlResponse, SAMLDocumentHolder h

String brokerUserId = config.getAlias() + "." + principal;
identity.setBrokerUserId(brokerUserId);
identity.setIdpConfig(config);
identity.setIdp(provider);
if (authn != null && authn.getSessionIndex() != null) {
identity.setBrokerSessionId(config.getAlias() + "." + authn.getSessionIndex());
Expand Down Expand Up @@ -646,7 +644,6 @@ private AuthenticationSessionModel samlIdpInitiatedSSO(final String clientUrlNam

LoginProtocolFactory factory = (LoginProtocolFactory) session.getKeycloakSessionFactory().getProviderFactory(LoginProtocol.class, SamlProtocol.LOGIN_PROTOCOL);
SamlService samlService = (SamlService) factory.createProtocolEndpoint(SpidSAMLEndpoint.this.session, event);
ResteasyProviderFactory.getInstance().injectProperties(samlService);
AuthenticationSessionModel authSession = samlService.getOrCreateLoginSessionForIdpInitiatedSso(session, SpidSAMLEndpoint.this.realm, oClient.get(), null);
if (authSession == null) {
event.error(Errors.INVALID_REDIRECT_URI);
Expand Down
Loading

0 comments on commit abc9a7e

Please sign in to comment.