public static IAuthenticatedWho CreatePublicUser(String tenantId)
        {
            IAuthenticatedWho authenticatedWho = null;
            Guid tenantGuid = Guid.Empty;

            if (String.IsNullOrWhiteSpace(tenantId) == true)
            {
                throw new ArgumentNullException("TenantId", "The TenantId cannot be null or blank.");
            }

            if (Guid.TryParse(tenantId, out tenantGuid) == false)
            {
                throw new ArgumentNullException("TenantId", "The TenantId is not a valid identifier.");
            }

            authenticatedWho                  = new AuthenticatedWho();
            authenticatedWho.DirectoryId      = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_DIRECTORY_ID;
            authenticatedWho.DirectoryName    = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_DIRECTORY_NAME;
            authenticatedWho.RoleId           = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_ROLE_ID;
            authenticatedWho.RoleName         = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_ROLE_NAME;
            authenticatedWho.PrimaryGroupId   = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_PRIMARY_GROUP_ID;
            authenticatedWho.PrimaryGroupName = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_PRIMARY_GROUP_NAME;
            authenticatedWho.IdentityProvider = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_IDENTITY_PROVIDER;
            authenticatedWho.Email            = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_EMAIL;
            authenticatedWho.TenantName       = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_TENANT_NAME;
            authenticatedWho.Token            = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_TOKEN;
            authenticatedWho.UserId           = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_USER_ID;
            authenticatedWho.ManyWhoTenantId  = tenantGuid;
            authenticatedWho.ManyWhoUserId    = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_MANYWHO_USER_ID;

            return(authenticatedWho);
        }
예제 #2
0
        public static IAuthenticatedWho CreatePublicUser(Guid tenant)
        {
            IAuthenticatedWho authenticatedWho = null;

            authenticatedWho                  = new AuthenticatedWho();
            authenticatedWho.DirectoryId      = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_DIRECTORY_ID;
            authenticatedWho.DirectoryName    = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_DIRECTORY_NAME;
            authenticatedWho.RoleId           = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_ROLE_ID;
            authenticatedWho.RoleName         = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_ROLE_NAME;
            authenticatedWho.PrimaryGroupId   = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_PRIMARY_GROUP_ID;
            authenticatedWho.PrimaryGroupName = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_PRIMARY_GROUP_NAME;
            authenticatedWho.IdentityProvider = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_IDENTITY_PROVIDER;
            authenticatedWho.Email            = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_EMAIL;
            authenticatedWho.TenantName       = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_TENANT_NAME;
            authenticatedWho.Token            = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_TOKEN;
            authenticatedWho.UserId           = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_USER_ID;
            authenticatedWho.ManyWhoTenantId  = tenant;
            authenticatedWho.ManyWhoToken     = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_TOKEN;
            authenticatedWho.ManyWhoUserId    = ManyWhoConstants.AUTHENTICATED_USER_PUBLIC_MANYWHO_USER_ID;

            return(authenticatedWho);
        }
        public static IAuthenticatedWho Deserialize(String token)
        {
            IAuthenticatedWho authenticatedWho = null;

            String[] parameters                = null;
            String   directoryIdParameter      = null;
            String   directoryNameParameter    = null;
            String   roleIdParameter           = null;
            String   roleNameParameter         = null;
            String   primaryGroupIdParameter   = null;
            String   primaryGroupNameParameter = null;
            String   identityProviderParameter = null;
            String   manywhoTenantIdParameter  = null;
            String   manywhoUserIdParameter    = null;
            String   manywhoTokenParameter     = null;
            String   tenantNameParameter       = null;
            String   tokenParameter            = null;
            String   userIdParameter           = null;
            String   usernameParameter         = null;
            String   emailParameter            = null;
            String   firstNameParameter        = null;
            String   lastNameParameter         = null;

            // Start by splitting the string so we have a complete key/value pairing
            parameters = token.Split('&');

            // Grab the parameters for each of the properties from the array
            manywhoTenantIdParameter  = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_MANYWHO_TENANT_ID, StringComparison.OrdinalIgnoreCase));
            manywhoUserIdParameter    = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_MANYWHO_USER_ID, StringComparison.OrdinalIgnoreCase));
            manywhoTokenParameter     = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_MANYWHO_TOKEN, StringComparison.OrdinalIgnoreCase));
            directoryIdParameter      = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_DIRECTORY_ID, StringComparison.OrdinalIgnoreCase));
            directoryNameParameter    = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_DIRECTORY_NAME, StringComparison.OrdinalIgnoreCase));
            roleIdParameter           = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_ROLE_ID, StringComparison.OrdinalIgnoreCase));
            roleNameParameter         = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_ROLE_NAME, StringComparison.OrdinalIgnoreCase));
            primaryGroupIdParameter   = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_PRIMARY_GROUP_ID, StringComparison.OrdinalIgnoreCase));
            primaryGroupNameParameter = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_PRIMARY_GROUP_NAME, StringComparison.OrdinalIgnoreCase));
            emailParameter            = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_EMAIL, StringComparison.OrdinalIgnoreCase));
            identityProviderParameter = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_IDENTITY_PROVIDER, StringComparison.OrdinalIgnoreCase));
            tenantNameParameter       = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_TENANT_NAME, StringComparison.OrdinalIgnoreCase));
            tokenParameter            = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_TOKEN, StringComparison.OrdinalIgnoreCase));
            userIdParameter           = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_USER_ID, StringComparison.OrdinalIgnoreCase));
            usernameParameter         = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_USERNAME, StringComparison.OrdinalIgnoreCase));
            firstNameParameter        = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_FIRST_NAME, StringComparison.OrdinalIgnoreCase));
            lastNameParameter         = parameters.Single(value => value.StartsWith(ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_LAST_NAME, StringComparison.OrdinalIgnoreCase));

            // Check to make sure we have all of the parameters
            Validation.Instance.IsNotNullOrWhiteSpace(manywhoTenantIdParameter, "ManyWhoTenantId", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_MANYWHO_TENANT_ID)
            .IsNotNullOrWhiteSpace(manywhoUserIdParameter, "ManyWhoUserId", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_MANYWHO_USER_ID)
            .IsNotNullOrWhiteSpace(manywhoTokenParameter, "ManyWhoToken", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_MANYWHO_TOKEN)
            .IsNotNullOrWhiteSpace(directoryIdParameter, "DirectoryId", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_DIRECTORY_ID)
            .IsNotNullOrWhiteSpace(directoryNameParameter, "DirectoryName", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_DIRECTORY_NAME)
            .IsNotNullOrWhiteSpace(emailParameter, "Email", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_EMAIL)
            .IsNotNullOrWhiteSpace(identityProviderParameter, "IdentityProvider", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_IDENTITY_PROVIDER)
            .IsNotNullOrWhiteSpace(tenantNameParameter, "TenantName", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_TENANT_NAME)
            .IsNotNullOrWhiteSpace(tokenParameter, "Token", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_TOKEN)
            .IsNotNullOrWhiteSpace(userIdParameter, "UserId", "Missing parameter: " + ManyWhoConstants.AUTHENTICATED_WHO_TOKEN_USER_ID);

            // Create our new authenticated who object
            authenticatedWho = new AuthenticatedWho();
            authenticatedWho.ManyWhoTenantId  = Guid.Parse(manywhoTenantIdParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1]);
            authenticatedWho.ManyWhoUserId    = Guid.Parse(manywhoUserIdParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1]);
            authenticatedWho.ManyWhoToken     = manywhoTokenParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            authenticatedWho.DirectoryId      = directoryIdParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            authenticatedWho.DirectoryName    = directoryNameParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            authenticatedWho.Email            = emailParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            authenticatedWho.IdentityProvider = identityProviderParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            authenticatedWho.TenantName       = tenantNameParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            authenticatedWho.Token            = tokenParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            authenticatedWho.UserId           = userIdParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];

            if (firstNameParameter != null &&
                firstNameParameter.Trim().Length > 0)
            {
                authenticatedWho.FirstName = firstNameParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            }

            if (lastNameParameter != null &&
                lastNameParameter.Trim().Length > 0)
            {
                authenticatedWho.LastName = lastNameParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            }

            if (usernameParameter != null &&
                usernameParameter.Trim().Length > 0)
            {
                authenticatedWho.Username = usernameParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            }

            if (!string.IsNullOrWhiteSpace(roleIdParameter))
            {
                authenticatedWho.RoleId = roleIdParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            }

            if (!string.IsNullOrWhiteSpace(roleNameParameter))
            {
                authenticatedWho.RoleName = roleNameParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            }

            if (!string.IsNullOrWhiteSpace(primaryGroupIdParameter))
            {
                authenticatedWho.PrimaryGroupId = primaryGroupIdParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            }

            if (!string.IsNullOrWhiteSpace(primaryGroupNameParameter))
            {
                authenticatedWho.PrimaryGroupName = primaryGroupNameParameter.Split(ManyWhoConstants.SERIALIZATION_DELIMITER_DELIMITER)[1];
            }

            // Finally, validate the object is OK
            ValidateAuthenticatedWho(authenticatedWho);

            return(authenticatedWho);
        }
        public HttpResponseMessage TaskEmailOutcomeResponse(String token, String selectedOutcomeId, String redirectUri = null)
        {
            IAuthenticatedWho   authenticatedWho = null;
            INotifier           notifier         = null;
            HttpResponseMessage response         = null;
            ServiceResponseAPI  serviceResponse  = null;
            ServiceRequestAPI   serviceRequest   = null;
            String invokeType      = null;
            String responseContent = null;

            try
            {
                if (String.IsNullOrWhiteSpace(token) == true)
                {
                    throw new ArgumentNullException("Token", "The token for the request is null or blank.");
                }

                if (String.IsNullOrWhiteSpace(selectedOutcomeId) == true)
                {
                    throw new ArgumentNullException("SelectedOutcomeId", "The selected outcome for the request is null or blank.");
                }

                // Get the email verification for this tracking code
                serviceRequest = JsonConvert.DeserializeObject <ServiceRequestAPI>(StorageUtils.GetStoredJson(token.ToLower()));

                if (serviceRequest == null)
                {
                    throw new ArgumentNullException("ServiceRequest", "The request has already been processed.");
                }

                // Get the notifier email
                authenticatedWho       = new AuthenticatedWho();
                authenticatedWho.Email = ValueUtils.GetContentValue(SalesforceServiceSingleton.SERVICE_VALUE_ADMIN_EMAIL, serviceRequest.configurationValues, true);

                // Create the notifier
                notifier = EmailNotifier.GetInstance(serviceRequest.tenantId, authenticatedWho, null, "TaskEmailOutcomeResponse");

                // Create the service response to send back to ManyWho based on this outcome click
                serviceResponse                   = new ServiceResponseAPI();
                serviceResponse.invokeType        = ManyWhoConstants.INVOKE_TYPE_FORWARD;
                serviceResponse.tenantId          = serviceRequest.tenantId;
                serviceResponse.token             = serviceRequest.token;
                serviceResponse.selectedOutcomeId = selectedOutcomeId;

                // Invoke the response on the manywho service
                invokeType = RunSingleton.GetInstance().Response(notifier, null, serviceRequest.tenantId, serviceRequest.callbackUri, serviceResponse);

                if (invokeType == null ||
                    invokeType.Trim().Length == 0)
                {
                    throw new ArgumentNullException("ServiceRequest", "The invokeType coming back from ManyWho cannot be null or blank.");
                }

                if (invokeType.IndexOf(ManyWhoConstants.INVOKE_TYPE_SUCCESS, StringComparison.InvariantCultureIgnoreCase) >= 0)
                {
                    // The system has accepted our task email response so the token is now dead - we remove it from storage
                    StorageUtils.RemoveStoredJson(token.ToLower());
                }
                else
                {
                    // The system has not accepted our task email response, so we should simply keep waiting and responding to emails with this task token
                }

                // Tell the user the outcome selection was successful
                responseContent = "Your request has been successfully completed. Please close this window.";

                if (String.IsNullOrWhiteSpace(redirectUri) == false)
                {
                    // Redirect the user as specified
                    response = Request.CreateResponse(HttpStatusCode.RedirectMethod, redirectUri);
                    response.Headers.Add("Location", redirectUri);
                }
                else
                {
                    // Send the user a response page
                    response         = Request.CreateResponse(HttpStatusCode.OK);
                    response.Content = new StringContent(responseContent);
                }
            }
            catch (Exception exception)
            {
                throw BaseHttpUtils.GetWebException(HttpStatusCode.BadRequest, BaseHttpUtils.GetExceptionMessage(exception));
            }

            return(response);
        }