Search in sources :

Example 16 with UserRegistrationConfigDTO

use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.

the class UserSignUpApprovalWorkflowExecutor method complete.

/**
 * Complete the Approval workflow executor for User self sign up.
 *
 * @param workflowDTO
 */
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setUpdatedTime(System.currentTimeMillis());
    if (log.isDebugEnabled()) {
        log.debug("User Sign Up [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + " Workflow State : " + workflowDTO.getStatus());
    }
    super.complete(workflowDTO);
    String tenantDomain = workflowDTO.getTenantDomain();
    try {
        UserRegistrationConfigDTO signupConfig = SelfSignUpUtil.getSignupConfiguration(tenantDomain);
        String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(workflowDTO.getWorkflowReference());
        if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
            try {
                updateRolesOfUser(tenantAwareUserName, SelfSignUpUtil.getRoleNames(signupConfig), tenantDomain);
            } catch (Exception e) {
                // updateRolesOfUser throws generic Exception. Therefore generic Exception is caught
                throw new WorkflowException("Error while assigning role to user", e);
            }
        } else {
            try {
                /* Remove created user */
                deleteUser(tenantDomain, tenantAwareUserName);
            } catch (Exception e) {
                throw new WorkflowException("Error while deleting the user", e);
            }
        }
    } catch (APIManagementException e1) {
        throw new WorkflowException("Error while accessing signup configuration", e1);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Aggregations

UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)16 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 HashMap (java.util.HashMap)7 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 Iterator (java.util.Iterator)3 QName (javax.xml.namespace.QName)3 OMElement (org.apache.axiom.om.OMElement)3 PasswordResolver (org.wso2.carbon.apimgt.api.PasswordResolver)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 APIMConfigService (org.wso2.carbon.apimgt.impl.config.APIMConfigService)2 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)2 SelfSignUpUtil (org.wso2.carbon.apimgt.impl.utils.SelfSignUpUtil)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)1 UserRealm (org.wso2.carbon.user.core.UserRealm)1 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)1 RealmService (org.wso2.carbon.user.core.service.RealmService)1