Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@

package org.keycloak.admin.client.resource;

import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.keycloak.representations.idm.MemberRepresentation;
import org.keycloak.representations.idm.OrganizationRepresentation;

public interface OrganizationMemberResource {

Expand All @@ -32,4 +36,9 @@ public interface OrganizationMemberResource {

@DELETE
Response delete();

@Path("organizations")
@GET
@Produces(MediaType.APPLICATION_JSON)
List<OrganizationRepresentation> getOrganizations();
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ List<MemberRepresentation> search(
@QueryParam("max") Integer max
);

@Path("{id}/organization")
@GET
@Produces(MediaType.APPLICATION_JSON)
OrganizationRepresentation getOrganization(@PathParam("id") String id);

@Path("{id}")
OrganizationMemberResource member(@PathParam("id") String id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,7 @@ protected UserModel cacheUser(RealmModel realm, UserModel delegate, Long revisio
int notBefore = getDelegate().getNotBeforeOfUser(realm, delegate);

if (Profile.isFeatureEnabled(Profile.Feature.ORGANIZATION)) {
// check if provider is enabled and user is managed member of a disabled organization OR provider is disabled and user is managed member
OrganizationProvider organizationProvider = session.getProvider(OrganizationProvider.class);
OrganizationModel organization = organizationProvider.getByMember(delegate);

if ((organizationProvider.isEnabled() && organization != null && organization.isManaged(delegate) && !organization.isEnabled()) ||
(!organizationProvider.isEnabled() && organization != null && organization.isManaged(delegate))) {
if (isOrganizationDisabled(session, delegate)) {
return new ReadOnlyUserModelDelegate(delegate) {
@Override
public boolean isEnabled() {
Expand Down Expand Up @@ -981,4 +976,13 @@ public List<AttributeMetadata> decorateUserProfile(String providerId, UserProfil
}
return List.of();
}

private boolean isOrganizationDisabled(KeycloakSession session, UserModel delegate) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have this method in utils/Organizations a remove it from here and UserStorageManager?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can but it would require moving that class to another package and increase the change set. Can you please open an issue so we can work as a follow-up, if you think it makes sense?

// check if provider is enabled and user is managed member of a disabled organization OR provider is disabled and user is managed member
OrganizationProvider organizationProvider = session.getProvider(OrganizationProvider.class);

return organizationProvider.getByMember(delegate)
.anyMatch((org) -> (organizationProvider.isEnabled() && org.isManaged(delegate) && !org.isEnabled()) ||
(!organizationProvider.isEnabled() && org.isManaged(delegate)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2024 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.
*/

package org.keycloak.models.cache.infinispan.organization;

import org.keycloak.models.RealmModel;
import org.keycloak.models.cache.infinispan.entities.AbstractRevisioned;
import org.keycloak.models.cache.infinispan.entities.InRealm;

public class CachedMembership extends AbstractRevisioned implements InRealm {

private final RealmModel realm;
private final boolean managed;
private final boolean isMember;

public CachedMembership(Long revision, String key, RealmModel realm, boolean managed, boolean isMember) {
super(revision, key);
this.realm = realm;
this.managed = managed;
this.isMember = isMember;
}

@Override
public String getRealm() {
return realm.getId();
}

public boolean isManaged() {
return managed;
}

public boolean isMember() {
return isMember;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2024 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.
*/

package org.keycloak.models.cache.infinispan.organization;

import java.util.HashSet;
import java.util.Set;
import java.util.stream.Stream;

import org.keycloak.models.OrganizationModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.cache.infinispan.entities.AbstractRevisioned;
import org.keycloak.models.cache.infinispan.entities.InRealm;

public class CachedOrganizationIds extends AbstractRevisioned implements InRealm {

private final RealmModel realm;
private final Set<String> orgIds = new HashSet<>();

public CachedOrganizationIds(Long revision, String id, RealmModel realm, Stream<OrganizationModel> organizations) {
super(revision, id);
this.realm = realm;
organizations.map(OrganizationModel::getId).forEach(orgIds::add);
}

@Override
public String getRealm() {
return realm.getId();
}

public Set<String> getOrgIds() {
return orgIds;
}
}
Loading