Search in sources :

Example 51 with Subscriber

use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.

the class GatewayJMSMessageListener method handleAsyncWebhooksUnSubscriptionMessage.

private synchronized void handleAsyncWebhooksUnSubscriptionMessage(JsonNode payloadData) {
    if (log.isDebugEnabled()) {
        log.debug("Received event for -  Async Webhooks API unsubscription for : " + payloadData.get(APIConstants.Webhooks.API_UUID).asText());
    }
    String apiKey = payloadData.get(APIConstants.Webhooks.API_UUID).textValue();
    String tenantDomain = payloadData.get(APIConstants.Webhooks.TENANT_DOMAIN).textValue();
    String topicName = payloadData.get(APIConstants.Webhooks.TOPIC).textValue();
    WebhooksDTO subscriber = new WebhooksDTO();
    subscriber.setCallbackURL(payloadData.get(APIConstants.Webhooks.CALLBACK).textValue());
    subscriber.setAppID(payloadData.get(APIConstants.Webhooks.APP_ID).textValue());
    subscriber.setSecret(payloadData.get(APIConstants.Webhooks.SECRET).textValue());
    ServiceReferenceHolder.getInstance().getSubscriptionsDataService().removeSubscription(apiKey, topicName, tenantDomain, subscriber);
}
Also used : WebhooksDTO(org.wso2.carbon.apimgt.impl.dto.WebhooksDTO)

Example 52 with Subscriber

use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.

the class GatewayJMSMessageListener method handleAsyncWebhooksSubscriptionMessage.

private synchronized void handleAsyncWebhooksSubscriptionMessage(JsonNode payloadData) {
    if (log.isDebugEnabled()) {
        log.debug("Received event for -  Async Webhooks API subscription for : " + payloadData.get(APIConstants.Webhooks.API_UUID).asText());
    }
    String apiUUID = payloadData.get(APIConstants.Webhooks.API_UUID).textValue();
    String appID = payloadData.get(APIConstants.Webhooks.APP_ID).textValue();
    String tenantDomain = payloadData.get(APIConstants.Webhooks.TENANT_DOMAIN).textValue();
    boolean isThrottled = payloadData.get(APIConstants.Webhooks.IS_THROTTLED).asBoolean();
    ServiceReferenceHolder.getInstance().getSubscriptionsDataService().updateThrottleStatus(appID, apiUUID, tenantDomain, isThrottled);
    if (!isThrottled) {
        String topicName = payloadData.get(APIConstants.Webhooks.TOPIC).textValue();
        WebhooksDTO subscriber = new WebhooksDTO();
        subscriber.setApiUUID(apiUUID);
        subscriber.setApiContext(payloadData.get(APIConstants.Webhooks.API_CONTEXT).textValue());
        subscriber.setApiName(payloadData.get(APIConstants.Webhooks.API_NAME).textValue());
        subscriber.setApiVersion(payloadData.get(APIConstants.Webhooks.API_VERSION).textValue());
        subscriber.setAppID(appID);
        subscriber.setCallbackURL(payloadData.get(APIConstants.Webhooks.CALLBACK).textValue());
        subscriber.setTenantDomain(tenantDomain);
        subscriber.setTenantId(payloadData.get(APIConstants.Webhooks.TENANT_ID).intValue());
        subscriber.setSecret(payloadData.get(APIConstants.Webhooks.SECRET).textValue());
        subscriber.setExpiryTime(payloadData.get(APIConstants.Webhooks.EXPIRY_AT).asLong());
        subscriber.setTopicName(topicName);
        subscriber.setApiTier(payloadData.get(APIConstants.Webhooks.API_TIER).textValue());
        subscriber.setApplicationTier(payloadData.get(APIConstants.Webhooks.APPLICATION_TIER).textValue());
        subscriber.setTier(payloadData.get(APIConstants.Webhooks.TIER).textValue());
        subscriber.setSubscriberName(payloadData.get(APIConstants.Webhooks.SUBSCRIBER_NAME).textValue());
        ServiceReferenceHolder.getInstance().getSubscriptionsDataService().addSubscription(apiUUID, topicName, tenantDomain, subscriber);
    }
}
Also used : WebhooksDTO(org.wso2.carbon.apimgt.impl.dto.WebhooksDTO)

Example 53 with Subscriber

use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.

the class SubscriberInfoLoader method mediate.

// private final GenericRequestDataCollector dataCollector = null;
@Override
public boolean mediate(MessageContext messageContext) {
    List<WebhooksDTO> subscribersList = (List<WebhooksDTO>) messageContext.getProperty(APIConstants.Webhooks.SUBSCRIBERS_LIST_PROPERTY);
    int index = (Integer) messageContext.getProperty(APIConstants.CLONED_ITERATION_INDEX_PROPERTY);
    WebhooksDTO subscriber = subscribersList.get(index - 1);
    if (subscriber != null) {
        boolean canProceed = handleThrottle(subscriber, messageContext);
        if (!canProceed) {
            return false;
        }
        messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_CALLBACK_PROPERTY, subscriber.getCallbackURL());
        messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_SECRET_PROPERTY, subscriber.getSecret());
        messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_APPLICATION_ID_PROPERTY, subscriber.getAppID());
    }
    return true;
}
Also used : WebhooksDTO(org.wso2.carbon.apimgt.impl.dto.WebhooksDTO) List(java.util.List)

Example 54 with Subscriber

use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.

the class APIUtil method createSelfSignUpRoles.

/**
 * @param tenantId
 * @throws APIManagementException
 */
public static void createSelfSignUpRoles(int tenantId) throws APIManagementException {
    try {
        String selfSighupConfig = ServiceReferenceHolder.getInstance().getApimConfigService().getSelfSighupConfig(getTenantDomainFromTenantId(tenantId));
        DocumentBuilderFactory factory = getSecuredDocumentBuilder();
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        DocumentBuilder parser = factory.newDocumentBuilder();
        InputStream inputStream = new ByteArrayInputStream(selfSighupConfig.getBytes());
        Document dc = parser.parse(inputStream);
        boolean enableSubscriberRoleCreation = isSubscriberRoleCreationEnabled(tenantId);
        String signUpDomain = dc.getElementsByTagName(APIConstants.SELF_SIGN_UP_REG_DOMAIN_ELEM).item(0).getFirstChild().getNodeValue();
        if (enableSubscriberRoleCreation) {
            int roleLength = dc.getElementsByTagName(APIConstants.SELF_SIGN_UP_REG_ROLE_NAME_ELEMENT).getLength();
            for (int i = 0; i < roleLength; i++) {
                String roleName = dc.getElementsByTagName(APIConstants.SELF_SIGN_UP_REG_ROLE_NAME_ELEMENT).item(i).getFirstChild().getNodeValue();
                boolean isExternalRole = Boolean.parseBoolean(dc.getElementsByTagName(APIConstants.SELF_SIGN_UP_REG_ROLE_IS_EXTERNAL).item(i).getFirstChild().getNodeValue());
                if (roleName != null) {
                    // If isExternalRole==false ;create the subscriber role as an internal role
                    if (isExternalRole && signUpDomain != null) {
                        roleName = signUpDomain.toUpperCase() + CarbonConstants.DOMAIN_SEPARATOR + roleName;
                    } else {
                        roleName = UserCoreConstants.INTERNAL_DOMAIN + CarbonConstants.DOMAIN_SEPARATOR + roleName;
                    }
                    createSubscriberRole(roleName, tenantId);
                }
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Adding Self signup configuration to the tenant's registry");
        }
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new APIManagementException("Error while getting Self signup role information from the registry", e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) SolrDocument(org.apache.solr.common.SolrDocument) Endpoint(org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint) SAXException(org.xml.sax.SAXException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 55 with Subscriber

use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.

the class ImportUtils method validateOwner.

/**
 * Check whether a provided userId corresponds to a valid consumer of the store and subscribe if valid
 *
 * @param userId      Username of the Owner
 * @param groupId     The groupId to which the target subscriber belongs to
 * @param apiConsumer API Consumer
 * @throws APIManagementException if an error occurs while checking the validity of user
 */
public static void validateOwner(String userId, String groupId, APIConsumer apiConsumer) throws APIManagementException {
    Subscriber subscriber = apiConsumer.getSubscriber(userId);
    try {
        if (subscriber == null && !APIUtil.isPermissionCheckDisabled()) {
            APIUtil.checkPermission(userId, APIConstants.Permissions.API_SUBSCRIBE);
            apiConsumer.addSubscriber(userId, groupId);
        }
    } catch (APIManagementException e) {
        throw new APIManagementException("Provided Application Owner is Invalid", e);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber)

Aggregations

Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)98 Test (org.junit.Test)64 Application (org.wso2.carbon.apimgt.api.model.Application)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)60 PreparedStatement (java.sql.PreparedStatement)39 SQLException (java.sql.SQLException)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)39 ResultSet (java.sql.ResultSet)37 Connection (java.sql.Connection)31 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)28 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)25 Tier (org.wso2.carbon.apimgt.api.model.Tier)20 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)19 Date (java.util.Date)14 HashMap (java.util.HashMap)11 LinkedHashSet (java.util.LinkedHashSet)10 JSONObject (org.json.simple.JSONObject)10 OAuthApplicationInfo (org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo)10 TreeMap (java.util.TreeMap)9