Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
implement cache for user authorization data
Browse files Browse the repository at this point in the history
  • Loading branch information
mofobo-bit committed Mar 30, 2022
1 parent fca3682 commit c170332
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import ch.admin.bag.covidcertificate.gateway.service.dto.CreateCertificateException;
import ch.admin.bag.covidcertificate.gateway.service.model.UserAuthorizationData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.StringUtils;

import java.util.Collection;
Expand All @@ -23,8 +26,11 @@
@Slf4j
public abstract class AbstractIdentityAuthorizationClient implements IdentityAuthorizationClient {

private static final String USER_AUTHORIZATION_DATA_CACHE = "USER_AUTHORIZATION_DATA_CACHE";

protected abstract User searchUser(String uuid, String idpSource);

@Cacheable(USER_AUTHORIZATION_DATA_CACHE)
@Override
public UserAuthorizationData fetchUserAndGetAuthData(String uuid, String idpSource) {
if (!StringUtils.hasText(uuid) || !StringUtils.hasText(idpSource)) {
Expand Down Expand Up @@ -53,4 +59,10 @@ public UserAuthorizationData fetchUserAndGetAuthData(String uuid, String idpSour
log.trace("Authorization checked successfully.");
return new UserAuthorizationData(uuid, idpSource, roles);
}

@Scheduled(fixedRateString = "${cc-api-gateway-service.cache-duration}")
@CacheEvict(value = USER_AUTHORIZATION_DATA_CACHE, allEntries = true)
public void cleanUserAuthorizationDataCache() {
log.info("Cleaning cache of user autorization data.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ch.admin.bag.covidcertificate.gateway.web.config.ProfileRegistry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public List<OtpRevocation> getOtpRevocations() {
@Scheduled(fixedRateString = "${cc-api-gateway-service.cache-duration}")
@CacheEvict(value = OTP_CACHE_NAME, allEntries = true)
public void clearCache() {
log.info("Cleaning cache of otps list.");
}

}

0 comments on commit c170332

Please sign in to comment.