Merge pull request #3915 from TeliaSoneraNorge/KEYCLOAK-4524

KEYCLOAK-4524
This commit is contained in:
Bill Burke 2017-03-08 10:08:04 -05:00 committed by GitHub
commit efffcc5f41
3 changed files with 11 additions and 2 deletions

View file

@ -1194,7 +1194,7 @@ public class RealmAdapter implements RealmModel, JpaModel<RealmEntity> {
@Override
public IdentityProviderMapperModel addIdentityProviderMapper(IdentityProviderMapperModel model) {
if (getIdentityProviderMapperByName(model.getIdentityProviderAlias(), model.getIdentityProviderMapper()) != null) {
if (getIdentityProviderMapperByName(model.getIdentityProviderAlias(), model.getName()) != null) {
throw new RuntimeException("identity provider mapper name must be unique per identity provider");
}
String id = KeycloakModelUtils.generateId();

View file

@ -319,7 +319,11 @@ public class IdentityProviderResource {
}
IdentityProviderMapperModel model = RepresentationToModel.toModel(mapper);
try {
model = realm.addIdentityProviderMapper(model);
} catch (Exception e) {
return ErrorResponse.error("Failed to add mapper '" + model.getName() + "' to identity provider [" + identityProviderModel.getProviderId() + "].", Response.Status.BAD_REQUEST);
}
adminEvent.operation(OperationType.CREATE).resource(ResourceType.IDENTITY_PROVIDER_MAPPER).resourcePath(uriInfo, model.getId())
.representation(mapper).success();

View file

@ -424,6 +424,11 @@ public class IdentityProviderTest extends AbstractAdminTest {
Assert.assertNotNull("mapper.config exists", mapper.getConfig());
Assert.assertEquals("config retained", "offline_access", mapper.getConfig().get("role"));
// add duplicate mapper
Response error = provider.addMapper(mapper);
Assert.assertEquals("mapper unique name", 400, error.getStatus());
error.close();
// update mapper
mapper.getConfig().put("role", "master-realm.manage-realm");
provider.update(id, mapper);