Merge pull request #3915 from TeliaSoneraNorge/KEYCLOAK-4524
KEYCLOAK-4524
This commit is contained in:
commit
efffcc5f41
3 changed files with 11 additions and 2 deletions
|
@ -1194,7 +1194,7 @@ public class RealmAdapter implements RealmModel, JpaModel<RealmEntity> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IdentityProviderMapperModel addIdentityProviderMapper(IdentityProviderMapperModel model) {
|
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");
|
throw new RuntimeException("identity provider mapper name must be unique per identity provider");
|
||||||
}
|
}
|
||||||
String id = KeycloakModelUtils.generateId();
|
String id = KeycloakModelUtils.generateId();
|
||||||
|
|
|
@ -319,7 +319,11 @@ public class IdentityProviderResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityProviderMapperModel model = RepresentationToModel.toModel(mapper);
|
IdentityProviderMapperModel model = RepresentationToModel.toModel(mapper);
|
||||||
|
try {
|
||||||
model = realm.addIdentityProviderMapper(model);
|
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())
|
adminEvent.operation(OperationType.CREATE).resource(ResourceType.IDENTITY_PROVIDER_MAPPER).resourcePath(uriInfo, model.getId())
|
||||||
.representation(mapper).success();
|
.representation(mapper).success();
|
||||||
|
|
|
@ -424,6 +424,11 @@ public class IdentityProviderTest extends AbstractAdminTest {
|
||||||
Assert.assertNotNull("mapper.config exists", mapper.getConfig());
|
Assert.assertNotNull("mapper.config exists", mapper.getConfig());
|
||||||
Assert.assertEquals("config retained", "offline_access", mapper.getConfig().get("role"));
|
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
|
// update mapper
|
||||||
mapper.getConfig().put("role", "master-realm.manage-realm");
|
mapper.getConfig().put("role", "master-realm.manage-realm");
|
||||||
provider.update(id, mapper);
|
provider.update(id, mapper);
|
||||||
|
|
Loading…
Reference in a new issue