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());
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations