use of org.wso2.carbon.apimgt.impl.kmclient.model.IntrospectInfo in project carbon-apimgt by wso2.
the class AMDefaultKeyManagerImpl method getTokenMetaData.
@Override
public AccessTokenInfo getTokenMetaData(String accessToken) throws APIManagementException {
AccessTokenInfo tokenInfo = new AccessTokenInfo();
try {
IntrospectInfo introspectInfo = introspectionClient.introspect(accessToken);
tokenInfo.setAccessToken(accessToken);
boolean isActive = introspectInfo.isActive();
if (!isActive) {
tokenInfo.setTokenValid(false);
tokenInfo.setErrorcode(APIConstants.KeyValidationStatus.API_AUTH_INVALID_CREDENTIALS);
return tokenInfo;
}
tokenInfo.setTokenValid(true);
if (introspectInfo.getIat() > 0 && introspectInfo.getExpiry() > 0) {
if (introspectInfo.getExpiry() != Long.MAX_VALUE) {
long validityPeriod = introspectInfo.getExpiry() - introspectInfo.getIat();
tokenInfo.setValidityPeriod(validityPeriod * 1000L);
} else {
tokenInfo.setValidityPeriod(Long.MAX_VALUE);
}
tokenInfo.setIssuedTime(introspectInfo.getIat() * 1000L);
}
if (StringUtils.isNotEmpty(introspectInfo.getScope())) {
String[] scopes = introspectInfo.getScope().split(" ");
tokenInfo.setScope(scopes);
}
tokenInfo.setConsumerKey(introspectInfo.getClientId());
String username = introspectInfo.getUsername();
if (!StringUtils.isEmpty(username)) {
tokenInfo.setEndUserName(username);
}
return tokenInfo;
} catch (KeyManagerClientException e) {
throw new APIManagementException("Error occurred in token introspection!", e);
}
}
use of org.wso2.carbon.apimgt.impl.kmclient.model.IntrospectInfo in project carbon-apimgt by wso2.
the class AMDefaultKeyManagerImplTest method testTokenUnlimitedExpirationTime.
@Test
public void testTokenUnlimitedExpirationTime() throws KeyManagerClientException, APIManagementException {
String accessToken = "155ddde3-68db-35b1-82dc-1247616b2da9";
IntrospectInfo response = new IntrospectInfo();
response.setActive(true);
response.setExpiry(Long.MAX_VALUE);
response.setIat(new Date().getTime());
Mockito.when(introspectionClient.introspect(accessToken)).thenReturn(response);
AccessTokenInfo info = keyManager.getTokenMetaData(accessToken);
Assert.assertEquals(Long.MAX_VALUE, info.getValidityPeriod());
}
Aggregations