Search in sources :

Example 1 with SubscribedApiDTO

use of org.wso2.carbon.apimgt.impl.dto.SubscribedApiDTO 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);
}
Also used : SubscribedApiDTO(org.wso2.carbon.apimgt.impl.dto.SubscribedApiDTO) InternalAPIKeyGenerator(org.wso2.carbon.apimgt.impl.token.InternalAPIKeyGenerator) JwtTokenInfoDTO(org.wso2.carbon.apimgt.impl.dto.JwtTokenInfoDTO) PublisherAPIInfo(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo) APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) ApiKeyGenerator(org.wso2.carbon.apimgt.impl.token.ApiKeyGenerator) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Example 2 with SubscribedApiDTO

use of org.wso2.carbon.apimgt.impl.dto.SubscribedApiDTO in project carbon-apimgt by wso2.

the class APIUtil method getJwtTokenInfoDTO.

public static JwtTokenInfoDTO getJwtTokenInfoDTO(Application application, String userName, String tenantDomain) throws APIManagementException {
    int applicationId = application.getId();
    String appOwner = application.getOwner();
    APISubscriptionInfoDTO[] apis = ApiMgtDAO.getInstance().getSubscribedAPIsForAnApp(appOwner, applicationId);
    JwtTokenInfoDTO jwtTokenInfoDTO = new JwtTokenInfoDTO();
    jwtTokenInfoDTO.setSubscriber("sub");
    jwtTokenInfoDTO.setEndUserName(userName);
    jwtTokenInfoDTO.setContentAware(true);
    Set<String> subscriptionTiers = new HashSet<>();
    List<SubscribedApiDTO> subscribedApiDTOList = new ArrayList<SubscribedApiDTO>();
    for (APISubscriptionInfoDTO api : apis) {
        subscriptionTiers.add(api.getSubscriptionTier());
        SubscribedApiDTO subscribedApiDTO = new SubscribedApiDTO();
        subscribedApiDTO.setName(api.getApiName());
        subscribedApiDTO.setContext(api.getContext());
        subscribedApiDTO.setVersion(api.getVersion());
        subscribedApiDTO.setPublisher(APIUtil.replaceEmailDomainBack(api.getProviderId()));
        subscribedApiDTO.setSubscriptionTier(api.getSubscriptionTier());
        subscribedApiDTO.setSubscriberTenantDomain(tenantDomain);
        subscribedApiDTOList.add(subscribedApiDTO);
    }
    jwtTokenInfoDTO.setSubscribedApiDTOList(subscribedApiDTOList);
    if (subscriptionTiers.size() > 0) {
        SubscriptionPolicy[] subscriptionPolicies = ApiMgtDAO.getInstance().getSubscriptionPolicies(subscriptionTiers.toArray(new String[0]), APIUtil.getTenantId(appOwner));
        Map<String, SubscriptionPolicyDTO> subscriptionPolicyDTOList = new HashMap<>();
        for (SubscriptionPolicy subscriptionPolicy : subscriptionPolicies) {
            SubscriptionPolicyDTO subscriptionPolicyDTO = new SubscriptionPolicyDTO();
            subscriptionPolicyDTO.setSpikeArrestLimit(subscriptionPolicy.getRateLimitCount());
            subscriptionPolicyDTO.setSpikeArrestUnit(subscriptionPolicy.getRateLimitTimeUnit());
            subscriptionPolicyDTO.setStopOnQuotaReach(subscriptionPolicy.isStopOnQuotaReach());
            subscriptionPolicyDTO.setTierQuotaType(subscriptionPolicy.getTierQuotaType());
            subscriptionPolicyDTO.setGraphQLMaxDepth(subscriptionPolicy.getGraphQLMaxDepth());
            subscriptionPolicyDTO.setGraphQLMaxComplexity(subscriptionPolicy.getGraphQLMaxComplexity());
            subscriptionPolicyDTOList.put(subscriptionPolicy.getPolicyName(), subscriptionPolicyDTO);
        }
        jwtTokenInfoDTO.setSubscriptionPolicyDTOList(subscriptionPolicyDTOList);
    }
    return jwtTokenInfoDTO;
}
Also used : SubscribedApiDTO(org.wso2.carbon.apimgt.impl.dto.SubscribedApiDTO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) JwtTokenInfoDTO(org.wso2.carbon.apimgt.impl.dto.JwtTokenInfoDTO) ArrayList(java.util.ArrayList) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint) SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy) APISubscriptionInfoDTO(org.wso2.carbon.apimgt.impl.dto.APISubscriptionInfoDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SubscriptionPolicyDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionPolicyDTO)

Aggregations

JwtTokenInfoDTO (org.wso2.carbon.apimgt.impl.dto.JwtTokenInfoDTO)2 SubscribedApiDTO (org.wso2.carbon.apimgt.impl.dto.SubscribedApiDTO)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)1 APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)1 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)1 APISubscriptionInfoDTO (org.wso2.carbon.apimgt.impl.dto.APISubscriptionInfoDTO)1 SubscriptionPolicyDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionPolicyDTO)1 ApiKeyGenerator (org.wso2.carbon.apimgt.impl.token.ApiKeyGenerator)1 InternalAPIKeyGenerator (org.wso2.carbon.apimgt.impl.token.InternalAPIKeyGenerator)1 PublisherAPIInfo (org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo)1 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)1