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


Java OAuth2AccessToken.getRefreshToken方法代码示例

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


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

示例1: 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

示例2: fetch

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
public static EAccessToken fetch(OAuth2Authentication oAuth2Authentication, OAuth2AccessToken accessToken){
	EAccessToken eAccessToken = new EAccessToken();
	eAccessToken.setOpenUser(fetch(oAuth2Authentication));

	Object details = oAuth2Authentication.getDetails();
	if(details instanceof OAuth2AuthenticationDetails){
		OAuth2AuthenticationDetails details1 = (OAuth2AuthenticationDetails) details;
		eAccessToken.setRemoteAddress(details1.getRemoteAddress());
		eAccessToken.setSessionId(details1.getSessionId());
	}
	eAccessToken.setTokenType(accessToken.getTokenType());
	eAccessToken.setTokenValue(accessToken.getValue());
	eAccessToken.setExpiresIn(accessToken.getExpiresIn());
	if (accessToken.getRefreshToken() != null) {
		eAccessToken.setRefreshToken(accessToken.getRefreshToken().getValue());
	}
	if (accessToken.getScope() != null) {
		String scopes = Strings.join2("|", accessToken.getScope().toArray(new String[]{}));
		eAccessToken.setScopes(scopes);
	}
	return eAccessToken;
}
 
开发者ID:DataAgg,项目名称:DAFramework,代码行数:23,代码来源:OAuth2Util.java

示例3: storeAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
	String refreshToken = null;
	if (token.getRefreshToken() != null) {
		refreshToken = token.getRefreshToken().getValue();
	}
	
	if (readAccessToken(token.getValue())!=null) {
		removeAccessToken(token.getValue());
	}
	
	String bid = getAuthorizationDetail(authentication).get("bid");
	String pid = getAuthorizationDetail(authentication).get("pid");
	
	jdbcTemplate.update(insertAccessTokenSql, new Object[] { extractTokenKey(token.getValue()),
			new SqlLobValue(serializeAccessToken(token)), authenticationKeyGenerator.extractKey(authentication),
			authentication.isClientOnly() ? null : authentication.getName(),
			authentication.getOAuth2Request().getClientId(),
			new SqlLobValue(serializeAuthentication(authentication)), extractTokenKey(refreshToken),bid,pid}, new int[] {
			Types.VARCHAR, Types.BLOB, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.BLOB, Types.VARCHAR,Types.VARCHAR,Types.VARCHAR });
}
 
开发者ID:xienjiang,项目名称:session-cloud,代码行数:21,代码来源:CustomTokenStore.java

示例4: revokeToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Override
public boolean revokeToken(String tokenValue) {
    OAuth2AccessToken accessToken = tokenStore.readAccessToken(tokenValue);
    if (accessToken == null) {
        return false;
    }
    if (accessToken.getRefreshToken() != null) {
        tokenStore.removeRefreshToken(accessToken.getRefreshToken());
    }
    tokenStore.removeAccessToken(accessToken);
    return true;
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:13,代码来源:DomainTokenServices.java

示例5: getToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
/**
 * Chooses a token among all tokens for this user in the token store.
 * 
 * @param tokenStore the token store to search in
 * @param userName the username
 * @return the chosen token, or null if no token was found
 */
public OAuth2AccessToken getToken(String userName) {
    OAuth2AccessToken token = null;
    Collection<OAuth2AccessToken> tokens = tokenStore.findTokensByUserName(userName);
    for (OAuth2AccessToken tokenx : tokens) {
        // If a token is already found, overwrite it if the new token:
        // 1) has a refresh token, and the current token hasn't, or
        // 2) expires later than the current token
        if (token == null || ((tokenx.getRefreshToken() != null) && (token.getRefreshToken() == null))
            || (tokenx.getExpiresIn() > token.getExpiresIn())) {
            token = tokenx;
        }
    }
    return token;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:22,代码来源:TokenService.java

示例6: storeAccessToken

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
@Override
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {

    String tokenId = token.getValue();

    final RefreshTokenEntity refreshToken;
    String authenticationKey = authenticationKeyGenerator.extractKey(authentication);

    if (token.getRefreshToken() != null) {
        refreshToken = refreshTokenRepository.findOneByTokenId(token.getRefreshToken().getValue()).orElseGet(() -> refreshTokenRepository.save(RefreshTokenEntity.builder().tokenId(token.getRefreshToken().getValue()).token(token.getRefreshToken()).authentication(authentication).build()));
    } else {
        refreshToken = null;
    }

    accessTokenRepository.findOneByAuthenticationId(authenticationKey).ifPresent(accessTokenEntity -> {
        if (!tokenId.equals(accessTokenEntity.getTokenId())) {
            accessTokenRepository.delete(accessTokenEntity);
        }
    });

    AccessTokenEntity entityToSave = accessTokenRepository.findOneByTokenId(tokenId).map(accessTokenEntity -> {
        accessTokenEntity.setToken(token);
        accessTokenEntity.setAuthenticationId(authenticationKey);
        accessTokenEntity.setAuthentication(authentication);
        accessTokenEntity.setUserName(authentication.isClientOnly() ? null : authentication.getName());
        accessTokenEntity.setClientId(authentication.getOAuth2Request().getClientId());
        accessTokenEntity.setRefreshToken(refreshToken);
        return accessTokenEntity;
    }).orElseGet(() -> AccessTokenEntity.builder().tokenId(tokenId).token(token).authenticationId(authenticationKey).authentication(authentication).userName(authentication.isClientOnly() ? null : authentication.getName()).clientId(authentication.getOAuth2Request().getClientId()).refreshToken(refreshToken).build());

    accessTokenRepository.save(entityToSave);
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:33,代码来源:DatabaseTokenStoreService.java

示例7: 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

示例8: 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

示例9: createCredentials

import org.springframework.security.oauth2.common.OAuth2AccessToken; //导入方法依赖的package包/类
private static CloudCredentials createCredentials(OAuth2AccessToken token) {
    boolean refreshable = (token.getRefreshToken() != null);
    return new CloudCredentials(token, refreshable);
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:5,代码来源:ClientFactory.java


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