Merge pull request #3739 from hmlnarik/KEYCLOAK-2847-Unexpected-error-when-trying-to-update-clientTemplate-to-already-existing-name

KEYCLOAK-2847 Fix for client template duplicate name
This commit is contained in:
Stian Thorgersen 2017-01-16 09:45:39 +01:00 committed by GitHub
commit 1913f801b9
2 changed files with 36 additions and 1 deletions

View file

@ -104,6 +104,9 @@ public class ClientTemplateResource {
try { try {
RepresentationToModel.updateClientTemplate(rep, template); RepresentationToModel.updateClientTemplate(rep, template);
if (session.getTransactionManager().isActive()) {
session.getTransactionManager().commit();
}
adminEvent.operation(OperationType.UPDATE).resourcePath(uriInfo).representation(rep).success(); adminEvent.operation(OperationType.UPDATE).resourcePath(uriInfo).representation(rep).success();
return Response.noContent().build(); return Response.noContent().build();
} catch (ModelDuplicateException e) { } catch (ModelDuplicateException e) {

View file

@ -19,6 +19,7 @@ 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.RoleMappingResource; import org.keycloak.admin.client.resource.RoleMappingResource;
import org.keycloak.events.admin.OperationType; import org.keycloak.events.admin.OperationType;
@ -34,6 +35,7 @@ import org.keycloak.representations.idm.MappingsRepresentation;
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 javax.ws.rs.BadRequestException; import javax.ws.rs.BadRequestException;
import javax.ws.rs.NotFoundException; import javax.ws.rs.NotFoundException;
@ -43,8 +45,10 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.ws.rs.*;
import javax.ws.rs.core.Response.Status;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
/** /**
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a> * @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
@ -151,6 +155,34 @@ public class ClientTemplateTest extends AbstractClientTest {
} }
@Test
public void testRenameTemplate() {
// Create two templates
ClientTemplateRepresentation template1Rep = new ClientTemplateRepresentation();
template1Rep.setName("template1");
template1Rep.setDescription("template1-desc");
template1Rep.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
template1Rep.setFullScopeAllowed(true);
createTemplate(template1Rep);
ClientTemplateRepresentation template2Rep = new ClientTemplateRepresentation();
template2Rep.setName("template2");
template2Rep.setDescription("template2-desc");
template2Rep.setProtocol(OIDCLoginProtocol.LOGIN_PROTOCOL);
template2Rep.setFullScopeAllowed(true);
String template2Id = createTemplate(template2Rep);
// Test updating
template2Rep.setName("template1");
try {
clientTemplates().get(template2Id).update(template2Rep);
} catch (ClientErrorException ex) {
assertThat(ex.getResponse(), Matchers.statusCodeIs(Status.CONFLICT));
}
}
@Test @Test
public void testScopes() { public void testScopes() {
// Add realm role1 // Add realm role1