Exemple #1
0
            /// <summary>
            /// Validates hardware station token.
            /// </summary>
            /// <param name="request">The validate authentication token request.</param>
            /// <returns>Validate hardware station token response.</returns>
            private static ValidateHardwareStationTokenServiceResponse ValidateHardwareStationToken(ValidateHardwareStationTokenServiceRequest request)
            {
                const int TokenExpirationInMinutes = 1;
                string    deviceNumber             = string.Empty;
                long      tokenCreationFileTime;
                ValidateHardwareStationTokenResult result = new ValidateHardwareStationTokenResult();

                try
                {
                    string decryptedToken = DeviceManagementService.DecryptData(request.RequestContext, request.HardwareStationToken);

                    string[] fields = decryptedToken.Split(Separator);
                    deviceNumber          = fields[0];
                    result.PairingKey     = fields[1];
                    tokenCreationFileTime = long.Parse(fields[2], CultureInfo.InvariantCulture);
                }
                catch (Exception ex)
                {
                    throw new SecurityException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidHardwareStationToken, ex, "Hardware station token validation failed.");
                }

                if ((!request.DeviceNumber.Equals(deviceNumber, StringComparison.OrdinalIgnoreCase)) ||
                    (DateTimeOffset.UtcNow.CompareTo(DateTimeOffset.FromFileTime(tokenCreationFileTime).AddMinutes(TokenExpirationInMinutes)) > 0))
                {
                    throw new SecurityException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_InvalidHardwareStationToken);
                }

                return(new ValidateHardwareStationTokenServiceResponse(result));
            }
Exemple #2
0
            /// <summary>
            /// Creates hardware station token.
            /// </summary>
            /// <param name="request">The create authentication token request.</param>
            /// <returns>Create authentication token response.</returns>
            private static CreateHardwareStationTokenServiceResponse CreateHardwareStationToken(CreateHardwareStationTokenServiceRequest request)
            {
                // Authorization token (pairing key) for the client and hardware station.
                string pairingKey = Guid.NewGuid().ToString();

                // Validateion token for HS to get validated from Retail Server
                string validationToken = request.DeviceNumber + Separator + pairingKey + Separator + DateTimeOffset.UtcNow.ToFileTime();

                try
                {
                    CreateHardwareStationTokenResult result = new CreateHardwareStationTokenResult();

                    result.PairingKey           = pairingKey;
                    result.HardwareStationToken = DeviceManagementService.EncryptData(
                        request.RequestContext,
                        validationToken,
                        request.CertificateThumbprint,
                        request.StoreName,
                        request.StoreLocation);

                    return(new CreateHardwareStationTokenServiceResponse(result));
                }
                catch (Exception ex)
                {
                    throw new SecurityException(SecurityErrors.Microsoft_Dynamics_Commerce_Runtime_HardwareStationTokenCreationFailed, ex, "Failed to create a hardware station token.");
                }
            }
        public void AssignDeviceManagementScriptToGroup()
        {
            DeviceManagementService service = TestServiceLocator.GetDeviceManagementService();

            var script = service.Get().Result;

            service.AssignToGroup(script.Id);
        }
        public void GetDeviceManagementScripts(DeviceManagementService service)
        {
            var response = service.Get();

            response.Result.Should().NotBeNull();
            response.Result.Id.Should().NotBeEmpty();

            Console.WriteLine(response.Result.Id);
        }
Exemple #5
0
 public DeviceController(IConfiguration configuration, DeviceManagementService deviceManagementService, IDeviceStateService deviceStateService,
                         IDeviceConfigurationService deviceConfigurationService, IDeviceFunctionService deviceFunctionService, DevicePluginService devicePluginService,
                         IDeviceService deviceService) : base(deviceService)
 {
     _deviceManagementService    = deviceManagementService;
     _deviceStateService         = deviceStateService;
     _deviceConfigurationService = deviceConfigurationService;
     _deviceFunctionService      = deviceFunctionService;
     _configuration       = configuration;
     _devicePluginService = devicePluginService;
 }
        public void CreateDeviceManagementScript(DeviceManagementService service)
        {
            var encoder = new EncodingHelpers();

            var deviceScript = new DeviceManagementScript
            {
                DisplayName           = $"Test {Guid.NewGuid()}",
                Datatype              = "#microsoft.graph.deviceManagementScript",
                Description           = "Test script",
                ScriptContent         = encoder.Base64Encode("echo test"),
                EnforceSignatureCheck = false,
                FileName              = "test.ps1",
                RunAsAccount          = "system"
            };

            var response = service.Create(deviceScript);

            response.Should().NotBeNull();
            response.Result.Should().NotBeNull();
            response.Result.Id.Should().NotBeEmpty();

            Console.WriteLine(response.Result.Id);
        }
 public FunctionController(IDeviceService deviceService, IDeviceFunctionService deviceFunctionService,
                           DeviceManagementService deviceManagementService) : base(deviceService)
 {
     _deviceFunctionService   = deviceFunctionService;
     _deviceManagementService = deviceManagementService;
 }
Exemple #8
0
 public DeviceFunctionApiController(IDeviceFunctionService deviceFunctionService, DeviceManagementService deviceManagementService)
 {
     _deviceFunctionService   = deviceFunctionService;
     _deviceManagementService = deviceManagementService;
 }