Skip to content

Commit

Permalink
Merge pull request #10 from RoboJackets/renovate/major-keycloak.version
Browse files Browse the repository at this point in the history
Update dependency org.keycloak:keycloak-parent to v24
  • Loading branch information
renovate[bot] authored Mar 10, 2024
2 parents 39bb913 + 7676745 commit 824f842
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 113 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</developers>

<properties>
<keycloak.version>23.0.7</keycloak.version>
<keycloak.version>24.0.1</keycloak.version>

<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.github.johnjcool.keycloak.broker.cas;

import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbContextResolver;
import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbProvider;
import java.util.List;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.keycloak.Config;
import org.keycloak.broker.provider.AbstractIdentityProviderFactory;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.KeycloakSession;
Expand All @@ -17,14 +13,6 @@ public class CasIdentityProviderFactory extends AbstractIdentityProviderFactory<

public static final String PROVIDER_ID = "cas";

@Override
public void init(final Config.Scope config) {
super.init(config);
ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbProvider.class, true);
ResteasyProviderFactory.getInstance()
.registerProvider(ServiceResponseJaxbContextResolver.class, true);
}

@Override
public String getName() {
return "CAS";
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.johnjcool.keycloak.broker.cas.model;

import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbContextResolver;
import io.github.johnjcool.keycloak.broker.cas.jaxb.ServiceResponseJaxbProvider;
import io.undertow.Undertow;
import io.undertow.util.Headers;
import jakarta.ws.rs.client.Client;
Expand All @@ -10,11 +8,11 @@
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Unmarshaller;
import java.io.File;
import java.io.StringReader;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import org.apache.commons.io.FileUtils;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.junit.AfterClass;
Expand All @@ -27,15 +25,25 @@ public class ServiceResponseTest {
private static Undertow server;

@Test
public void testReadWithAttributes() {
public void testReadWithAttributes() throws JAXBException {
Client client = ResteasyClientBuilder.newClient(ResteasyProviderFactory.getInstance());
WebTarget target =
client.target(String.format("http://%s:%d%s", "localhost", 9999, "/with-attributes"));
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
response.bufferEntity();

ServiceResponse serviceResponse = response.readEntity(ServiceResponse.class);
String stringResponse = response.readEntity(String.class);

Unmarshaller um = JAXBContext.newInstance(ServiceResponse.class).createUnmarshaller();
um.setEventHandler(new jakarta.xml.bind.helpers.DefaultValidationEventHandler());

ServiceResponse serviceResponse =
(ServiceResponse) um.unmarshal(new StringReader(stringResponse));

System.out.println(serviceResponse);
System.out.println(serviceResponse.getSuccess());
System.out.println(serviceResponse.getSuccess().getAttributes());
Success success = serviceResponse.getSuccess();

Assert.assertEquals("test", success.getUser());
Expand Down Expand Up @@ -81,17 +89,25 @@ public void testReadWithMultiValAttributes() throws JAXBException {
}

@Test
public void testReadWithoutAttributes() {
public void testReadWithoutAttributes() throws JAXBException {
Client client = ResteasyClientBuilder.newClient(ResteasyProviderFactory.getInstance());
WebTarget target =
client.target(String.format("http://%s:%d%s", "localhost", 9999, "/without-attributes"));
Response response = target.request().get();
Assert.assertEquals(200, response.getStatus());
response.bufferEntity();

System.out.println(response.readEntity(String.class));
String stringResponse = response.readEntity(String.class);

Unmarshaller um = JAXBContext.newInstance(ServiceResponse.class).createUnmarshaller();
um.setEventHandler(new jakarta.xml.bind.helpers.DefaultValidationEventHandler());

ServiceResponse serviceResponse =
(ServiceResponse) um.unmarshal(new StringReader(stringResponse));

ServiceResponse serviceResponse = response.readEntity(ServiceResponse.class);
System.out.println(serviceResponse);
System.out.println(serviceResponse.getSuccess());
System.out.println(serviceResponse.getSuccess().getAttributes());
Success success = serviceResponse.getSuccess();

Assert.assertEquals("test", success.getUser());
Expand All @@ -100,10 +116,6 @@ public void testReadWithoutAttributes() {

@BeforeClass
public static void init() {
ResteasyProviderFactory.getInstance().registerProvider(ServiceResponseJaxbProvider.class, true);
ResteasyProviderFactory.getInstance()
.registerProvider(ServiceResponseJaxbContextResolver.class, true);

server =
Undertow.builder()
.addHttpListener(9999, "localhost")
Expand All @@ -117,9 +129,16 @@ public static void init() {
httpServerExchange
.getResponseSender()
.send(
FileUtils.readFileToString(
new File("src/test/resources/test-without-attributes.xml"),
"UTF-8"));
Charset.defaultCharset()
.encode(
CharBuffer.wrap(
"""
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>test</cas:user>
</cas:authenticationSuccess>
</cas:serviceResponse>
""")));
break;
case "/with-attributes":
httpServerExchange
Expand All @@ -128,9 +147,29 @@ public static void init() {
httpServerExchange
.getResponseSender()
.send(
FileUtils.readFileToString(
new File("src/test/resources/test-with-attributes.xml"),
"UTF-8"));
Charset.defaultCharset()
.encode(
CharBuffer.wrap(
"""
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>test</cas:user>
<!-- Begin Ldap Attributes -->
<cas:attributes>
<cas:mail>test.test@test.test</cas:mail>
<cas:sn>tets</cas:sn>
<cas:cn>test</cas:cn>
</cas:attributes>
<!-- End Ldap Attributes -->
</cas:authenticationSuccess>
</cas:serviceResponse>
""")));
break;
case "/with-multival-attributes":
httpServerExchange
Expand All @@ -139,10 +178,32 @@ public static void init() {
httpServerExchange
.getResponseSender()
.send(
FileUtils.readFileToString(
new File(
"src/test/resources/test-with-multivalue-attributes.xml"),
"UTF-8"));
Charset.defaultCharset()
.encode(
CharBuffer.wrap(
"""
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>test</cas:user>
<!-- Begin Ldap Attributes -->
<cas:attributes>
<cas:mail>test.test@test.test</cas:mail>
<cas:sn>tets</cas:sn>
<cas:cn>test</cas:cn>
<cas:successfulAuthenticationHandlers>LdapAuthenticationHandler</cas:successfulAuthenticationHandlers>
<cas:successfulAuthenticationHandlers>mfa-duo</cas:successfulAuthenticationHandlers>
</cas:attributes>
<!-- End Ldap Attributes -->
</cas:authenticationSuccess>
</cas:serviceResponse>
""")));
break;
default:
throw new IllegalStateException(
Expand Down
18 changes: 0 additions & 18 deletions src/test/resources/test-with-attributes.xml

This file was deleted.

21 changes: 0 additions & 21 deletions src/test/resources/test-with-multivalue-attributes.xml

This file was deleted.

5 changes: 0 additions & 5 deletions src/test/resources/test-without-attributes.xml

This file was deleted.

0 comments on commit 824f842

Please sign in to comment.