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 @@ -172,6 +172,29 @@ public GroupProvider getGroupDelegate() {
return groupDelegate;
}

public Set<String> getInvalidations() {
return Collections.unmodifiableSet(invalidations);
}

public RealmCacheManager getCache() {
return cache;
}

public long getStartupRevision() {
return startupRevision;
}

@Override
public void registerInvalidation(String id) {
invalidations.add(id);
invalidationEvents.add(new InvalidationEvent() {
@Override
public String getId() {
return id;
}
});
}

@Override
public void registerRealmInvalidation(String id, String name) {
cache.realmUpdated(id, name, invalidations);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.models.IdentityProviderModel;
import org.keycloak.models.OrganizationDomainModel;
import org.keycloak.models.OrganizationModel;
import org.keycloak.models.RealmModel;
import org.keycloak.models.cache.infinispan.DefaultLazyLoader;
import org.keycloak.models.cache.infinispan.LazyLoader;
import org.keycloak.models.cache.infinispan.entities.AbstractRevisioned;
import org.keycloak.models.cache.infinispan.entities.InRealm;

public class CachedOrganization extends AbstractRevisioned implements InRealm {

private final RealmModel realm;
private final String name;
private final String description;
private final boolean enabled;
private final LazyLoader<OrganizationModel, MultivaluedHashMap<String, String>> attributes;
private final Set<OrganizationDomainModel> domains;
private final Set<IdentityProviderModel> idps;

public CachedOrganization(Long revision, RealmModel realm, OrganizationModel organization) {
super(revision, organization.getId());
this.realm = realm;
this.name = organization.getName();
this.description = organization.getDescription();
this.enabled = organization.isEnabled();
this.attributes = new DefaultLazyLoader<>(orgModel -> new MultivaluedHashMap<>(orgModel.getAttributes()), MultivaluedHashMap::new);
this.domains = organization.getDomains().collect(Collectors.toSet());
this.idps = organization.getIdentityProviders().collect(Collectors.toSet());
}

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

public RealmModel getRealmModel() {
return realm;
}

public String getName() {
return name;
}

public String getDescription() {
return description;
}

public boolean isEnabled() {
return enabled;
}

public MultivaluedHashMap<String, String> getAttributes(Supplier<OrganizationModel> organizationModel) {
return attributes.get(organizationModel);
}

public Stream<OrganizationDomainModel> getDomains() {
return domains.stream();
}

public Stream<IdentityProviderModel> getIdentityProviders() {
return idps.stream();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 CachedOrganizationCount extends AbstractRevisioned implements InRealm {

private final RealmModel realm;
private final long count;

public CachedOrganizationCount(Long revision, RealmModel realm, long count) {
super(revision, InfinispanOrganizationProvider.cacheKeyOrgCount(realm));
this.realm = realm;
this.count = count;
}

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

public long getCount() {
return count;
}
}
Loading