当前位置: 首页>>代码示例>>Java>>正文


Java OAuth2AccessToken.isExpired方法代码示例

本文整理汇总了Java中org.springframework.security.oauth2.common.OAuth2AccessToken.isExpired方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth2AccessToken.isExpired方法的具体用法?Java OAuth2AccessToken.isExpired怎么用?Java OAuth2AccessToken.isExpired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.oauth2.common.OAuth2AccessToken的用法示例。


在下文中一共展示了OAuth2AccessToken.isExpired方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadAuthentication

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Override
public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException,
    InvalidTokenException {
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(accessTokenValue);
    if (accessToken == null) {
        throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
    } else if (accessToken.isExpired()) {
        tokenStore.removeAccessToken(accessToken);
        throw new InvalidTokenException("Access token expired: " + accessTokenValue.substring(0,200));
    }

    OAuth2Authentication result = tokenStore.readAuthentication(accessToken);
    if (result == null) {
        // in case of race condition
        throw new InvalidTokenException("Invalid access token: " + accessTokenValue);
    }

    return result;
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:20,代码来源:DomainTokenServices.java

示例2: getAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
public OAuth2AccessToken getAccessToken() throws UserRedirectRequiredException {
    OAuth2AccessToken accessToken = this.context.getAccessToken();
    if(accessToken == null || accessToken.isExpired()) {
        try {
            accessToken = this.acquireAccessToken(this.context);
        } catch (UserRedirectRequiredException var5) {
            this.context.setAccessToken((OAuth2AccessToken)null);
            accessToken = null;
            String stateKey = var5.getStateKey();
            if(stateKey != null) {
                Object stateToPreserve = var5.getStateToPreserve();
                if(stateToPreserve == null) {
                    stateToPreserve = "NONE";
                }

                this.context.setPreservedState(stateKey, stateToPreserve);
            }

            throw var5;
        }
    }

    return accessToken;
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:25,代码来源:MyOAuth2RestTemplate.java

示例3: getValidToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
private OAuth2AccessToken getValidToken(String userName, String org, String space) throws SLException {
    OAuth2AccessToken token = tokenService.getToken(userName);
    if (token == null) {
        throw new SLException(Messages.NO_VALID_TOKEN_FOUND, userName);
    }

    if (token.isExpired() && token.getRefreshToken() == null) {
        tokenService.removeToken(token);
        if (org != null && space != null) {
            releaseClientFromCache(token, org, space);
        }
        throw new SLException(Messages.TOKEN_EXPIRED, userName);
    }

    return token;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:17,代码来源:CloudFoundryClientProvider.java

示例4: removeExpiredTokens

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
private void removeExpiredTokens() {
    Collection<OAuth2AccessToken> allTokens = tokenStore.findTokensByClientId(SecurityUtil.CLIENT_ID);
    if (CollectionUtils.isEmpty(allTokens)) {
        return;
    }
    LOGGER.info("Removing expired tokens");
    int removedTokens = 0;
    for (OAuth2AccessToken token : allTokens) {
        if (token.isExpired()) {
            tokenStore.removeAccessToken(token);
            removedTokens++;
        }
    }
    LOGGER.info("Removed expired tokens count: " + removedTokens);
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:16,代码来源:CleanUpJob.java

示例5: createAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Override
public OAuth2AccessToken createAccessToken(OAuth2Authentication authentication) {
    setCustomDetails(authentication);
    OAuth2AccessToken existingAccessToken = tokenStore.getAccessToken(authentication);
    OAuth2RefreshToken refreshToken = null;
    if (existingAccessToken != null) {
        if (existingAccessToken.isExpired()) {
            if (existingAccessToken.getRefreshToken() != null) {
                refreshToken = existingAccessToken.getRefreshToken();
                // The token store could remove the refresh token when the
                // access token is removed, but we want to
                // be sure...
                tokenStore.removeRefreshToken(refreshToken);
            }
            tokenStore.removeAccessToken(existingAccessToken);
        } else {
            // Re-store the access token in case the authentication has changed
            tokenStore.storeAccessToken(existingAccessToken, authentication);
            return existingAccessToken;
        }
    }

    // Only create a new refresh token if there wasn't an existing one
    // associated with an expired access token.
    // Clients might be holding existing refresh tokens, so we re-use it in
    // the case that the old access token
    // expired.
    if (refreshToken == null) {
        refreshToken = createRefreshToken(authentication);
    } else if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
        ExpiringOAuth2RefreshToken expiring = (ExpiringOAuth2RefreshToken) refreshToken;
        if (System.currentTimeMillis() > expiring.getExpiration().getTime()) {
            refreshToken = createRefreshToken(authentication);
        }
    }

    OAuth2AccessToken accessToken = createAccessToken(authentication, refreshToken);
    tokenStore.storeAccessToken(accessToken, authentication);
    // In case it was modified
    refreshToken = accessToken.getRefreshToken();
    if (refreshToken != null) {
        tokenStore.storeRefreshToken(refreshToken, authentication);
    }
    return accessToken;

}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:47,代码来源:DomainTokenServices.java

示例6: obtainAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails resource, AccessTokenRequest request) throws UserRedirectRequiredException, AccessDeniedException {
    OAuth2AccessToken accessToken = null;
    OAuth2AccessToken existingToken = null;
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if(auth instanceof AnonymousAuthenticationToken && !resource.isClientOnly()) {
        throw new InsufficientAuthenticationException("Authentication is required to obtain an access token (anonymous not allowed)");
    } else {
        if(resource.isClientOnly() || auth != null && auth.isAuthenticated()) {
            existingToken = request.getExistingToken();
            if(existingToken == null && this.clientTokenServices != null) {
                existingToken = this.clientTokenServices.getAccessToken(resource, auth);
            }

            if(existingToken != null) {
                if(existingToken.isExpired()) {
                    if(this.clientTokenServices != null) {
                        this.clientTokenServices.removeAccessToken(resource, auth);
                    }

                    OAuth2RefreshToken refreshToken = existingToken.getRefreshToken();
                    if(refreshToken != null) {
                        accessToken = this.refreshAccessToken(resource, refreshToken, request);
                    }
                } else {
                    accessToken = existingToken;
                }
            }
        }

        if(accessToken == null) {
            accessToken = this.obtainNewAccessTokenInternal(resource, request);
            if(accessToken == null) {
                System.out.println("An OAuth 2 access token must be obtained or an exception thrown.");
                throw new IllegalStateException("An OAuth 2 access token must be obtained or an exception thrown.");
            }
        }

        if(this.clientTokenServices != null && (resource.isClientOnly() || auth != null && auth.isAuthenticated())) {
            this.clientTokenServices.saveAccessToken(resource, auth, accessToken);
        }

        return accessToken;
    }
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:45,代码来源:MyAccessTokenProviderChain.java


注:本文中的org.springframework.security.oauth2.common.OAuth2AccessToken.isExpired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。