• 本地缓存


    一些间的使用

    @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);
         }
    
  • 相关阅读:
    Win32程序支持命令行参数的做法
    打包jar类库与使用jar类库
    Java日期格式化
    集合类层次结构关系
    深入理解Arrays.sort()
    Java 异常类层次结构
    equals()与hashCode()方法协作约定
    shp数据和tab数据的两点区别
    java+上传文件夹
    vue+大文件分片上传
  • 原文地址:https://www.cnblogs.com/liuyupen/p/11131808.html
Copyright © 2020-2023  润新知