Search in sources :

Example 96 with UserStoreException

use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.

the class UserSubstitutionService method substitute.

/**
 * Add new addSubstituteInfo record.
 * Following request body parameters are required,
 *  assignee : optional, logged in user is used if not provided
 *  substitute : required
 *  startTime : optional, current timestamp if not provided, the timestamp the substitution should start in ISO format
 *  endTime : optional, considered as forever if not provided, the timestamp the substitution should end in ISO format
 * @param request
 * @return 201 created response with the resource location. 405 if substitution disabled
 */
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response substitute(SubstitutionRequest request) {
    try {
        if (!subsFeatureEnabled) {
            return Response.status(405).build();
        }
        String assignee = getRequestedAssignee(request.getAssignee());
        String substitute = validateAndGetSubstitute(request.getSubstitute(), assignee);
        Date endTime = null;
        Date startTime = new Date();
        DateTime requestStartTime = null;
        if (request.getStartTime() != null) {
            requestStartTime = new DateTime(request.getStartTime());
            startTime = new Date(requestStartTime.getMillis());
        }
        if (request.getEndTime() != null) {
            endTime = validateEndTime(request.getEndTime(), requestStartTime);
        }
        if (!UserSubstitutionUtils.validateTasksList(request.getTaskList(), assignee)) {
            throw new ActivitiIllegalArgumentException("Invalid task list provided, for substitution.");
        }
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        // at this point, substitution is enabled by default
        UserSubstitutionUtils.handleNewSubstituteAddition(assignee, substitute, startTime, endTime, true, request.getTaskList(), tenantId);
        return Response.created(new URI("substitutes/" + assignee)).build();
    } catch (UserStoreException e) {
        throw new ActivitiException("Error accessing User Store", e);
    } catch (URISyntaxException e) {
        throw new ActivitiException("Response location URI creation header", e);
    } catch (ActivitiIllegalArgumentException e) {
        throw new ActivitiIllegalArgumentException(e.getMessage());
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) DateTime(org.joda.time.DateTime)

Example 97 with UserStoreException

use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.

the class UserSubstitutionService method isUserAuthorizedForSubstitute.

/**
 * Check the logged in user has permission for viewing other substitutions.
 * @return true if the permission sufficient
 * @throws UserStoreException
 */
private boolean isUserAuthorizedForSubstitute(String username) throws UserStoreException {
    UserRealm userRealm = BPMNOSGIService.getUserRealm();
    // check with bpmn permission path
    String[] permissionArray = userRealm.getAuthorizationManager().getAllowedUIResourcesForUser(username, BPMNConstants.BPMN_PERMISSION_PATH);
    if (permissionArray != null && permissionArray.length > 0) {
        if (permissionArray[0].equals(BPMNConstants.BPMN_PERMISSION_PATH) || isPermissionExist(permissionArray, BPMNConstants.SUBSTITUTION_PERMISSION_PATH)) {
            return true;
        }
    }
    // check for admin permission
    String[] adminPermissionArray = userRealm.getAuthorizationManager().getAllowedUIResourcesForUser(username, BPMNConstants.ROOT_PERMISSION_PATH);
    if (adminPermissionArray != null && adminPermissionArray.length > 0) {
        if (adminPermissionArray[0].equals(BPMNConstants.ROOT_PERMISSION_PATH) || adminPermissionArray[0].equals(BPMNConstants.ADMIN_PERMISSION_PATH)) {
            return true;
        }
    }
    return false;
}
Also used : UserRealm(org.wso2.carbon.user.api.UserRealm)

Example 98 with UserStoreException

use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.

the class BPSGroupIdentityManager method findGroupsByUser.

@Override
public List<Group> findGroupsByUser(String userId) {
    List<Group> groups = new ArrayList<Group>();
    try {
        String[] roles = userStoreManager.getRoleListOfUser(userId);
        for (String role : roles) {
            Group group = new GroupEntity(role);
            groups.add(group);
        }
    } catch (UserStoreException e) {
        String msg = "Failed to get roles of the user: " + userId + ". Returning an empty roles list.";
        log.error(msg, e);
    }
    return groups;
}
Also used : Group(org.activiti.engine.identity.Group) GroupEntity(org.activiti.engine.impl.persistence.entity.GroupEntity) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 99 with UserStoreException

use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.

the class BPSUserIdentityManager method findGroupsByUser.

@Override
public List<Group> findGroupsByUser(String userId) {
    List<Group> groups = new ArrayList<Group>();
    try {
        String[] userNameTokens = userId.split("@");
        int tenantId = BPMNConstants.SUPER_TENANT_ID;
        if (userNameTokens.length > 1) {
            TenantInfoBean tenantInfoBean = tenantMgtAdminService.getTenant(userNameTokens[userNameTokens.length - 1]);
            if (tenantInfoBean != null) {
                tenantId = tenantInfoBean.getTenantId();
            } else {
                log.error("Could not retrieve tenant ID for tenant domain : " + userNameTokens[userNameTokens.length - 1]);
                return new ArrayList<Group>();
            }
        }
        String[] roles = registryService.getUserRealm(tenantId).getUserStoreManager().getRoleListOfUser(userId);
        for (String role : roles) {
            Group group = new GroupEntity(role);
            groups.add(group);
        }
    } catch (UserStoreException e) {
        String msg = "Failed to get roles of the user: " + userId + ". Returning an empty roles list.";
        log.error(msg, e);
    } catch (Exception e) {
        log.error("error retrieving user tenant info", e);
    }
    return groups;
}
Also used : Group(org.activiti.engine.identity.Group) GroupEntity(org.activiti.engine.impl.persistence.entity.GroupEntity) ArrayList(java.util.ArrayList) UserStoreException(org.wso2.carbon.user.api.UserStoreException) TenantInfoBean(org.wso2.carbon.stratos.common.beans.TenantInfoBean) UserStoreException(org.wso2.carbon.user.api.UserStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BPMNAuthenticationException(org.wso2.carbon.bpmn.core.exception.BPMNAuthenticationException)

Example 100 with UserStoreException

use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.

the class CommonTaskUtil method getAssignableUserNameList.

/**
 * Returns the list of assignable user name list.
 *
 * @param task               : The task object.
 * @param excludeActualOwner : Whether to exclude the actual owner from the returned list.
 * @return : the list of assignable user name list.
 */
public static List<String> getAssignableUserNameList(TaskDAO task, boolean excludeActualOwner) {
    List<String> allPotentialOwners = new ArrayList<String>();
    GenericHumanRoleDAO ghr = task.getGenericHumanRole(GenericHumanRole.GenericHumanRoleType.POTENTIAL_OWNERS);
    RegistryService registryService = HumanTaskServiceComponent.getRegistryService();
    for (OrganizationalEntityDAO orgEntity : ghr.getOrgEntities()) {
        if (OrganizationalEntityDAO.OrganizationalEntityType.GROUP.equals(orgEntity.getOrgEntityType())) {
            String roleName = orgEntity.getName();
            UserRealm userRealm;
            try {
                userRealm = registryService.getUserRealm(task.getTenantId());
                String[] assignableUsersArray = userRealm.getUserStoreManager().getUserListOfRole(roleName);
                allPotentialOwners.addAll(Arrays.asList(assignableUsersArray));
            } catch (RegistryException e) {
                throw new HumanTaskRuntimeException("Cannot locate user realm for tenant id " + task.getTenantId());
            } catch (UserStoreException e) {
                throw new HumanTaskRuntimeException("Error retrieving the UserStoreManager " + task.getTenantId(), e);
            }
        } else if (OrganizationalEntityDAO.OrganizationalEntityType.USER.equals(orgEntity.getOrgEntityType())) {
            allPotentialOwners.add(orgEntity.getName());
        }
    }
    OrganizationalEntityDAO actualOwner = getActualOwner(task);
    if (excludeActualOwner && actualOwner != null) {
        allPotentialOwners.remove(actualOwner.getName());
    }
    return allPotentialOwners;
}
Also used : UserRealm(org.wso2.carbon.user.core.UserRealm) UserStoreException(org.wso2.carbon.user.core.UserStoreException) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Aggregations

UserStoreException (org.wso2.carbon.user.api.UserStoreException)127 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)65 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)47 Test (org.junit.Test)37 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)37 RealmService (org.wso2.carbon.user.core.service.RealmService)36 ArrayList (java.util.ArrayList)33 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)33 API (org.wso2.carbon.apimgt.api.model.API)31 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)27 HashMap (java.util.HashMap)25 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)23 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)23 Resource (org.wso2.carbon.registry.core.Resource)23 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)21 JSONObject (org.json.simple.JSONObject)20 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)20 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)20 HashSet (java.util.HashSet)19 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)18