use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class KeyManagerUserOperationListener method doPreDeleteUser.
/**
* Deleting user from the identity database prerequisites. Remove pending approval requests for the user and remove
* the gateway key cache.
*/
@Override
public boolean doPreDeleteUser(String username, UserStoreManager userStoreManager) {
boolean isTenantFlowStarted = false;
ApiMgtDAO apiMgtDAO = getDAOInstance();
try {
String tenantDomain = getTenantDomain();
int tenantId = getTenantId();
Tenant tenant = getTenant(tenantId);
if (tenant == null && MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
tenant = new org.wso2.carbon.user.core.tenant.Tenant();
tenant.setDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
tenant.setId(MultitenantConstants.SUPER_TENANT_ID);
} else {
// Add tenant domain to the username if user is not from super tenant domain.
// When adding a user, tenant domain is appended to workflow reference only if that user
// is from a different tenant domain(not carbon.super).
username = UserCoreUtil.addTenantDomainToEntry(username, tenantDomain);
}
Map<String, String> userStoreProperties = userStoreManager.getProperties(tenant);
String userDomain = userStoreProperties.get(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
// therefore domain name should be manually added to the username if domain is PRIMARY
if (UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME.equals(userDomain)) {
username = userDomain.toUpperCase() + UserCoreConstants.DOMAIN_SEPARATOR + username;
} else {
username = IdentityUtil.addDomainToName(username, userDomain);
}
WorkflowExecutor userSignupWFExecutor = getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_USER_SIGNUP);
String workflowExtRef = apiMgtDAO.getExternalWorkflowReferenceForUserSignup(username);
userSignupWFExecutor.cleanUpPendingTask(workflowExtRef);
} catch (WorkflowException | APIManagementException | UserStoreException e) {
// exception is not thrown to the caller since this is a event Identity(IS) listener
log.error("Error while cleaning up workflow task for the user: " + username, e);
}
APIUtil.clearRoleCache(getUserName(username, userStoreManager));
return true;
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class ApplicationRegistrationSimpleWorkflowExecutorTest method testFailureWhileExecutingApplicationRegistrationWorkFlow.
@Test
public void testFailureWhileExecutingApplicationRegistrationWorkFlow() throws APIManagementException {
PowerMockito.doNothing().when(apiMgtDAO).createApplicationRegistrationEntry(workflowDTO, false);
oAuthApplicationInfo.setJsonString("{\"client_credentials\":\"Client Credentials\"}");
Mockito.when(keyManager.createApplication(oAuthAppRequest)).thenThrow(new APIManagementException(""));
try {
applicationRegistrationSimpleWorkflowExecutor.execute(workflowDTO);
Assert.fail("Expected WorkflowException is not thrown while executing application registration simple " + "workflow");
} catch (WorkflowException e) {
Assert.assertTrue(e.getMessage().contains("Error occurred while executing SubscriberKeyMgtClient."));
}
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class SampleWorkFlowExecutor method execute.
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
workflowDTO.setStatus(WorkflowStatus.APPROVED);
WorkflowResponse workflowResponse = complete(workflowDTO);
if (workflowDTO instanceof ApplicationRegistrationWorkflowDTO) {
OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
((ApplicationRegistrationWorkflowDTO) workflowDTO).setApplicationInfo(oAuthApplicationInfo);
((ApplicationRegistrationWorkflowDTO) workflowDTO).setAccessTokenInfo(accessTokenInfo);
}
return workflowResponse;
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowApprove.
@Test
public void testWorkflowApprove() throws APIManagementException, WorkflowException {
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
workflowDTO.setStatus(WorkflowStatus.APPROVED);
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
subscriptionCreationWSWorkflowExecutor.complete(workflowDTO);
Mockito.verify(apiMgtDAO, Mockito.times(1)).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
}
use of org.wso2.carbon.apimgt.impl.workflow.WorkflowException in project carbon-apimgt by wso2.
the class SubscriptionCreationWSWorkflowExecutorTest method testWorkflowCleanupTask.
@Test
public void testWorkflowCleanupTask() throws Exception {
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
try {
subscriptionCreationWSWorkflowExecutor.cleanUpPendingTask(workflowDTO.getExternalWorkflowReference());
} catch (WorkflowException e) {
Assert.fail("Error while calling the cleanup task");
}
}
Aggregations