zoukankan      html  css  js  c++  java
  • 本地缓存

    一些间的使用

    @Bean
        public LoadingCache<String, OAuth2Authentication> authenticationLoadingCache() {
            return CacheBuilder.newBuilder().maximumSize(1000L).expireAfterWrite((long)this.oAuth2ClientProperties.getExpireAfterWrite().intValue(), TimeUnit.SECONDS).refreshAfterWrite((long)this.oAuth2ClientProperties.getRefreshAfterWrite().intValue(), TimeUnit.SECONDS).build(new CacheLoader<String, OAuth2Authentication>() {
                public OAuth2Authentication load(String jwtToken) throws Exception {
                    ResponseMessage<OAuth2Authentication> responseMessage = OAuth2ClientAutoConfiguration.this.oAuth2ResourceService.getLoginUserByJwt(OAuth2ClientAutoConfiguration.this.oAuth2UtilService.buildJwtQueryParam(jwtToken));
                    if (!responseMessage.is2xxSuccessful()) {
                        return null;
                    } else {
                        OAuth2Authentication oAuth2Authentication = (OAuth2Authentication)responseMessage.getResult(OAuth2Authentication.class);
                        return oAuth2Authentication;
                    }
                }
            });
        }
    
    
        @Autowired
        LoadingCache<String, OAuth2Authentication> authenticationLoadingCache;
    
        if (this.authenticationLoadingCache.getIfPresent(authToken) == null) {
                            ResponseMessage<Object> claims = this.oAuth2AccessTokenService.checkToken(authToken);
                            if ("-1".equals(claims.getCode())) {
                                throw new CommonException(401, claims.getMessage());
                            }
         }
    
        if (SecurityContextHolder.getContext().getAuthentication() == null || !SecurityContextHolder.getContext().getAuthentication().getCredentials().equals(username)) {
                            OAuth2Authentication oAuth2Authentication = (OAuth2Authentication)this.authenticationLoadingCache.getUnchecked(authToken);
                            AuthUserDetails principal = new AuthUserDetails(oAuth2Authentication);
                            PreAuthenticatedAuthenticationToken auth = new PreAuthenticatedAuthenticationToken(principal, authToken, principal.getAuthorities());
                            SecurityContextHolder.getContext().setAuthentication(auth);
         }
    
  • 相关阅读:
    如何用ASP.NET加密Cookie数据过程分析
    PHP监控linux服务器负载情况分析解决方案
    我发现了博客的一个小问题
    人生总是有太多的失望
    小公司根据实据情况部署实施Linux集群网站
    刚刚收到光棍短信祝福了!
    我对你的期望有点过了
    PHP在接下来的几年内将是主主流的
    不付出一定不会有收获!
    关于创建RootDesigner的文章
  • 原文地址:https://www.cnblogs.com/liuyupen/p/11131808.html
Copyright © 2011-2022 走看看