Search in sources :

Example 66 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.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;
}
Also used : WorkflowException(org.wso2.carbon.apimgt.impl.workflow.WorkflowException) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Tenant(org.wso2.carbon.user.api.Tenant) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)

Example 67 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.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."));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 68 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.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;
}
Also used : AccessTokenInfo(org.wso2.carbon.apimgt.api.model.AccessTokenInfo) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse)

Example 69 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.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);
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 70 with WorkflowException

use of org.wso2.carbon.apimgt.core.exception.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");
    }
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ServiceReferenceHolderMockCreator(org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)56 Test (org.junit.Test)49 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)49 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)32 ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)25 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)24 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)24 Application (org.wso2.carbon.apimgt.api.model.Application)18 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)17 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)15 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)13 HashMap (java.util.HashMap)12 JSONObject (org.json.simple.JSONObject)12 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)12 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)10 XMLStreamException (javax.xml.stream.XMLStreamException)9 UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)9 WorkflowResponse (org.wso2.carbon.apimgt.api.WorkflowResponse)8 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)6