Skip to content

Commit

Permalink
keycloak changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry0589 committed Oct 29, 2024
1 parent cbebe59 commit 4f98797
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 161 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.github.bcgov.keycloak.mapper;


import com.github.bcgov.keycloak.common.utils.ExpiringConcurrentHashMap;
import com.github.bcgov.keycloak.common.utils.ExpiringConcurrentHashMapListener;
import com.github.bcgov.keycloak.exception.SoamRuntimeException;
import com.github.bcgov.keycloak.model.SoamLoginEntity;
import com.github.bcgov.keycloak.model.SoamServicesCard;
import com.github.bcgov.keycloak.model.SoamStudent;
import com.github.bcgov.keycloak.rest.SoamRestUtils;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.jboss.logging.Logger;
import org.keycloak.models.ProtocolMapperModel;
import org.keycloak.models.UserSessionModel;
Expand All @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
* SOAM Protocol Mapper Will be used to set Education specific claims for our
Expand All @@ -38,22 +39,9 @@ public class SoamProtocolMapper extends AbstractOIDCProtocolMapper
// OIDCAttributeMapperHelper.addTokenClaimNameConfig(configProperties);
OIDCAttributeMapperHelper.addIncludeInTokensConfig(configProperties, SoamProtocolMapper.class);
}

//Create hashmap with 30 second expiry.
private ExpiringConcurrentHashMap<String, SoamLoginEntity> loginDetailCache = new ExpiringConcurrentHashMap<>(30000, new ExpiringConcurrentHashMapListener<String, SoamLoginEntity>() {

@Override
public void notifyOnAdd(String key, SoamLoginEntity value) {
logger.debug("Adding SoamLoginEntity to SOAM cache, key: " + key);
}

@Override
public void notifyOnRemoval(String key, SoamLoginEntity value) {
logger.debug("Removing SoamLoginEntity from SOAM cache, key: " + key);
logger.debug("Current cache size on this node: " + loginDetailCache.size());
}
});

private Cache<String, SoamLoginEntity> loginDetailCache = CacheBuilder.newBuilder()
.expireAfterWrite(30, TimeUnit.SECONDS)
.build();
public static final String PROVIDER_ID = "oidc-soam-mapper";

public List<ProviderConfigProperty> getConfigProperties() {
Expand All @@ -77,8 +65,8 @@ public String getHelpText() {
}

private SoamLoginEntity fetchSoamLoginEntity(String type, String userGUID) {
if (loginDetailCache.containsKey(userGUID)) {
return loginDetailCache.get(userGUID);
if (null != loginDetailCache.getIfPresent(userGUID)) {
return loginDetailCache.getIfPresent(userGUID);
}
logger.debug("SOAM Fetching " + type + " Claims for UserGUID: " + userGUID);
SoamLoginEntity soamLoginEntity = soamRestUtils.getSoamLoginEntity(type, userGUID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.bcgov.keycloak.tenant.mapper;


import com.github.bcgov.keycloak.common.utils.ExpiringConcurrentHashMap;
import com.github.bcgov.keycloak.common.utils.ExpiringConcurrentHashMapListener;
import com.github.bcgov.keycloak.tenant.model.TenantAccess;
import com.github.bcgov.keycloak.tenant.rest.TenantRestUtils;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.jboss.logging.Logger;
import org.keycloak.models.ClientSessionContext;
import org.keycloak.models.KeycloakSession;
Expand All @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
* Tenant Protocol Mapper Will be used to set Tenant valid attribute
Expand All @@ -38,7 +39,7 @@ public class TenantProtocolMapper extends AbstractOIDCProtocolMapper
}

//Create hashmap with 30 second expiry.
private ExpiringConcurrentHashMap<String, TenantAccess> loginDetailCache = new ExpiringConcurrentHashMap<>(30000, new ExpiringConcurrentHashMapListener<String, TenantAccess>() {
/* private ExpiringConcurrentHashMap<String, TenantAccess> loginDetailCache = new ExpiringConcurrentHashMap<>(30000, new ExpiringConcurrentHashMapListener<String, TenantAccess>() {
@Override
public void notifyOnAdd(String key, TenantAccess value) {
Expand All @@ -50,8 +51,10 @@ public void notifyOnRemoval(String key, TenantAccess value) {
logger.debug("Removing TenantAccessEntity from Tenant cache, key: " + key);
logger.debug("Current cache size on this node: " + loginDetailCache.size());
}
});

});*/
private Cache<String, TenantAccess> loginDetailCache = CacheBuilder.newBuilder()
.expireAfterWrite(30, TimeUnit.SECONDS)
.build();
public static final String PROVIDER_ID = "oidc-tenant-mapper";

public List<ProviderConfigProperty> getConfigProperties() {
Expand All @@ -75,8 +78,8 @@ public String getHelpText() {
}

private TenantAccess fetchTenantAccessEntity(String clientID, String tenantID) {
if (loginDetailCache.containsKey(tenantID)) {
return loginDetailCache.get(tenantID);
if (null != loginDetailCache.getIfPresent(tenantID)) {
return loginDetailCache.getIfPresent(tenantID);
}
logger.debug("Tenant Access Fetching by Tenant ID: " + tenantID + " and Client ID: " + clientID);
TenantAccess tenantAccess = tenantRestUtils.checkForValidTenant(clientID, tenantID);
Expand Down

0 comments on commit 4f98797

Please sign in to comment.