KEYCLOAK-3142 - Revised according to codereview
Liquibase Moved schema evolution configuration from jpa-changelog-2.1.0 to jpa-changelog-2.2.0. Corrected wrong ResourceType references in tests. Adapted AdminEvents copy-routines to be aware of resourceType attribute. Added ResourceType enum to exposed ENUMS of ServerInfoAdminResource. Signed-off-by: Thomas Darimont <thomas.darimont@gmail.com>
This commit is contained in:
parent
586f6eeece
commit
e49afb2d83
21 changed files with 73 additions and 39 deletions
|
@ -196,10 +196,4 @@
|
|||
|
||||
</changeSet>
|
||||
|
||||
<changeSet author="thomas.darimont@gmail.com" id="2.1.0.1">
|
||||
<addColumn tableName="ADMIN_EVENT_ENTITY">
|
||||
<column name="RESOURCE_TYPE" type="VARCHAR(64)"></column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
27
model/jpa/src/main/resources/META-INF/jpa-changelog-2.2.0.xml
Executable file
27
model/jpa/src/main/resources/META-INF/jpa-changelog-2.2.0.xml
Executable file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!--
|
||||
~ Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
~ and other contributors as indicated by the @author tags.
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
|
||||
<changeSet author="thomas.darimont@gmail.com" id="2.2.0">
|
||||
<addColumn tableName="ADMIN_EVENT_ENTITY">
|
||||
<column name="RESOURCE_TYPE" type="VARCHAR(64)"></column>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
|
@ -35,4 +35,5 @@
|
|||
|
||||
<include file="META-INF/jpa-changelog-authz-master.xml"/>
|
||||
<include file="META-INF/jpa-changelog-2.1.0.xml"/>
|
||||
<include file="META-INF/jpa-changelog-2.2.0.xml"/>
|
||||
</databaseChangeLog>
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.keycloak.events.Event;
|
|||
import org.keycloak.events.EventQuery;
|
||||
import org.keycloak.events.EventStoreProvider;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.events.admin.ResourceType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -172,6 +173,9 @@ public class MongoEventStoreProvider implements EventStoreProvider {
|
|||
adminEvent.setTime(o.getLong("time"));
|
||||
adminEvent.setRealmId(o.getString("realmId"));
|
||||
adminEvent.setOperationType(OperationType.valueOf(o.getString("operationType")));
|
||||
if (o.getString("resourceType") != null) {
|
||||
adminEvent.setResourceType(ResourceType.valueOf(o.getString("resourceType")));
|
||||
}
|
||||
setAuthDetails(adminEvent, o);
|
||||
adminEvent.setResourcePath(o.getString("resourcePath"));
|
||||
adminEvent.setError(o.getString("error"));
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.keycloak.broker.provider.IdentityProvider;
|
|||
import org.keycloak.broker.provider.IdentityProviderFactory;
|
||||
import org.keycloak.connections.httpclient.HttpClientProvider;
|
||||
import org.keycloak.events.admin.OperationType;
|
||||
import org.keycloak.events.admin.ResourceType;
|
||||
import org.keycloak.models.IdentityProviderModel;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.ModelDuplicateException;
|
||||
|
@ -71,7 +72,7 @@ public class IdentityProvidersResource {
|
|||
this.session = session;
|
||||
this.auth = auth;
|
||||
this.auth.init(RealmAuth.Resource.IDENTITY_PROVIDER);
|
||||
this.adminEvent = adminEvent;
|
||||
this.adminEvent = adminEvent.resource(ResourceType.IDENTITY_PROVIDER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -172,7 +172,6 @@ public class RoleContainerResource extends RoleResource {
|
|||
throw new NotFoundException("Could not find client");
|
||||
}
|
||||
|
||||
RoleRepresentation rep = getRole(roleName);
|
||||
RoleModel role = roleContainer.getRole(roleName);
|
||||
if (role == null) {
|
||||
throw new NotFoundException("Could not find role");
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.keycloak.broker.provider.IdentityProviderFactory;
|
|||
import org.keycloak.common.util.MultivaluedHashMap;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.events.admin.OperationType;
|
||||
import org.keycloak.events.admin.ResourceType;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.policy.PasswordPolicyProvider;
|
||||
import org.keycloak.policy.PasswordPolicyProviderFactory;
|
||||
|
@ -68,7 +69,7 @@ import org.keycloak.representations.info.ThemeInfoRepresentation;
|
|||
*/
|
||||
public class ServerInfoAdminResource {
|
||||
|
||||
private static final Map<String, List<String>> ENUMS = createEnumsMap(EventType.class, OperationType.class);
|
||||
private static final Map<String, List<String>> ENUMS = createEnumsMap(EventType.class, OperationType.class, ResourceType.class);
|
||||
|
||||
@Context
|
||||
private KeycloakSession session;
|
||||
|
|
|
@ -69,6 +69,7 @@ public class EventsListenerProvider implements EventListenerProvider {
|
|||
newEvent.setAuthDetails(adminEvent.getAuthDetails());
|
||||
newEvent.setError(adminEvent.getError());
|
||||
newEvent.setOperationType(adminEvent.getOperationType());
|
||||
newEvent.setResourceType(adminEvent.getResourceType());
|
||||
newEvent.setRealmId(adminEvent.getRealmId());
|
||||
newEvent.setRepresentation(adminEvent.getRepresentation());
|
||||
newEvent.setResourcePath(adminEvent.getResourcePath());
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.keycloak.common.util.Time;
|
|||
import org.keycloak.connections.infinispan.InfinispanConnectionProvider;
|
||||
import org.keycloak.events.Event;
|
||||
import org.keycloak.events.admin.AdminEvent;
|
||||
import org.keycloak.events.admin.ResourceType;
|
||||
import org.keycloak.models.KeycloakSession;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserSessionModel;
|
||||
|
@ -492,6 +493,9 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
event.setAuthDetails(repToModel(rep.getAuthDetails()));
|
||||
event.setError(rep.getError());
|
||||
event.setOperationType(OperationType.valueOf(rep.getOperationType()));
|
||||
if (rep.getResourceType() != null) {
|
||||
event.setResourceType(ResourceType.valueOf(rep.getResourceType()));
|
||||
}
|
||||
event.setRealmId(rep.getRealmId());
|
||||
event.setRepresentation(rep.getRepresentation());
|
||||
event.setResourcePath(rep.getResourcePath());
|
||||
|
|
|
@ -68,13 +68,13 @@ public class AttackDetectionResourceTest extends AbstractAdminTest {
|
|||
assertBruteForce(detection.bruteForceUserStatus("nosuchuser"), 0, false, false);
|
||||
|
||||
detection.clearBruteForceForUser(findUser("test-user@localhost").getId());
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.attackDetectionClearBruteForceForUserPath(findUser("test-user@localhost").getId()), ResourceType.USER);
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.attackDetectionClearBruteForceForUserPath(findUser("test-user@localhost").getId()), ResourceType.USER_LOGIN_FAILURE);
|
||||
|
||||
assertBruteForce(detection.bruteForceUserStatus(findUser("test-user@localhost").getId()), 0, false, false);
|
||||
assertBruteForce(detection.bruteForceUserStatus(findUser("test-user2").getId()), 2, true, true);
|
||||
|
||||
detection.clearAllBruteForce();
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.attackDetectionClearAllBruteForcePath(), ResourceType.USER);
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.attackDetectionClearAllBruteForcePath(), ResourceType.USER_LOGIN_FAILURE);
|
||||
|
||||
assertBruteForce(detection.bruteForceUserStatus(findUser("test-user@localhost").getId()), 0, false, false);
|
||||
assertBruteForce(detection.bruteForceUserStatus(findUser("test-user2").getId()), 0, false, false);
|
||||
|
|
|
@ -158,7 +158,7 @@ public class ClientTest extends AbstractAdminTest {
|
|||
foundClientRep.setDefaultRoles(new String[]{"test"});
|
||||
realm.clients().get(id).update(foundClientRep);
|
||||
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.clientResourcePath(id), rep, ResourceType.CLIENT_ROLE);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.clientResourcePath(id), rep, ResourceType.CLIENT);
|
||||
|
||||
assertArrayEquals(new String[]{"test"}, realm.clients().get(id).toRepresentation().getDefaultRoles());
|
||||
|
||||
|
@ -339,8 +339,8 @@ public class ClientTest extends AbstractAdminTest {
|
|||
realm.roles().create(roleRep1);
|
||||
realm.roles().create(roleRep2);
|
||||
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.roleResourcePath("role1"), roleRep1, ResourceType.CLIENT_ROLE);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.roleResourcePath("role2"), roleRep2, ResourceType.CLIENT_ROLE);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.roleResourcePath("role1"), roleRep1, ResourceType.REALM_ROLE);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.CREATE, AdminEventPaths.roleResourcePath("role2"), roleRep2, ResourceType.REALM_ROLE);
|
||||
|
||||
roleRep1 = realm.roles().get("role1").toRepresentation();
|
||||
roleRep2 = realm.roles().get("role2").toRepresentation();
|
||||
|
|
|
@ -258,14 +258,14 @@ public class UserFederationMapperTest extends AbstractAdminTest {
|
|||
|
||||
Map<String, Object> eventRep = new HashMap<>();
|
||||
eventRep.put("action", "fedToKeycloak");
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.ACTION, AdminEventPaths.userFederationMapperResourcePath(ldapProviderId, mapperId) + "/sync", eventRep, ResourceType.USER_FEDERATION_MAPPER);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.ACTION, AdminEventPaths.userFederationMapperResourcePath(ldapProviderId, mapperId) + "/sync", eventRep, ResourceType.USER_FEDERATION_PROVIDER);
|
||||
|
||||
// Try keycloak to fed
|
||||
result = ldapProviderResource().syncMapperData(mapperId, "keycloakToFed");
|
||||
Assert.assertEquals("dummyKeycloakToFedSuccess mapper=some-dummy", result.getStatus());
|
||||
|
||||
eventRep.put("action", "keycloakToFed");
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.ACTION, AdminEventPaths.userFederationMapperResourcePath(ldapProviderId, mapperId) + "/sync", ResourceType.USER_FEDERATION_MAPPER);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.ACTION, AdminEventPaths.userFederationMapperResourcePath(ldapProviderId, mapperId) + "/sync", ResourceType.USER_FEDERATION_PROVIDER);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ public class UserFederationTest extends AbstractAdminTest {
|
|||
// update LDAP provider with kerberos
|
||||
ldapRep = userFederation().get(id).toRepresentation();
|
||||
userFederation().get(id).update(ldapRep);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.userFederationResourcePath(id), ldapRep, ResourceType.REALM);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.userFederationResourcePath(id), ldapRep, ResourceType.USER_FEDERATION_PROVIDER);
|
||||
|
||||
// Assert kerberos authenticator still REQUIRED
|
||||
kerberosExecution = findKerberosExecution();
|
||||
|
@ -305,7 +305,7 @@ public class UserFederationTest extends AbstractAdminTest {
|
|||
// Cleanup
|
||||
kerberosExecution.setRequirement(AuthenticationExecutionModel.Requirement.DISABLED.toString());
|
||||
realm.flows().updateExecutions("browser", kerberosExecution);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.authUpdateExecutionPath("browser"), kerberosExecution, ResourceType.REALM);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.authUpdateExecutionPath("browser"), kerberosExecution, ResourceType.AUTH_EXECUTION);
|
||||
removeUserFederationProvider(id);
|
||||
|
||||
}
|
||||
|
|
|
@ -747,7 +747,7 @@ public class UserTest extends AbstractAdminTest {
|
|||
RequiredActionProviderRepresentation updatePasswordReqAction = realm.flows().getRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD.toString());
|
||||
updatePasswordReqAction.setDefaultAction(true);
|
||||
realm.flows().updateRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD.toString(), updatePasswordReqAction);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.authRequiredActionPath(UserModel.RequiredAction.UPDATE_PASSWORD.toString()), updatePasswordReqAction, ResourceType.USER);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.authRequiredActionPath(UserModel.RequiredAction.UPDATE_PASSWORD.toString()), updatePasswordReqAction, ResourceType.REQUIRED_ACTION);
|
||||
|
||||
// Create user
|
||||
String userId = createUser("user1", "user1@localhost");
|
||||
|
@ -760,7 +760,7 @@ public class UserTest extends AbstractAdminTest {
|
|||
updatePasswordReqAction = realm.flows().getRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD.toString());
|
||||
updatePasswordReqAction.setDefaultAction(true);
|
||||
realm.flows().updateRequiredAction(UserModel.RequiredAction.UPDATE_PASSWORD.toString(), updatePasswordReqAction);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.authRequiredActionPath(UserModel.RequiredAction.UPDATE_PASSWORD.toString()), updatePasswordReqAction, ResourceType.USER);
|
||||
assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, AdminEventPaths.authRequiredActionPath(UserModel.RequiredAction.UPDATE_PASSWORD.toString()), updatePasswordReqAction, ResourceType.REQUIRED_ACTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -84,7 +84,7 @@ public class ExecutionTest extends AbstractAuthenticationTest {
|
|||
// add execution - should succeed
|
||||
params.put("provider", "idp-review-profile");
|
||||
authMgmtResource.addExecution("Copy-of-browser", params);
|
||||
assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authAddExecutionPath("Copy-of-browser"), params, ResourceType.AUTH_EXECUTION_FLOW);
|
||||
assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authAddExecutionPath("Copy-of-browser"), params, ResourceType.AUTH_EXECUTION);
|
||||
|
||||
// check execution was added
|
||||
List<AuthenticationExecutionInfoRepresentation> executionReps = authMgmtResource.getExecutions("Copy-of-browser");
|
||||
|
|
|
@ -142,7 +142,7 @@ public class FlowTest extends AbstractAuthenticationTest {
|
|||
|
||||
// delete non-built-in flow
|
||||
authMgmtResource.deleteFlow(found.getId());
|
||||
assertAdminEvents.assertEvent(REALM_NAME, OperationType.DELETE, AdminEventPaths.authFlowPath(found.getId()), ResourceType.AUTH_EXECUTION_FLOW);
|
||||
assertAdminEvents.assertEvent(REALM_NAME, OperationType.DELETE, AdminEventPaths.authFlowPath(found.getId()), ResourceType.AUTH_FLOW);
|
||||
|
||||
// check the deleted flow is no longer returned
|
||||
flows = authMgmtResource.getFlows();
|
||||
|
|
|
@ -63,7 +63,7 @@ public class RegistrationFlowTest extends AbstractAuthenticationTest {
|
|||
|
||||
// Should success to add execution under form flow
|
||||
authMgmtResource.addExecution("registrationForm2", data2);
|
||||
assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authAddExecutionPath("registrationForm2"), data2, ResourceType.AUTH_EXECUTION_FLOW);
|
||||
assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authAddExecutionPath("registrationForm2"), data2, ResourceType.AUTH_EXECUTION);
|
||||
}
|
||||
|
||||
// TODO: More type-safety instead of passing generic maps
|
||||
|
|
|
@ -176,10 +176,10 @@ public class ClientTemplateTest extends AbstractClientTest {
|
|||
RoleMappingResource scopesResource = clientTemplates().get(templateId).getScopeMappings();
|
||||
|
||||
scopesResource.realmLevel().add(Collections.singletonList(roleRep1));
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientTemplateScopeMappingsRealmLevelPath(templateId), Collections.singletonList(roleRep1), ResourceType.CLIENT_TEMPLATE);
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientTemplateScopeMappingsRealmLevelPath(templateId), Collections.singletonList(roleRep1), ResourceType.REALM_SCOPE_MAPPING);
|
||||
|
||||
scopesResource.clientLevel(accountMgmtId).add(Collections.singletonList(viewAccountRoleRep));
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientTemplateScopeMappingsClientLevelPath(templateId, accountMgmtId), Collections.singletonList(viewAccountRoleRep), ResourceType.CLIENT_TEMPLATE);
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientTemplateScopeMappingsClientLevelPath(templateId, accountMgmtId), Collections.singletonList(viewAccountRoleRep), ResourceType.CLIENT_SCOPE_MAPPING);
|
||||
|
||||
// test that scopes are available (also through composite role)
|
||||
List<RoleRepresentation> allRealm = scopesResource.realmLevel().listAll();
|
||||
|
@ -198,10 +198,10 @@ public class ClientTemplateTest extends AbstractClientTest {
|
|||
|
||||
// remove scopes
|
||||
scopesResource.realmLevel().remove(Collections.singletonList(roleRep1));
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.clientTemplateScopeMappingsRealmLevelPath(templateId), Collections.singletonList(roleRep1), ResourceType.CLIENT_TEMPLATE);
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.clientTemplateScopeMappingsRealmLevelPath(templateId), Collections.singletonList(roleRep1), ResourceType.REALM_SCOPE_MAPPING);
|
||||
|
||||
scopesResource.clientLevel(accountMgmtId).remove(Collections.singletonList(viewAccountRoleRep));
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.clientTemplateScopeMappingsClientLevelPath(templateId, accountMgmtId), Collections.singletonList(viewAccountRoleRep), ResourceType.CLIENT_TEMPLATE);
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.DELETE, AdminEventPaths.clientTemplateScopeMappingsClientLevelPath(templateId, accountMgmtId), Collections.singletonList(viewAccountRoleRep), ResourceType.CLIENT_SCOPE_MAPPING);
|
||||
|
||||
// assert scopes are removed
|
||||
allRealm = scopesResource.realmLevel().listAll();
|
||||
|
@ -256,7 +256,7 @@ public class ClientTemplateTest extends AbstractClientTest {
|
|||
|
||||
// Add realm role to scopes of clientTemplate
|
||||
clientTemplates().get(templateId).getScopeMappings().realmLevel().add(Collections.singletonList(roleRep));
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientTemplateScopeMappingsRealmLevelPath(templateId), Collections.singletonList(roleRep), ResourceType.CLIENT_TEMPLATE);
|
||||
assertAdminEvents.assertEvent(getRealmId(), OperationType.CREATE, AdminEventPaths.clientTemplateScopeMappingsRealmLevelPath(templateId), Collections.singletonList(roleRep), ResourceType.REALM_SCOPE_MAPPING);
|
||||
|
||||
List<RoleRepresentation> roleReps = clientTemplates().get(templateId).getScopeMappings().realmLevel().listAll();
|
||||
Assert.assertEquals(1, roleReps.size());
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.junit.Test;
|
|||
import org.keycloak.admin.client.Keycloak;
|
||||
import org.keycloak.admin.client.resource.RealmResource;
|
||||
import org.keycloak.events.admin.OperationType;
|
||||
import org.keycloak.events.admin.ResourceType;
|
||||
import org.keycloak.models.AdminRoles;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
@ -136,6 +137,7 @@ public class AdminEventAuthDetailsTest extends AbstractAuthTest {
|
|||
.realmId(realmUuid)
|
||||
.operationType(OperationType.UPDATE)
|
||||
.resourcePath(AdminEventPaths.userResourcePath(appUserId))
|
||||
.resourceType(ResourceType.USER)
|
||||
.representation(rep)
|
||||
.authDetails(expectedRealmId, expectedClientUuid, expectedUserId)
|
||||
.assertEvent();
|
||||
|
|
|
@ -122,7 +122,7 @@ public class GroupTest extends AbstractGroupTest {
|
|||
List<RoleRepresentation> list = new LinkedList<>();
|
||||
list.add(role);
|
||||
realm.groups().group(group.getId()).roles().clientLevel(client.getId()).add(list);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientUuid), list, ResourceType.CLIENT_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientUuid), list, ResourceType.CLIENT_ROLE_MAPPING);
|
||||
|
||||
realm.clients().get(client.getId()).remove();
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.clientResourcePath(clientUuid), ResourceType.CLIENT);
|
||||
|
@ -172,7 +172,7 @@ public class GroupTest extends AbstractGroupTest {
|
|||
List<RoleRepresentation> roles = new LinkedList<>();
|
||||
roles.add(topRole);
|
||||
realm.groups().group(topGroup.getId()).roles().realmLevel().add(roles);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(topGroup.getId()), roles, ResourceType.GROUP);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(topGroup.getId()), roles, ResourceType.REALM_ROLE_MAPPING);
|
||||
|
||||
GroupRepresentation level2Group = new GroupRepresentation();
|
||||
level2Group.setName("level2");
|
||||
|
@ -199,7 +199,7 @@ public class GroupTest extends AbstractGroupTest {
|
|||
roles.clear();
|
||||
roles.add(level2Role);
|
||||
realm.groups().group(level2Group.getId()).roles().realmLevel().add(roles);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(level2Group.getId()), roles, ResourceType.REALM_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(level2Group.getId()), roles, ResourceType.REALM_ROLE_MAPPING);
|
||||
|
||||
GroupRepresentation level3Group = new GroupRepresentation();
|
||||
level3Group.setName("level3");
|
||||
|
@ -212,7 +212,7 @@ public class GroupTest extends AbstractGroupTest {
|
|||
roles.clear();
|
||||
roles.add(level3Role);
|
||||
realm.groups().group(level3Group.getId()).roles().realmLevel().add(roles);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(level3Group.getId()), roles, ResourceType.REALM_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(level3Group.getId()), roles, ResourceType.REALM_ROLE_MAPPING);
|
||||
|
||||
topGroup = realm.getGroupByPath("/top");
|
||||
assertEquals(1, topGroup.getRealmRoles().size());
|
||||
|
@ -420,15 +420,15 @@ public class GroupTest extends AbstractGroupTest {
|
|||
l.add(realm.roles().get("realm-role").toRepresentation());
|
||||
l.add(realm.roles().get("realm-composite").toRepresentation());
|
||||
roles.realmLevel().add(l);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(group.getId()), l, ResourceType.REALM_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesRealmRolesPath(group.getId()), l, ResourceType.REALM_ROLE_MAPPING);
|
||||
|
||||
// Add client roles
|
||||
RoleRepresentation clientRole = realm.clients().get(clientId).roles().get("client-role").toRepresentation();
|
||||
RoleRepresentation clientComposite = realm.clients().get(clientId).roles().get("client-composite").toRepresentation();
|
||||
roles.clientLevel(clientId).add(Collections.singletonList(clientRole));
|
||||
roles.clientLevel(clientId).add(Collections.singletonList(clientComposite));
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientId), Collections.singletonList(clientRole), ResourceType.CLIENT_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientId), Collections.singletonList(clientComposite), ResourceType.CLIENT_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientId), Collections.singletonList(clientRole), ResourceType.CLIENT_ROLE_MAPPING);
|
||||
assertAdminEvents.assertEvent("test", OperationType.CREATE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientId), Collections.singletonList(clientComposite), ResourceType.CLIENT_ROLE_MAPPING);
|
||||
|
||||
// List realm roles
|
||||
assertNames(roles.realmLevel().listAll(), "realm-role", "realm-composite");
|
||||
|
@ -449,13 +449,13 @@ public class GroupTest extends AbstractGroupTest {
|
|||
// Remove realm role
|
||||
RoleRepresentation realmRoleRep = realm.roles().get("realm-role").toRepresentation();
|
||||
roles.realmLevel().remove(Collections.singletonList(realmRoleRep));
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.groupRolesRealmRolesPath(group.getId()), Collections.singletonList(realmRoleRep), ResourceType.REALM_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.groupRolesRealmRolesPath(group.getId()), Collections.singletonList(realmRoleRep), ResourceType.REALM_ROLE_MAPPING);
|
||||
assertNames(roles.realmLevel().listAll(), "realm-composite");
|
||||
|
||||
// Remove client role
|
||||
RoleRepresentation clientRoleRep = realm.clients().get(clientId).roles().get("client-role").toRepresentation();
|
||||
roles.clientLevel(clientId).remove(Collections.singletonList(clientRoleRep));
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientId), Collections.singletonList(clientRoleRep), ResourceType.CLIENT_ROLE);
|
||||
assertAdminEvents.assertEvent("test", OperationType.DELETE, AdminEventPaths.groupRolesClientRolesPath(group.getId(), clientId), Collections.singletonList(clientRoleRep), ResourceType.CLIENT_ROLE_MAPPING);
|
||||
assertNames(roles.clientLevel(clientId).listAll(), "client-composite");
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ public class AssertAdminEvents implements TestRule {
|
|||
}
|
||||
|
||||
public ExpectedAdminEvent resourceType(ResourceType resourceType){
|
||||
this.resourceType = resourceType;
|
||||
expected.setResourceType(resourceType.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ public class AssertAdminEvents implements TestRule {
|
|||
public AdminEventRepresentation assertEvent(AdminEventRepresentation actual) {
|
||||
Assert.assertEquals(expected.getRealmId(), actual.getRealmId());
|
||||
Assert.assertThat(actual.getResourcePath(), resourcePath);
|
||||
Assert.assertEquals(actual.getResourceType(), resourceType);
|
||||
Assert.assertEquals(expected.getResourceType(), actual.getResourceType());
|
||||
Assert.assertEquals(expected.getOperationType(), actual.getOperationType());
|
||||
|
||||
Assert.assertTrue(ObjectUtil.isEqualOrBothNull(expected.getError(), actual.getError()));
|
||||
|
|
Loading…
Reference in a new issue