Search in sources :

Example 1 with WorkflowManagementService

use of org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService in project carbon-identity-framework by wso2.

the class WorkflowPendingUserAuthnHandler method validatePendingApproval.

/**
 * Validate whether the user account approval is pending.
 *
 * @param username Username.
 * @throws IdentityEventException If an error occurred while validating pending approval.
 */
private void validatePendingApproval(String username, int tenantId) throws IdentityEventException {
    boolean isPendingApproval;
    try {
        Entity entity = new Entity(MultitenantUtils.getTenantAwareUsername(username), WFConstant.WORKFLOW_ENTITY_TYPE, tenantId);
        WorkflowManagementService workflowManagementService = new WorkflowManagementServiceImpl();
        isPendingApproval = workflowManagementService.entityHasPendingWorkflowsOfType(entity, WFConstant.WORKFLOW_REQUEST_TYPE);
    } catch (WorkflowException e) {
        throw new IdentityEventException("Error occurred while checking the pending approvals for " + "the account of the user: " + username, e);
    } catch (IdentityRuntimeException e) {
        throw new IdentityEventException("Can't find the tenant domain for the user: " + username, e);
    }
    if (isPendingApproval) {
        IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(IdentityCoreConstants.USER_ACCOUNT_PENDING_APPROVAL_ERROR_CODE);
        IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
        throw new IdentityEventException(WorkflowErrorConstants.ErrorMessages.ERROR_CODE_USER_ACCOUNT_PENDING_APPROVAL.getCode(), WorkflowErrorConstants.ErrorMessages.ERROR_CODE_USER_ACCOUNT_PENDING_APPROVAL.getMessage());
    }
}
Also used : Entity(org.wso2.carbon.identity.workflow.mgt.bean.Entity) IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException) IdentityErrorMsgContext(org.wso2.carbon.identity.core.model.IdentityErrorMsgContext) WorkflowManagementService(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService) WorkflowManagementServiceImpl(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl)

Example 2 with WorkflowManagementService

use of org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService in project carbon-identity-framework by wso2.

the class WorkflowMgtServiceComponent method activate.

@Activate
protected void activate(ComponentContext context) {
    try {
        BundleContext bundleContext = context.getBundleContext();
        WorkflowManagementService workflowService = new WorkflowManagementServiceImpl();
        bundleContext.registerService(WorkflowManagementService.class, workflowService, null);
        AbstractEventHandler workflowPendingUserAuthnHandler = new WorkflowPendingUserAuthnHandler();
        bundleContext.registerService(AbstractEventHandler.class, workflowPendingUserAuthnHandler, null);
        WorkflowServiceDataHolder.getInstance().setWorkflowService(workflowService);
        WorkflowServiceDataHolder.getInstance().setBundleContext(bundleContext);
        ServiceRegistration serviceRegistration = context.getBundleContext().registerService(WorkflowListener.class.getName(), new WorkflowAuditLogger(), null);
        context.getBundleContext().registerService(WorkflowExecutorManagerListener.class.getName(), new WorkflowExecutorAuditLogger(), null);
        context.getBundleContext().registerService(TenantMgtListener.class.getName(), new WorkflowTenantMgtListener(), null);
        if (serviceRegistration != null) {
            if (log.isDebugEnabled()) {
                log.debug("WorkflowAuditLogger registered.");
            }
        } else {
            log.error("Workflow Audit Logger could not be registered.");
        }
        if (System.getProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID) == null) {
            System.setProperty(WFConstant.KEYSTORE_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance().getFirstProperty(WFConstant.KEYSTORE_CARBON_CONFIG_PATH));
        }
        if (System.getProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID) == null) {
            System.setProperty(WFConstant.KEYSTORE_PASSWORD_SYSTEM_PROPERTY_ID, ServerConfiguration.getInstance().getFirstProperty(WFConstant.KEYSTORE_PASSWORD_CARBON_CONFIG_PATH));
        }
    } catch (Throwable e) {
        log.error("Failed to start the WorkflowMgtServiceComponent", e);
    }
}
Also used : WorkflowAuditLogger(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowAuditLogger) WorkflowPendingUserAuthnHandler(org.wso2.carbon.identity.workflow.mgt.handler.WorkflowPendingUserAuthnHandler) WorkflowListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener) WorkflowManagementService(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService) TenantMgtListener(org.wso2.carbon.stratos.common.listeners.TenantMgtListener) WorkflowTenantMgtListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowTenantMgtListener) WorkflowTenantMgtListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowTenantMgtListener) AbstractEventHandler(org.wso2.carbon.identity.event.handler.AbstractEventHandler) WorkflowExecutorManagerListener(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorManagerListener) WorkflowExecutorAuditLogger(org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorAuditLogger) BundleContext(org.osgi.framework.BundleContext) WorkflowManagementServiceImpl(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl) ServiceRegistration(org.osgi.framework.ServiceRegistration) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with WorkflowManagementService

use of org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService in project identity-governance by wso2-extensions.

the class UserSelfRegistrationManager method isUsernameAlreadyTaken.

/**
 * Returns whether a given username is already taken.
 *
 * @param username Username
 * @param tenantDomain Tenant domain in the request.
 * @return True if username is already taken, else false.
 * @throws IdentityRecoveryException Error occurred while retrieving user realm.
 */
public boolean isUsernameAlreadyTaken(String username, String tenantDomain) throws IdentityRecoveryException {
    boolean isUsernameAlreadyTaken = true;
    WorkflowManagementService workflowService = new WorkflowManagementServiceImpl();
    if (StringUtils.isBlank(tenantDomain)) {
        tenantDomain = MultitenantUtils.getTenantDomain(username);
    }
    try {
        String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
        Entity userEntity = new Entity(tenantAwareUsername, IdentityRecoveryConstants.ENTITY_TYPE_USER, IdentityTenantUtil.getTenantId(tenantDomain));
        UserRealm userRealm = getUserRealm(tenantDomain);
        if (userRealm != null) {
            isUsernameAlreadyTaken = userRealm.getUserStoreManager().isExistingUser(tenantAwareUsername) || workflowService.entityHasPendingWorkflowsOfType(userEntity, IdentityRecoveryConstants.ADD_USER_EVENT);
        }
    } catch (CarbonException | org.wso2.carbon.user.core.UserStoreException | WorkflowException e) {
        throw new IdentityRecoveryException("Error while retrieving user realm for tenant : " + tenantDomain, e);
    }
    return isUsernameAlreadyTaken;
}
Also used : Entity(org.wso2.carbon.identity.workflow.mgt.bean.Entity) WorkflowException(org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException) CarbonException(org.wso2.carbon.CarbonException) WorkflowManagementService(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService) UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityRecoveryException(org.wso2.carbon.identity.recovery.IdentityRecoveryException) WorkflowManagementServiceImpl(org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl)

Aggregations

WorkflowManagementService (org.wso2.carbon.identity.workflow.mgt.WorkflowManagementService)3 WorkflowManagementServiceImpl (org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl)3 Entity (org.wso2.carbon.identity.workflow.mgt.bean.Entity)2 WorkflowException (org.wso2.carbon.identity.workflow.mgt.exception.WorkflowException)2 BundleContext (org.osgi.framework.BundleContext)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 Activate (org.osgi.service.component.annotations.Activate)1 CarbonException (org.wso2.carbon.CarbonException)1 IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)1 IdentityErrorMsgContext (org.wso2.carbon.identity.core.model.IdentityErrorMsgContext)1 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)1 AbstractEventHandler (org.wso2.carbon.identity.event.handler.AbstractEventHandler)1 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)1 WorkflowPendingUserAuthnHandler (org.wso2.carbon.identity.workflow.mgt.handler.WorkflowPendingUserAuthnHandler)1 WorkflowAuditLogger (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowAuditLogger)1 WorkflowExecutorAuditLogger (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorAuditLogger)1 WorkflowExecutorManagerListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowExecutorManagerListener)1 WorkflowListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowListener)1 WorkflowTenantMgtListener (org.wso2.carbon.identity.workflow.mgt.listener.WorkflowTenantMgtListener)1 TenantMgtListener (org.wso2.carbon.stratos.common.listeners.TenantMgtListener)1