use of org.wso2.carbon.apimgt.keymgt.model.entity.Subscription in project carbon-apimgt by wso2.
the class SubscriptionCreationApprovalWorkflowExecutor method cleanUpPendingTask.
/**
* Handle cleanup task for subscription creation Approval workflow executor.
* Use workflow external reference to delete the pending workflow request
*
* @param workflowExtRef Workflow external reference of pending workflow request
*/
@Override
public void cleanUpPendingTask(String workflowExtRef) throws WorkflowException {
String errorMsg = null;
super.cleanUpPendingTask(workflowExtRef);
if (log.isDebugEnabled()) {
log.debug("Starting cleanup task for SubscriptionCreationApprovalWorkflowExecutor for :" + workflowExtRef);
}
try {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
apiMgtDAO.deleteWorkflowRequest(workflowExtRef);
} catch (APIManagementException axisFault) {
errorMsg = "Error sending out cancel pending subscription approval process message. cause: " + axisFault.getMessage();
throw new WorkflowException(errorMsg, axisFault);
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Subscription in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutor method complete.
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
workflowDTO.setUpdatedTime(System.currentTimeMillis());
super.complete(workflowDTO);
log.info("Subscription Creation [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
} catch (APIManagementException e) {
log.error("Could not complete subscription creation workflow", e);
throw new WorkflowException("Could not complete subscription creation workflow", e);
}
} else if (WorkflowStatus.REJECTED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
} catch (APIManagementException e) {
log.error("Could not complete subscription creation workflow", e);
throw new WorkflowException("Could not complete subscription creation workflow", e);
}
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Subscription in project carbon-apimgt by wso2.
the class SubscriptionUpdateApprovalWorkflowExecutor method complete.
/**
* Complete the Approval workflow executor for Subscription creation.
*
* @param workflowDTO
*/
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
workflowDTO.setUpdatedTime(System.currentTimeMillis());
super.complete(workflowDTO);
if (log.isDebugEnabled()) {
String logMessage = "Subscription Update [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + " Workflow State : " + workflowDTO.getStatus();
log.debug(logMessage);
}
SubscriptionWorkflowDTO subscriptionWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatusAndTier(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
} catch (APIManagementException e) {
log.error("Could not complete subscription update workflow", e);
throw new WorkflowException("Could not complete subscription update workflow", e);
}
} else if (WorkflowStatus.REJECTED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
} catch (APIManagementException e) {
log.error("Could not complete subscription update workflow", e);
throw new WorkflowException("Could not complete subscription update workflow", e);
}
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Subscription in project carbon-apimgt by wso2.
the class SubscriptionUpdateWSWorkflowExecutor method complete.
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
workflowDTO.setUpdatedTime(System.currentTimeMillis());
super.complete(workflowDTO);
log.info("Subscription Update [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
} catch (APIManagementException e) {
log.error("Could not complete subscription update workflow", e);
throw new WorkflowException("Could not complete subscription update workflow", e);
}
} else if (WorkflowStatus.REJECTED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
} catch (APIManagementException e) {
log.error("Could not complete subscription update workflow", e);
throw new WorkflowException("Could not complete subscription update workflow", e);
}
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.Subscription in project carbon-apimgt by wso2.
the class GatewayUtils method validateAPISubscription.
/**
* Validate whether the user is subscribed to the invoked API. If subscribed, return a JSON object containing
* the API information.
*
* @param apiContext API context
* @param apiVersion API version
* @param payload The payload of the JWT token
* @return an JSON object containing subscribed API information retrieved from token payload.
* If the subscription information is not found, return a null object.
* @throws APISecurityException if the user is not subscribed to the API
*/
public static JSONObject validateAPISubscription(String apiContext, String apiVersion, JWTClaimsSet payload, String[] splitToken, boolean isOauth) throws APISecurityException {
JSONObject api = null;
APIKeyValidator apiKeyValidator = new APIKeyValidator();
APIKeyValidationInfoDTO apiKeyValidationInfoDTO = null;
boolean apiKeySubValidationEnabled = isAPIKeySubscriptionValidationEnabled();
JSONObject application;
int appId = 0;
if (payload.getClaim(APIConstants.JwtTokenConstants.APPLICATION) != null) {
application = (JSONObject) payload.getClaim(APIConstants.JwtTokenConstants.APPLICATION);
appId = Integer.parseInt(application.getAsString(APIConstants.JwtTokenConstants.APPLICATION_ID));
}
// if the appId is equal to 0 then it's a internal key
if (apiKeySubValidationEnabled && appId != 0) {
apiKeyValidationInfoDTO = apiKeyValidator.validateSubscription(apiContext, apiVersion, appId, getTenantDomain());
}
if (payload.getClaim(APIConstants.JwtTokenConstants.SUBSCRIBED_APIS) != null) {
// Subscription validation
JSONArray subscribedAPIs = (JSONArray) payload.getClaim(APIConstants.JwtTokenConstants.SUBSCRIBED_APIS);
for (Object subscribedAPI : subscribedAPIs) {
JSONObject subscribedAPIsJSONObject = (JSONObject) subscribedAPI;
if (apiContext.equals(subscribedAPIsJSONObject.getAsString(APIConstants.JwtTokenConstants.API_CONTEXT)) && apiVersion.equals(subscribedAPIsJSONObject.getAsString(APIConstants.JwtTokenConstants.API_VERSION))) {
// check whether the subscription is authorized
if (apiKeySubValidationEnabled && appId != 0) {
if (apiKeyValidationInfoDTO.isAuthorized()) {
api = subscribedAPIsJSONObject;
if (log.isDebugEnabled()) {
log.debug("User is subscribed to the API: " + apiContext + ", " + "version: " + apiVersion + ". Token: " + getMaskedToken(splitToken[0]));
}
}
} else {
api = subscribedAPIsJSONObject;
if (log.isDebugEnabled()) {
log.debug("User is subscribed to the API: " + apiContext + ", " + "version: " + apiVersion + ". Token: " + getMaskedToken(splitToken[0]));
}
}
break;
}
}
if (api == null) {
if (log.isDebugEnabled()) {
log.debug("User is not subscribed to access the API: " + apiContext + ", version: " + apiVersion + ". Token: " + getMaskedToken(splitToken[0]));
}
log.error("User is not subscribed to access the API.");
throw new APISecurityException(APISecurityConstants.API_AUTH_FORBIDDEN, APISecurityConstants.API_AUTH_FORBIDDEN_MESSAGE);
}
} else {
if (log.isDebugEnabled()) {
log.debug("No subscription information found in the token.");
}
// we perform mandatory authentication for Api Keys
if (!isOauth) {
log.error("User is not subscribed to access the API.");
throw new APISecurityException(APISecurityConstants.API_AUTH_FORBIDDEN, APISecurityConstants.API_AUTH_FORBIDDEN_MESSAGE);
}
}
return api;
}
Aggregations