forked from hapifhir/hapi-fhir-jpaserver-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SecurityConfiguration.java
42 lines (33 loc) · 1.28 KB
/
SecurityConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package earth.angelson.security.config;
import earth.angelson.security.AuthorizationInterceptor;
import earth.angelson.security.cache.TokenCacheService;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;
@EnableCaching
@Configuration
public class SecurityConfiguration {
@Value("${security.service.url:http:https://localhost:8081/account/info}")
private String securityServiceUrl;
@Bean
public TokenCacheService tokenCacheService() {
return new TokenCacheService(securityServiceUrl);
}
@Bean
public AuthorizationInterceptor authorizationInterceptor(TokenCacheService tokenCacheService) {
return new AuthorizationInterceptor(tokenCacheService);
}
@Bean
public CacheManager caffeineCacheManager() {
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
caffeineCacheManager
.setCaffeine(Caffeine.newBuilder()
.expireAfterWrite(15, TimeUnit.MINUTES));
return caffeineCacheManager;
}
}