Skip to content

Commit

Permalink
Use admin console correctly in KeycloakIdentity
Browse files Browse the repository at this point in the history
Fixes: keycloak#29688

Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
  • Loading branch information
hmlnarik committed May 21, 2024
1 parent bb5f308 commit 65fcd44
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
12 changes: 6 additions & 6 deletions js/apps/admin-ui/cypress/e2e/client_authorization_test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe("Client authentication subtab", () => {
);
});

describe.skip("Client authorization tab access for view-realm-authorization", () => {
describe("Client authorization tab access for view-realm-authorization", () => {
const clientId = "realm-view-authz-client-" + uuid();

beforeEach(async () => {
Expand Down Expand Up @@ -241,11 +241,11 @@ describe("Client authentication subtab", () => {
loginPage.logIn("test-view-authz-user", "password");
keycloakBefore();

sidebarPage
.waitForPageLoad()
.goToRealm("realm-view-authz")
.waitForPageLoad()
.goToClients();
sidebarPage.waitForPageLoad().goToRealm("realm-view-authz");

cy.reload();

sidebarPage.waitForPageLoad().goToClients();

listingPage
.searchItem(clientId, true, "realm-view-authz")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public UIRealmsResource(KeycloakSession session, AdminPermissionEvaluator auth)
)}
)
public Stream<RealmNameRepresentation> getRealms() {
final RealmsPermissionEvaluator eval = AdminPermissions.realms(session, auth.adminAuth());

Stream<RealmNameRepresentation> realms = session.realms().getRealmsStream()
.filter(realm -> {
RealmsPermissionEvaluator eval = AdminPermissions.realms(session, auth.adminAuth());
return eval.canView(realm) || eval.isAdmin(realm);
})
.map((RealmModel realm) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ class MgmtPermissions implements AdminPermissionEvaluator, AdminPermissionManage
}

private void initIdentity(KeycloakSession session, AdminAuth auth) {
if (Constants.ADMIN_CLI_CLIENT_ID.equals(auth.getToken().getIssuedFor())
|| Constants.ADMIN_CONSOLE_CLIENT_ID.equals(auth.getToken().getIssuedFor())) {
this.identity = new UserModelIdentity(auth.getRealm(), auth.getUser());
final String issuedFor = auth.getToken().getIssuedFor();

if (Constants.ADMIN_CLI_CLIENT_ID.equals(issuedFor) || Constants.ADMIN_CONSOLE_CLIENT_ID.equals(issuedFor)) {
this.identity = new UserModelIdentity(auth.getRealm(), auth.getUser());
} else {
this.identity = new KeycloakIdentity(auth.getToken(), session);
ClientModel client = session.clients().getClientByClientId(auth.getRealm(), issuedFor);
if (client != null && Boolean.parseBoolean(client.getAttribute(Constants.SECURITY_ADMIN_CONSOLE_ATTR))) {
this.identity = new UserModelIdentity(auth.getRealm(), auth.getUser());
} else {
this.identity = new KeycloakIdentity(auth.getToken(), session);
}
}
}

Expand Down

0 comments on commit 65fcd44

Please sign in to comment.