use of org.wso2.carbon.apimgt.impl.token.InternalAPIKeyGenerator in project carbon-apimgt by wso2.
the class APIProviderImpl method generateApiKey.
@Override
public String generateApiKey(String apiId) throws APIManagementException {
APIInfo apiInfo = apiMgtDAO.getAPIInfoByUUID(apiId);
if (apiInfo == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with ID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
}
SubscribedApiDTO subscribedApiInfo = new SubscribedApiDTO();
subscribedApiInfo.setName(apiInfo.getName());
subscribedApiInfo.setContext(apiInfo.getContext());
subscribedApiInfo.setPublisher(apiInfo.getProvider());
subscribedApiInfo.setVersion(apiInfo.getVersion());
JwtTokenInfoDTO jwtTokenInfoDTO = new JwtTokenInfoDTO();
jwtTokenInfoDTO.setEndUserName(username);
jwtTokenInfoDTO.setKeyType(APIConstants.API_KEY_TYPE_PRODUCTION);
jwtTokenInfoDTO.setSubscribedApiDTOList(Arrays.asList(subscribedApiInfo));
jwtTokenInfoDTO.setExpirationTime(60 * 1000);
ApiKeyGenerator apiKeyGenerator = new InternalAPIKeyGenerator();
return apiKeyGenerator.generateToken(jwtTokenInfoDTO);
}
Aggregations