Merge pull request #1668 from vramik/master
arquillian-testsuite: fixed org.keycloak.services.ForbiddenException in test log
This commit is contained in:
commit
424d357c9c
4 changed files with 54 additions and 12 deletions
|
@ -25,8 +25,8 @@ import java.net.URI;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.admin.client.resource.ClientResource;
|
||||
import org.keycloak.admin.client.resource.RoleScopeResource;
|
||||
import org.keycloak.admin.client.resource.UserResource;
|
||||
import org.keycloak.representations.idm.CredentialRepresentation;
|
||||
import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD;
|
||||
|
@ -37,6 +37,8 @@ import org.keycloak.representations.idm.UserRepresentation;
|
|||
* Created by st on 28.05.15.
|
||||
*/
|
||||
public class ApiUtil {
|
||||
|
||||
private static final Logger log = Logger.getLogger(ApiUtil.class);
|
||||
|
||||
public static String getCreatedId(Response response) {
|
||||
URI location = response.getLocation();
|
||||
|
@ -96,16 +98,32 @@ public class ApiUtil {
|
|||
userResource.resetPassword(newCredential);
|
||||
}
|
||||
|
||||
public static void assignClientRoles(UserResource userResource, String clientId, String... roles) {
|
||||
RoleScopeResource rsr = userResource.roles().clientLevel(clientId);
|
||||
List<String> rolesList = Arrays.asList(roles);
|
||||
List<RoleRepresentation> realmMgmtRoles = new ArrayList<>();
|
||||
for (RoleRepresentation rr : rsr.listAvailable()) {
|
||||
if (rolesList.contains(rr.getName())) {
|
||||
realmMgmtRoles.add(rr);
|
||||
public static void assignClientRoles(RealmResource realm, String userId, String clientName, String... roles) {
|
||||
String realmName = realm.toRepresentation().getRealm();
|
||||
String clientId = "";
|
||||
for (ClientRepresentation clientRepresentation : realm.clients().findAll()) {
|
||||
if (clientRepresentation.getClientId().equals(clientName)) {
|
||||
clientId = clientRepresentation.getId();
|
||||
}
|
||||
}
|
||||
rsr.add(realmMgmtRoles);
|
||||
|
||||
if (!clientId.isEmpty()) {
|
||||
ClientResource clientResource = realm.clients().get(clientId);
|
||||
|
||||
List<RoleRepresentation> roleRepresentations = new ArrayList<>();
|
||||
for (String roleName : roles) {
|
||||
RoleRepresentation role = clientResource.roles().get(roleName).toRepresentation();
|
||||
roleRepresentations.add(role);
|
||||
}
|
||||
|
||||
UserResource userResource = realm.users().get(userId);
|
||||
log.debug("assigning roles: " + Arrays.toString(roles) + " to user: \"" +
|
||||
userResource.toRepresentation().getUsername() + "\" of client: \"" +
|
||||
clientName + "\" in realm: \"" + realmName + "\"");
|
||||
userResource.roles().clientLevel(clientId).add(roleRepresentations);
|
||||
} else {
|
||||
log.warn("client with name " + clientName + "doesn't exist in realm " + realmName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.keycloak.testsuite.console.page.events;
|
|||
|
||||
import org.keycloak.testsuite.console.page.fragment.OnOffSwitch;
|
||||
import org.keycloak.testsuite.page.Form;
|
||||
import static org.keycloak.testsuite.util.WaitUtils.*;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
@ -101,5 +102,9 @@ public class Config extends Events {
|
|||
public void clearAdminEvents() {
|
||||
clearAdminEventsButton.click();
|
||||
}
|
||||
|
||||
public void waitForClearEventsButtonPresent() {
|
||||
waitAjaxForElement(clearLoginEventsButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2013 Red Hat, Inc. and/or its affiliates.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package org.keycloak.testsuite;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
@ -10,7 +27,7 @@ import org.keycloak.admin.client.resource.RealmResource;
|
|||
import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import static org.keycloak.testsuite.admin.ApiUtil.createUserAndResetPasswordWithAdminClient;
|
||||
import static org.keycloak.testsuite.admin.ApiUtil.*;
|
||||
import static org.keycloak.testsuite.admin.Users.setPasswordFor;
|
||||
import org.keycloak.testsuite.auth.page.AuthRealm;
|
||||
import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
||||
|
@ -56,6 +73,8 @@ public abstract class AbstractAuthTest extends AbstractKeycloakTest {
|
|||
log.debug("creating test user");
|
||||
String id = createUserAndResetPasswordWithAdminClient(testRealmResource(), testUser, PASSWORD);
|
||||
testUser.setId(id);
|
||||
|
||||
assignClientRoles(testRealmResource(), id, "realm-management", "view-realm");
|
||||
}
|
||||
|
||||
public static UserRepresentation createUserRepresentation(String username, String email, String firstName, String lastName, boolean enabled) {
|
||||
|
|
|
@ -21,14 +21,14 @@ import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD
|
|||
public class LoginEventsTest extends AbstractConsoleTest {
|
||||
@Page
|
||||
private LoginEvents loginEventsPage;
|
||||
|
||||
@Page
|
||||
private Config configPage;
|
||||
|
||||
|
||||
@Before
|
||||
public void beforeLoginEventsTest() {
|
||||
configPage.navigateTo();
|
||||
configPage.form().setSaveEvents(true);
|
||||
configPage.form().waitForClearEventsButtonPresent();
|
||||
configPage.form().addSaveType("LOGIN");
|
||||
configPage.form().addSaveType("LOGIN_ERROR");
|
||||
configPage.form().addSaveType("LOGOUT");
|
||||
|
|
Loading…
Reference in a new issue