use of org.wso2.carbon.user.api.UserStoreException in project core-util by WSO2Telco.
the class BasicAuthenticator method isAuthenticatedUser.
public boolean isAuthenticatedUser(String userName, String password) {
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
RealmService realmService = (RealmService) carbonContext.getOSGiService(RealmService.class, null);
RegistryService registryService = (RegistryService) carbonContext.getOSGiService(RegistryService.class, null);
String tenantDomain = MultitenantUtils.getTenantDomain(userName);
try {
UserRealm userRealm = null;
userRealm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain);
if (userRealm == null) {
log.error("invalid domain or unactivated tenant login");
return false;
}
String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(userName);
if (userRealm.getUserStoreManager().authenticate(tenantAwareUsername, password)) {
return true;
} else {
log.error("authentication failed. please check your username/password");
return false;
}
} catch (CarbonException | UserStoreException e) {
log.error("authentication failed for user : " + userName, e);
return false;
}
}
use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.
the class TaskOperationsImpl method getUserListForRole.
private TUser[] getUserListForRole(String roleName, int tenantId, String actualOwnerUserName) throws RegistryException, UserStoreException {
TUser[] userList = new TUser[0];
RegistryService registryService = HumanTaskServiceComponent.getRegistryService();
if (registryService != null && registryService.getUserRealm(tenantId) != null) {
UserRealm userRealm = registryService.getUserRealm(tenantId);
String[] assignableUserNameList = userRealm.getUserStoreManager().getUserListOfRole(roleName);
if (assignableUserNameList != null) {
userList = new TUser[assignableUserNameList.length];
for (int i = 0; i < assignableUserNameList.length; i++) {
TUser user = new TUser();
user.setTUser(assignableUserNameList[i]);
if (StringUtils.isEmpty(actualOwnerUserName)) {
userList[i] = user;
} else if (StringUtils.isNotEmpty(actualOwnerUserName) && !actualOwnerUserName.equals(assignableUserNameList[i])) {
userList[i] = user;
}
}
}
} else {
log.warn("Cannot load User Realm for Tenant Id: " + tenantId);
}
return userList;
}
use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.
the class PeopleActivity method invoke.
public String invoke(ExtensionContext extensionContext) throws FaultException {
BPELMessageContext taskMessageContext = new BPELMessageContext(hiWSDL);
UUID messageID = null;
int tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId);
String tenantDomain = null;
try {
tenantDomain = B4PContentHolder.getInstance().getRealmService().getTenantManager().getDomain(tenantId);
} catch (UserStoreException e) {
log.error(" Cannot find the tenant domain " + e.toString());
}
if (tenantDomain == null) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
try {
// Setting the attachment id attachmentIDList
List<Long> attachmentIDList = extractAttachmentIDsToBeSentToHumanTask(extensionContext, taskMessageContext);
taskMessageContext.setOperationName(getOperationName());
SOAPHelper soapHelper = new SOAPHelper(getBinding(), getSoapFactory(), isRPC);
MessageContext messageContext = new MessageContext();
/*
Adding attachment ID list as a method input to createSoapRequest makes no sense.
Have to fix. Here we can't embed attachments in MessageContext, as we have only a
list of attachment ids.
*/
soapHelper.createSoapRequest(messageContext, (Element) extensionContext.readVariable(inputVarName), getOperation(extensionContext), attachmentIDList);
// Coordination Context and skipable attribute is only valid for a Task.
if (InteractionType.TASK.equals(activityType)) {
// Note: If registration service is not enabled, we don't need to send coor-context.
if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
messageID = UUID.randomUUID();
soapHelper.addCoordinationContext(messageContext, messageID.toString(), getRegistrationServiceURL());
}
// Adding HumanTask Context overriding attributes.
soapHelper.addOverridingHumanTaskAttributes(messageContext, isSkipable);
}
taskMessageContext.setInMessageContext(messageContext);
taskMessageContext.setPort(getServicePort());
taskMessageContext.setService(getServiceName());
taskMessageContext.setRPCStyleOperation(isRPC);
taskMessageContext.setTwoWay(isTwoWay);
taskMessageContext.setSoapFactoryForCurrentMessageFlow(getSoapFactory());
taskMessageContext.setWsdlBindingForCurrentMessageFlow(getBinding());
taskMessageContext.setUep(getUnifiedEndpoint());
taskMessageContext.setCaller(processId.getLocalPart());
AxisServiceUtils.invokeService(taskMessageContext, getConfigurationContext());
} catch (AxisFault axisFault) {
log.error(axisFault, axisFault);
throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while invoking service " + serviceName, axisFault);
} catch (B4PCoordinationException coordinationFault) {
throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while generating Registration Service URL" + serviceName, coordinationFault);
}
if (taskMessageContext.getFaultMessageContext() != null || taskMessageContext.getOutMessageContext().isFault()) {
MessageContext faultContext = taskMessageContext.getFaultMessageContext() != null ? taskMessageContext.getFaultMessageContext() : taskMessageContext.getOutMessageContext();
log.warn("SOAP Fault: " + faultContext.getEnvelope().toString());
throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, faultContext.getEnvelope().toString());
}
String taskID = SOAPHelper.parseResponseFeedback(taskMessageContext.getOutMessageContext().getEnvelope().getBody());
// Ignore Notifications, since we are ignore coordination context for notification.
if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && InteractionType.TASK.equals(activityType)) {
Long instanceID = extensionContext.getProcessId();
if (CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
try {
// Already coordinated with Registration service.
updateCoordinationData(messageID.toString(), Long.toString(instanceID), taskID);
} catch (Exception e) {
log.error("Error occurred while updating humantask coordination data.", e);
}
} else {
// Handler URL by manually.
try {
messageID = UUID.randomUUID();
String protocolHandlerURL = generateTaskProtocolHandlerURL(taskMessageContext);
if (log.isDebugEnabled()) {
log.debug("Generated Protocol Handler URL : " + protocolHandlerURL);
}
createCoordinationData(messageID.toString(), protocolHandlerURL, Long.toString(instanceID), taskID);
} catch (Exception e) {
log.error("Error occurred while creating humantask coordination data for coordinated task.", e);
}
}
}
return taskID;
}
use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.
the class UserSubstitutionService method updateSubstituteInfo.
/**
* Update the substitute info of the given user in the request path. Use the same format used in POST method.
* @param user - user that need to update his substitute info
* @param request - substitute info that need to be updated
* @return
* @throws URISyntaxException
*/
@PUT
@Path("/{user}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateSubstituteInfo(@PathParam("user") String user, SubstitutionRequest request) throws URISyntaxException {
try {
if (!subsFeatureEnabled) {
return Response.status(405).build();
}
request.setAssignee(user);
String assignee = getRequestedAssignee(user);
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();
UserSubstitutionUtils.handleUpdateSubstitute(assignee, substitute, startTime, endTime, true, request.getTaskList(), tenantId);
return Response.ok().build();
} catch (UserStoreException e) {
throw new ActivitiException("Error accessing User Store", e);
}
}
use of org.wso2.carbon.user.api.UserStoreException in project carbon-business-process by wso2.
the class UserSubstitutionService method getRequestedAssignee.
/**
* Validate and get the assignee for a substitute request
* @param user
* @return actual assignee of the substitute request
* @throws UserStoreException
*/
private String getRequestedAssignee(final String user) throws UserStoreException {
String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
UserRealm userRealm = BPMNOSGIService.getUserRealm();
String assignee = getTenantAwareUser(user);
// validate the assignee
if (assignee != null && !assignee.trim().isEmpty() && !assignee.equals(loggedInUser)) {
// setting another users
boolean isAuthorized = isUserAuthorizedForSubstitute(loggedInUser);
if (!isAuthorized) {
throw new BPMNForbiddenException("Action requires BPMN substitution permission");
}
if (!userRealm.getUserStoreManager().isExistingUser(assignee)) {
throw new ActivitiIllegalArgumentException("Non existing user for argument assignee : " + assignee);
}
} else {
// assignee is the logged in user
assignee = loggedInUser;
}
return assignee;
}
Aggregations