本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}