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);
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations