use of org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl 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());
}
}
use of org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl 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);
}
}
use of org.wso2.carbon.identity.workflow.mgt.WorkflowManagementServiceImpl 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;
}
Aggregations