From ed92a2b30c31e0e13a0246b873389484bc85df8d Mon Sep 17 00:00:00 2001 From: Charles Haynes <33608920+haynescd@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:34:20 -0500 Subject: [PATCH] Fix CacheMapUtil configurations (#10513) * Fix CacheMapUtil configurations * fix InActiveCacheMapUtil * Fix Oauth config --- .../cachemaputil/InactiveCacheMapUtil.java | 5 ++++- .../SpringManagedCacheMapUtil.java | 5 ++++- .../cachemaputil/StaticRefCacheMapUtil.java | 2 ++ .../security/config/MethodSecurityConfig.java | 1 - .../service/impl/CacheServiceImpl.java | 4 +--- ...volvedCancerStudyExtractorInterceptor.java | 19 ++++++++----------- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/cbioportal/persistence/cachemaputil/InactiveCacheMapUtil.java b/src/main/java/org/cbioportal/persistence/cachemaputil/InactiveCacheMapUtil.java index 58d8d2d1744..2ef34e3839c 100644 --- a/src/main/java/org/cbioportal/persistence/cachemaputil/InactiveCacheMapUtil.java +++ b/src/main/java/org/cbioportal/persistence/cachemaputil/InactiveCacheMapUtil.java @@ -32,14 +32,17 @@ package org.cbioportal.persistence.cachemaputil; -import java.util.Map; import org.cbioportal.model.CancerStudy; import org.cbioportal.model.MolecularProfile; import org.cbioportal.model.SampleList; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; +import java.util.Map; + @Component // This implementation of the CacheMapUtils is instantiated on portals where all uses can access any study. +@ConditionalOnProperty(name = "security.method_authorization_enabled", havingValue = "false", matchIfMissing = true) public class InactiveCacheMapUtil implements CacheMapUtil { // Since user-permission evaluation is not needed when this bean is present, throw an error when it is accessed. diff --git a/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java b/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java index 5eae44a6812..74e9fe083b5 100644 --- a/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java +++ b/src/main/java/org/cbioportal/persistence/cachemaputil/SpringManagedCacheMapUtil.java @@ -40,12 +40,15 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; import java.util.Map; -//@Component +@Component // Instantiate when user authorization is active and spring-managed implementation is needed +@ConditionalOnExpression("${security.method_authorization_enabled:false} and ${cache.cache-map-utils.spring-managed:false}") public class SpringManagedCacheMapUtil implements CacheMapUtil { private static final Logger LOG = LoggerFactory.getLogger(SpringManagedCacheMapUtil.class); diff --git a/src/main/java/org/cbioportal/persistence/cachemaputil/StaticRefCacheMapUtil.java b/src/main/java/org/cbioportal/persistence/cachemaputil/StaticRefCacheMapUtil.java index ce598fbbbd1..991ebc99f50 100644 --- a/src/main/java/org/cbioportal/persistence/cachemaputil/StaticRefCacheMapUtil.java +++ b/src/main/java/org/cbioportal/persistence/cachemaputil/StaticRefCacheMapUtil.java @@ -39,12 +39,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; import java.util.Map; @Component // Instantiate when user authorization is active and spring-managed implementation is not needed +@ConditionalOnExpression("${security.method_authorization_enabled:false} and !${cache.cache-map-utils.spring-managed:false}") public class StaticRefCacheMapUtil implements CacheMapUtil { private static final Logger LOG = LoggerFactory.getLogger(StaticRefCacheMapUtil.class); diff --git a/src/main/java/org/cbioportal/security/config/MethodSecurityConfig.java b/src/main/java/org/cbioportal/security/config/MethodSecurityConfig.java index f347bf832e9..9a6822286e7 100644 --- a/src/main/java/org/cbioportal/security/config/MethodSecurityConfig.java +++ b/src/main/java/org/cbioportal/security/config/MethodSecurityConfig.java @@ -28,7 +28,6 @@ public class MethodSecurityConfig { @Value("${always_show_study_group:}") private String alwaysShowCancerStudyGroup; - @Qualifier("staticRefCacheMapUtil") @Autowired private CacheMapUtil cacheMapUtil; diff --git a/src/main/java/org/cbioportal/service/impl/CacheServiceImpl.java b/src/main/java/org/cbioportal/service/impl/CacheServiceImpl.java index 6e0de479f55..41896b98d9b 100644 --- a/src/main/java/org/cbioportal/service/impl/CacheServiceImpl.java +++ b/src/main/java/org/cbioportal/service/impl/CacheServiceImpl.java @@ -1,6 +1,5 @@ package org.cbioportal.service.impl; -import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.cbioportal.persistence.StudyRepository; @@ -10,12 +9,12 @@ import org.cbioportal.service.CacheService; import org.cbioportal.service.exception.CacheOperationException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.cache.CacheManager; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Component public class CacheServiceImpl implements CacheService { @@ -25,7 +24,6 @@ public class CacheServiceImpl implements CacheService { @Autowired(required = false) private CacheManager cacheManager; - @Qualifier("staticRefCacheMapUtil") @Autowired private CacheMapUtil cacheMapUtil; diff --git a/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java b/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java index 7e500845fb1..794363acbad 100644 --- a/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java +++ b/src/main/java/org/cbioportal/web/util/InvolvedCancerStudyExtractorInterceptor.java @@ -33,15 +33,6 @@ package org.cbioportal.web.util; import com.fasterxml.jackson.databind.ObjectMapper; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.cbioportal.model.AlterationFilter; @@ -76,9 +67,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.web.servlet.HandlerInterceptor; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + public class InvolvedCancerStudyExtractorInterceptor implements HandlerInterceptor { @Autowired @@ -86,7 +84,6 @@ public class InvolvedCancerStudyExtractorInterceptor implements HandlerIntercept private ObjectMapper objectMapper = new ObjectMapper(); - @Qualifier("staticRefCacheMapUtil") @Autowired private CacheMapUtil cacheMapUtil;