Java Code Examples for org.wso2.carbon.apimgt.impl.utils.APIUtil#isAccessTokenExpired()

The following examples show how to use org.wso2.carbon.apimgt.impl.utils.APIUtil#isAccessTokenExpired() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebsocketUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * validate access token via cache
 *
 * @param apiKey access token
 * @param cacheKey key of second level cache
 * @return APIKeyValidationInfoDTO
 */
public static APIKeyValidationInfoDTO validateCache(String apiKey, String cacheKey) {

	//Get the access token from the first level cache.
	String cachedToken = (String) getGatewayTokenCache().get(apiKey);

	//If the access token exists in the first level cache.
	if (cachedToken != null) {
		APIKeyValidationInfoDTO info =
				(APIKeyValidationInfoDTO) getGatewayKeyCache().get(cacheKey);

		if (info != null) {
			if (APIUtil.isAccessTokenExpired(info)) {
				info.setAuthorized(false);
				// in cache, if token is expired  remove cache entry.
				getGatewayKeyCache().remove(cacheKey);
				//Remove from the first level token cache as well.
				getGatewayTokenCache().remove(apiKey);
			}
			return info;
		}
	}

	return null;
}
 
Example 2
Source File: WebAppAuthenticatorImpl.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
private boolean isAccessTokenExpired (AccessTokenInfo accessTokenInfo) {
    APIKeyValidationInfoDTO infoDTO = new APIKeyValidationInfoDTO();
    infoDTO.setValidityPeriod(accessTokenInfo.getValidityPeriod());
    infoDTO.setIssuedTime(accessTokenInfo.getIssuedTime());
    return APIUtil.isAccessTokenExpired(infoDTO);
}