KEYCLOAK-5308 Fix updating protocol mappers on Oracle

This commit is contained in:
Stian Thorgersen 2017-11-17 09:45:57 +01:00 committed by Stian Thorgersen
parent 5666bfe88b
commit cf485c3fc9
3 changed files with 54 additions and 9 deletions

View file

@ -1680,7 +1680,7 @@ public class RepresentationToModel {
model.setConsentText(rep.getConsentText()); model.setConsentText(rep.getConsentText());
model.setProtocol(rep.getProtocol()); model.setProtocol(rep.getProtocol());
model.setProtocolMapper(rep.getProtocolMapper()); model.setProtocolMapper(rep.getProtocolMapper());
model.setConfig(rep.getConfig()); model.setConfig(removeEmptyString(rep.getConfig()));
return model; return model;
} }

View file

@ -455,12 +455,12 @@ public class IdentityProviderTest extends AbstractAdminTest {
// KEYCLOAK-4962 // KEYCLOAK-4962
@Test @Test
public void testUpdateProtocolMappers() { public void testUpdateProtocolMappers() {
create(createRep("google", "google")); create(createRep("google2", "google"));
IdentityProviderResource provider = realm.identityProviders().get("google"); IdentityProviderResource provider = realm.identityProviders().get("google2");
IdentityProviderMapperRepresentation mapper = new IdentityProviderMapperRepresentation(); IdentityProviderMapperRepresentation mapper = new IdentityProviderMapperRepresentation();
mapper.setIdentityProviderAlias("google"); mapper.setIdentityProviderAlias("google2");
mapper.setName("my_mapper"); mapper.setName("my_mapper");
mapper.setIdentityProviderMapper("oidc-hardcoded-role-idp-mapper"); mapper.setIdentityProviderMapper("oidc-hardcoded-role-idp-mapper");
Map<String, String> config = new HashMap<>(); Map<String, String> config = new HashMap<>();

View file

@ -19,8 +19,8 @@ package org.keycloak.testsuite.admin.client;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.keycloak.admin.client.resource.ClientTemplatesResource; import org.keycloak.admin.client.resource.ClientTemplatesResource;
import org.keycloak.admin.client.resource.ProtocolMappersResource;
import org.keycloak.admin.client.resource.RoleMappingResource; import org.keycloak.admin.client.resource.RoleMappingResource;
import org.keycloak.events.admin.OperationType; import org.keycloak.events.admin.OperationType;
import org.keycloak.events.admin.ResourceType; import org.keycloak.events.admin.ResourceType;
@ -32,23 +32,27 @@ import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.ClientTemplateRepresentation; import org.keycloak.representations.idm.ClientTemplateRepresentation;
import org.keycloak.representations.idm.ErrorRepresentation; import org.keycloak.representations.idm.ErrorRepresentation;
import org.keycloak.representations.idm.MappingsRepresentation; import org.keycloak.representations.idm.MappingsRepresentation;
import org.keycloak.representations.idm.ProtocolMapperRepresentation;
import org.keycloak.representations.idm.RoleRepresentation; import org.keycloak.representations.idm.RoleRepresentation;
import org.keycloak.testsuite.admin.ApiUtil; import org.keycloak.testsuite.admin.ApiUtil;
import org.keycloak.testsuite.util.AdminEventPaths; import org.keycloak.testsuite.util.AdminEventPaths;
import org.keycloak.testsuite.util.Matchers; import org.keycloak.testsuite.util.Matchers;
import javax.ws.rs.BadRequestException; import javax.ws.rs.BadRequestException;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.NotFoundException; import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.ws.rs.*;
import javax.ws.rs.core.Response.Status;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/** /**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a> * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
@ -315,7 +319,6 @@ public class ClientTemplateTest extends AbstractClientTest {
return testRealmResource().roles().get(roleName).toRepresentation(); return testRealmResource().roles().get(roleName).toRepresentation();
} }
// KEYCLOAK-2844 // KEYCLOAK-2844
@Test @Test
public void testRemoveTemplateInUse() { public void testRemoveTemplateInUse() {
@ -350,6 +353,48 @@ public class ClientTemplateTest extends AbstractClientTest {
removeTemplate(templateId); removeTemplate(templateId);
} }
// KEYCLOAK-5863
@Test
public void testUpdateProtocolMappers() {
ClientTemplateRepresentation templateRep = new ClientTemplateRepresentation();
templateRep.setName("testUpdateProtocolMappers");
templateRep.setProtocol("openid-connect");
String templateId = createTemplate(templateRep);
ProtocolMapperRepresentation mapper = new ProtocolMapperRepresentation();
mapper.setName("test");
mapper.setProtocol("openid-connect");
mapper.setProtocolMapper("oidc-usermodel-attribute-mapper");
Map<String, String> m = new HashMap<>();
m.put("user.attribute", "test");
m.put("claim.name", "");
m.put("jsonType.label", "");
mapper.setConfig(m);
ProtocolMappersResource protocolMappers = clientTemplates().get(templateId).getProtocolMappers();
Response response = protocolMappers.createMapper(mapper);
String mapperId = ApiUtil.getCreatedId(response);
mapper = protocolMappers.getMapperById(mapperId);
mapper.getConfig().put("claim.name", "claim");
protocolMappers.update(mapperId, mapper);
List<ProtocolMapperRepresentation> mappers = protocolMappers.getMappers();
assertEquals(1, mappers.size());
assertEquals(2, mappers.get(0).getConfig().size());
assertEquals("test", mappers.get(0).getConfig().get("user.attribute"));
assertEquals("claim", mappers.get(0).getConfig().get("claim.name"));
clientTemplates().get(templateId).remove();
}
private ClientTemplatesResource clientTemplates() { private ClientTemplatesResource clientTemplates() {
return testRealmResource().clientTemplates(); return testRealmResource().clientTemplates();