use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-business-process by wso2.
the class JPATaskUtil method processGenericHumanRoles.
public static void processGenericHumanRoles(TaskDAO task, HumanTaskBaseConfiguration taskConfiguration, PeopleQueryEvaluator peopleQueryEvaluator, EvaluationContext evaluationContext) throws HumanTaskException {
if (taskConfiguration.isTask()) {
// Task
TTask tTask = ((TaskConfiguration) taskConfiguration).getTask();
// TODO move the reading of configuration file in to the TaskConfiguration class
// Reading Excluded users
TGenericHumanRoleAssignment[] tExcludedOwners = tTask.getPeopleAssignments().getExcludedOwnersArray();
if (tExcludedOwners != null && tExcludedOwners.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tExcludedOwners[0], GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS, evaluationContext);
}
// Reading potential owners
TPotentialOwnerAssignment[] tPotentialOwners = tTask.getPeopleAssignments().getPotentialOwnersArray();
if (tPotentialOwners != null && tPotentialOwners.length > 0) {
TPotentialOwnerAssignment tPotentialOwner = tPotentialOwners[0];
OrganizationalEntityProvider provider = OrganizationalEntityProviderFactory.getOrganizationalEntityProvider(tPotentialOwner.getFrom());
List<OrganizationalEntityDAO> orgEntities = provider.getOrganizationalEntities(peopleQueryEvaluator, tPotentialOwner.getFrom(), evaluationContext);
if (tExcludedOwners != null && tExcludedOwners.length > 0) {
GenericHumanRoleDAO excludedOwners = task.getGenericHumanRole(GenericHumanRoleDAO.GenericHumanRoleType.EXCLUDED_OWNERS);
for (OrganizationalEntityDAO excludedEntity : excludedOwners.getOrgEntities()) {
for (OrganizationalEntityDAO ownerEntity : orgEntities) {
if (excludedEntity.getOrgEntityType() == ownerEntity.getOrgEntityType() && excludedEntity.getName().equals(ownerEntity.getName())) {
orgEntities.remove(ownerEntity);
break;
}
}
}
}
GenericHumanRole potentialOwnersGHRole = new GenericHumanRole();
potentialOwnersGHRole.setType(GenericHumanRole.GenericHumanRoleType.POTENTIAL_OWNERS);
potentialOwnersGHRole.setOrgEntities(orgEntities);
potentialOwnersGHRole.setTask(task);
for (OrganizationalEntityDAO oe : orgEntities) {
oe.addGenericHumanRole(potentialOwnersGHRole);
}
task.addHumanRole(potentialOwnersGHRole);
}
// Reading Stake holders
TGenericHumanRoleAssignment[] tStakeHolders = tTask.getPeopleAssignments().getTaskStakeholdersArray();
if (tStakeHolders != null && tStakeHolders.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tStakeHolders[0], GenericHumanRoleDAO.GenericHumanRoleType.STAKEHOLDERS, evaluationContext);
}
// Reading Business administrators
TGenericHumanRoleAssignment[] tBusinessAdministrators = tTask.getPeopleAssignments().getBusinessAdministratorsArray();
if (tBusinessAdministrators != null && tBusinessAdministrators.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tBusinessAdministrators[0], GenericHumanRoleDAO.GenericHumanRoleType.BUSINESS_ADMINISTRATORS, evaluationContext);
}
} else {
// Notification
TNotification tNotification = ((NotificationConfiguration) taskConfiguration).getNotificationDefinition();
// Reading Notification recipients
TGenericHumanRoleAssignment[] tRecipients = tNotification.getPeopleAssignments().getRecipientsArray();
if (tRecipients != null && tRecipients.length > 0) {
assignHumanRoles(task, peopleQueryEvaluator, tRecipients[0], GenericHumanRoleDAO.GenericHumanRoleType.NOTIFICATION_RECIPIENTS, evaluationContext);
}
}
}
use of org.wso2.carbon.apimgt.api.model.Provider in project identity-outbound-auth-sms-otp by wso2-extensions.
the class SMSOTPAuthenticator method proceedWithOTP.
/**
* Proceed with One Time Password.
*
* @param response the HttpServletResponse
* @param context the AuthenticationContext
* @param errorPage the errorPage
* @param mobileNumber the mobile number
* @param queryParams the queryParams
* @param username the Username
* @throws AuthenticationFailedException
*/
private void proceedWithOTP(HttpServletResponse response, AuthenticationContext context, String errorPage, String mobileNumber, String queryParams, String username) throws AuthenticationFailedException {
String screenValue;
Map<String, String> authenticatorProperties = context.getAuthenticatorProperties();
boolean isEnableResendCode = SMSOTPUtils.isEnableResendCode(context, getName());
String loginPage = getLoginPage(context);
String tenantDomain = MultitenantUtils.getTenantDomain(username);
String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
UserRealm userRealm = SMSOTPUtils.getUserRealm(tenantDomain);
try {
// One time password is generated and stored in the context.
OneTimePassword token = new OneTimePassword();
String secret = OneTimePassword.getRandomNumber(SMSOTPConstants.SECRET_KEY_LENGTH);
String otpToken = token.generateToken(secret, String.valueOf(SMSOTPConstants.NUMBER_BASE), SMSOTPConstants.NUMBER_DIGIT);
context.setProperty(SMSOTPConstants.OTP_TOKEN, otpToken);
if (log.isDebugEnabled()) {
log.debug("Generated OTP successfully and set to the context.");
}
// Get the values of the sms provider related api parameters.
String smsUrl = authenticatorProperties.get(SMSOTPConstants.SMS_URL);
String httpMethod = authenticatorProperties.get(SMSOTPConstants.HTTP_METHOD);
String headerString = authenticatorProperties.get(SMSOTPConstants.HEADERS);
String payload = authenticatorProperties.get(SMSOTPConstants.PAYLOAD);
String httpResponse = authenticatorProperties.get(SMSOTPConstants.HTTP_RESPONSE);
if (!sendRESTCall(context, smsUrl, httpMethod, headerString, payload, httpResponse, mobileNumber, otpToken)) {
String retryParam;
context.setProperty(SMSOTPConstants.STATUS_CODE, SMSOTPConstants.UNABLE_SEND_CODE);
if (context.getProperty(SMSOTPConstants.ERROR_CODE) != null) {
retryParam = SMSOTPConstants.UNABLE_SEND_CODE_PARAM + context.getProperty(SMSOTPConstants.ERROR_CODE).toString();
} else {
retryParam = SMSOTPConstants.UNABLE_SEND_CODE_PARAM + SMSOTPConstants.UNABLE_SEND_CODE_VALUE;
}
String redirectUrl = getURL(errorPage, queryParams);
response.sendRedirect(redirectUrl + SMSOTPConstants.RESEND_CODE + isEnableResendCode + retryParam);
} else {
String url = getURL(loginPage, queryParams);
boolean isUserExists = FederatedAuthenticatorUtil.isUserExistInUserStore(username);
if (isUserExists) {
screenValue = getScreenAttribute(context, userRealm, tenantAwareUsername);
if (screenValue != null) {
url = url + SMSOTPConstants.SCREEN_VALUE + screenValue;
}
}
response.sendRedirect(url);
}
} catch (IOException e) {
throw new AuthenticationFailedException("Error while sending the HTTP request. ", e);
} catch (UserStoreException e) {
throw new AuthenticationFailedException("Failed to get the user from user store. ", e);
}
}
use of org.wso2.carbon.apimgt.api.model.Provider in project product-iots by wso2.
the class APIUtil method getAPIManagementProviderService.
/**
* @return api management service of current context
*/
public static APIManagementProviderService getAPIManagementProviderService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
APIManagementProviderService apiManagementProviderService = (APIManagementProviderService) ctx.getOSGiService(APIManagementProviderService.class, null);
if (apiManagementProviderService == null) {
String msg = "API management provider service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return apiManagementProviderService;
}
use of org.wso2.carbon.apimgt.api.model.Provider in project product-iots by wso2.
the class AppOperations method addApplication.
public static boolean addApplication(String name, MobileApplication mblApp, boolean isEnterpriseApp) {
HashMap<String, String> headers = new HashMap<String, String>();
String appEndpoint = EMMQSGConfig.getInstance().getEmmHost() + appmPublisherAppsUrl;
// Set the application payload
JSONObject application = new JSONObject();
application.put("name", name);
application.put("description", "Sample application");
application.put("type", "enterprise");
// Set appMeta data
JSONObject appMeta = new JSONObject();
appMeta.put("package", mblApp.getPackageId());
appMeta.put("version", mblApp.getVersion());
if (isEnterpriseApp) {
application.put("marketType", "enterprise");
appMeta.put("path", mblApp.getAppId());
} else {
application.put("marketType", "public");
}
application.put("provider", "admin");
application.put("displayName", name);
application.put("category", "Business");
application.put("thumbnailUrl", mblApp.getIcon());
application.put("version", mblApp.getVersion());
application.put("banner", mblApp.getBanner());
application.put("platform", mblApp.getPlatform());
application.put("appType", mblApp.getPlatform());
// application.put("appUrL", mblApp.getAppId());
application.put("mediaType", "application/vnd.wso2-mobileapp+xml");
// Set screenshots
JSONArray screenshots = new JSONArray();
screenshots.add(mblApp.getScreenshot1());
screenshots.add(mblApp.getScreenshot2());
screenshots.add(mblApp.getScreenshot3());
application.put("appmeta", appMeta);
application.put("screenshots", screenshots);
// Set the headers
headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON);
HTTPResponse httpResponse = HTTPInvoker.sendHTTPPostWithOAuthSecurity(appEndpoint, application.toJSONString(), headers);
if (Constants.HTTPStatus.OK == httpResponse.getResponseCode()) {
return true;
}
return false;
}
use of org.wso2.carbon.apimgt.api.model.Provider in project charon by wso2.
the class GroupResourceManager method create.
/*
* Create group in the service provider given the submitted payload that contains the SCIM group
* resource, format and the handler to usermanager.
*
* @param scimObjectString - Payload of HTTP request, which contains the SCIM object.
* @param usermanager
* @param attributes
* @param excludeAttributes
* @return
*/
@Override
public SCIMResponse create(String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
JSONEncoder encoder = null;
JSONDecoder decoder = null;
try {
// obtain the json encoder
encoder = getEncoder();
// obtain the json decoder
decoder = getDecoder();
// returns core-group schema
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getGroupResourceSchema();
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
// decode the SCIM group object, encoded in the submitted payload.
Group group = (Group) decoder.decodeResource(scimObjectString, schema, new Group());
// validate decoded group
ServerSideValidator.validateCreatedSCIMObject(group, SCIMSchemaDefinitions.SCIM_GROUP_SCHEMA);
// handover the SCIM User object to the group usermanager provided by the SP.
Group createdGroup;
// need to send back the newly created group in the response payload
createdGroup = ((UserManager) userManager).createGroup(group, requiredAttributes);
// encode the newly created SCIM group object and add id attribute to Location header.
String encodedGroup;
Map<String, String> httpHeaders = new HashMap<String, String>();
if (createdGroup != null) {
encodedGroup = encoder.encodeSCIMObject(createdGroup);
// add location header
httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.GROUP_ENDPOINT) + "/" + createdGroup.getId());
httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
} else {
String message = "Newly created Group resource is null..";
throw new InternalErrorException(message);
}
// put the uri of the Group object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_CREATED, encodedGroup, httpHeaders);
} catch (InternalErrorException e) {
return encodeSCIMException(e);
} catch (BadRequestException e) {
return encodeSCIMException(e);
} catch (ConflictException e) {
return encodeSCIMException(e);
} catch (CharonException e) {
return encodeSCIMException(e);
} catch (NotFoundException e) {
return encodeSCIMException(e);
} catch (NotImplementedException e) {
return encodeSCIMException(e);
}
}
Aggregations