KEYCLOAK-2847 Fix for client template duplicate name

This commit is contained in:
Hynek Mlnarik 2017-01-11 13:54:52 +01:00
parent c4cce147e2
commit 0b58bebc90
2 changed files with 36 additions and 1 deletions

View file

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

View file

@ -19,6 +19,7 @@ package org.keycloak.testsuite.admin.client;
import org.junit.Assert;
import org.junit.Test;
import org.keycloak.admin.client.resource.ClientTemplatesResource;
import org.keycloak.admin.client.resource.RoleMappingResource;
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.testsuite.admin.ApiUtil;
import org.keycloak.testsuite.util.AdminEventPaths;
import org.keycloak.testsuite.util.Matchers;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.NotFoundException;
@ -43,8 +45,10 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
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>
@ -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
public void testScopes() {
// Add realm role1