Exemple #1
0
 private Credential EncryptCredentials(CredentialBase creds)
 {
     if (creds == null)
     {
         return(Credential.get_Empty());
     }
     using (RSACryptoServiceProvider crypoService = this.CreateCrypoService())
         return(new Credential(creds, (RSA)crypoService));
 }
 public OneTimeJobResult <T> ExecuteJobAndGetResult <T>(
     int engineId,
     JobDescription jobDescription,
     CredentialBase jobCredential,
     JobResultDataFormatType resultDataFormat,
     string jobType)
     where T : class, new()
 {
     return(this.ExecuteJobAndGetResult <T>(this.engineDal.GetEngine(engineId).get_ServerName(), jobDescription, jobCredential, resultDataFormat, jobType));
 }
 public OneTimeJobResult <T> ExecuteJobAndGetResult <T>(
     string engineName,
     JobDescription jobDescription,
     CredentialBase jobCredential,
     JobResultDataFormatType resultDataFormat,
     string jobType)
     where T : class, new()
 {
     this.RouteJobToEngine(jobDescription, engineName);
     using (OneTimeJobRawResult timeJobRawResult = this.oneTimeJobManager.ExecuteJob(jobDescription, jobCredential))
     {
         string error = timeJobRawResult.Error;
         if (!timeJobRawResult.Success)
         {
             OneTimeJobService.log.WarnFormat(jobType + " credential test failed: " + timeJobRawResult.Error, Array.Empty <object>());
             string messageFromException = this.GetLocalizedErrorMessageFromException(timeJobRawResult.ExceptionFromJob);
             return(new OneTimeJobResult <T>()
             {
                 Success = false,
                 Message = string.IsNullOrEmpty(messageFromException) ? error : messageFromException
             });
         }
         try
         {
             T obj;
             if (resultDataFormat == JobResultDataFormatType.Xml)
             {
                 using (XmlTextReader xmlTextReader = new XmlTextReader(timeJobRawResult.JobResultStream))
                 {
                     xmlTextReader.Namespaces = false;
                     obj = (T) new XmlSerializer(typeof(T)).Deserialize((XmlReader)xmlTextReader);
                 }
             }
             else
             {
                 obj = SerializationHelper.Deserialize <T>(timeJobRawResult.JobResultStream);
             }
             return(new OneTimeJobResult <T>()
             {
                 Success = true,
                 Value = obj
             });
         }
         catch (Exception ex)
         {
             OneTimeJobService.log.Error((object)string.Format("Failed to deserialize {0} credential test job result: {1}", (object)jobType, (object)ex));
             return(new OneTimeJobResult <T>()
             {
                 Success = false,
                 Message = this.GetLocalizedErrorMessageFromException(timeJobRawResult.ExceptionFromJob)
             });
         }
     }
 }
        /// <summary>
        /// 构造认证子类型实例
        /// </summary>
        /// <param name="credential"></param>
        /// <returns></returns>
        public IAuthenticator Create(CredentialBase credential)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            var result = (IAuthenticator)Activator.CreateInstance(Type.GetType(AuthenticationConfigurationFacade.AuthenticatorTypeName));

            result.Provider = new AuthenticationProviderFactory().Create(credential);
            return(result);
        }
        // Token: 0x060005A4 RID: 1444 RVA: 0x00022070 File Offset: 0x00020270
        private Credential EncryptCredentials(CredentialBase creds)
        {
            if (creds == null)
            {
                return(Credential.Empty);
            }
            Credential result;

            using (RSACryptoServiceProvider rsacryptoServiceProvider = this.CreateCrypoService())
            {
                result = new Credential(creds, rsacryptoServiceProvider);
            }
            return(result);
        }
Exemple #6
0
 public virtual IIdentity Verify(CredentialBase credential)
 {
     if ((credential == null) || (credential.GetType() != CredentialType))
     {
         throw new ArgumentException("credential");
     }
     return(new IdentityMock()
     {
         AuthenticationType = AuthenticationType,
         Name = Name,
         State = State,
         IsAuthenticated = true
     });
 }
Exemple #7
0
 public virtual void Handle(CredentialBase credential)
 {
     if (credential == null)
     {
         throw new ArgumentNullException("credential");
     }
     if (Policy.IsMatch(credential))
     {
         Trace.WriteLine(string.Format(Resources.OutputFormat, "Handler", GetType().Name, GetValue().ToString()));
     }
     if (Successor != null)
     {
         Successor.Handle(credential);
     }
 }
        /// <summary>
        /// 默认的认证过程
        /// </summary>
        /// <param name="credential"></param>
        /// <returns></returns>
        public virtual IIdentity Authenticate(CredentialBase credential)
        {
            Trace.WriteLine("credential type is " + credential.GetType().Name);
            // 正常的验证过程
            var result = Provider.Verify(credential);

            // 非功能性控制策略);
            if (AuthenticationConfigurationFacade.HandlerCoR != null)
            {
                AuthenticationConfigurationFacade.HandlerCoR.Handle(credential);
            }

            Trace.WriteLine("authentication result : " + result);
            return(result);
        }
Exemple #9
0
        public override IIdentity Verify(CredentialBase credential)
        {
            var adapter = new UsbAdapter();

            if (!adapter.IsOpen)
            {
                adapter.Open();
            }
            if (credential.GetType() != adapter.GetCredential(UsbAdapter.Pin).GetType())
            {
                throw new NotSupportedException();
            }
            var result = base.Verify(credential);

            adapter.Close();
            return(result);
        }
        /// <summary>
        /// 根据认证凭证类型选择合适的Provider
        /// </summary>
        /// <param name="credential"></param>
        /// <returns></returns>
        public IAuthenticationProvider Create(CredentialBase credential)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            Type providerType;

            if (AuthenticationConfigurationFacade.Providers.TryGetValue(credential.GetType(), out providerType))
            {
                return((IAuthenticationProvider)Activator.CreateInstance(providerType));
            }
            else
            {
                throw new NotSupportedException(credential.GetType().Name);
            }
        }
        public bool IsMatch(CredentialBase credential)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            bool result;

            if (ApplyToCredentialTypes.Count == 0)
            {
                result = false;
            }
            else
            {
                result = ApplyToCredentialTypes.Contains(credential.GetType());
            }
            if (result)
            {
                Trace.WriteLine(string.Format(Resources.OutputFormat, "Policy", GetType().Name, "match"));
            }
            return(result);
        }
Exemple #12
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 private void Initialize()
 {
     Group  = null;
     Member = null;
 }
Exemple #13
0
 public override Task <bool> SignInAsync(CredentialBase credential) => SignInAsync(credential.Password);
        // Token: 0x060005C0 RID: 1472 RVA: 0x00022798 File Offset: 0x00020998
        public OneTimeJobResult <T> ExecuteJobAndGetResult <T>(string engineName, JobDescription jobDescription, CredentialBase jobCredential, JobResultDataFormatType resultDataFormat, string jobType) where T : class, new()
        {
            this.RouteJobToEngine(jobDescription, engineName);
            OneTimeJobResult <T> result;

            using (OneTimeJobRawResult oneTimeJobRawResult = this.oneTimeJobManager.ExecuteJob(jobDescription, jobCredential))
            {
                string error = oneTimeJobRawResult.Error;
                if (!oneTimeJobRawResult.Success)
                {
                    OneTimeJobService.log.WarnFormat(jobType + " credential test failed: " + oneTimeJobRawResult.Error, Array.Empty <object>());
                    string localizedErrorMessageFromException = this.GetLocalizedErrorMessageFromException(oneTimeJobRawResult.ExceptionFromJob);
                    result = new OneTimeJobResult <T>
                    {
                        Success = false,
                        Message = (string.IsNullOrEmpty(localizedErrorMessageFromException) ? error : localizedErrorMessageFromException)
                    };
                }
                else
                {
                    try
                    {
                        T value;
                        if (resultDataFormat == JobResultDataFormatType.Xml)
                        {
                            using (XmlTextReader xmlTextReader = new XmlTextReader(oneTimeJobRawResult.JobResultStream))
                            {
                                xmlTextReader.Namespaces = false;
                                value = (T)((object)new XmlSerializer(typeof(T)).Deserialize(xmlTextReader));
                                goto IL_CF;
                            }
                        }
                        value = SerializationHelper.Deserialize <T>(oneTimeJobRawResult.JobResultStream);
IL_CF:
                        result = new OneTimeJobResult <T>
                        {
                            Success = true,
                            Value   = value
                        };
                    }
                    catch (Exception arg)
                    {
                        OneTimeJobService.log.Error(string.Format("Failed to deserialize {0} credential test job result: {1}", jobType, arg));
                        result = new OneTimeJobResult <T>
                        {
                            Success = false,
                            Message = this.GetLocalizedErrorMessageFromException(oneTimeJobRawResult.ExceptionFromJob)
                        };
                    }
                }
            }
            return(result);
        }
 public bool IsMatch(CredentialBase credential)
 {
     Trace.WriteLine(string.Format(Resources.OutputFormat, "Policy", GetType().Name, "match"));
     return(true);
 }
Exemple #16
0
        public OneTimeJobRawResult ExecuteJob(
            JobDescription jobDescription,
            CredentialBase jobCredential = null)
        {
            if (this.listenerUri == string.Empty)
            {
                JobSchedulerEventServicev2.log.Error((object)"ListenerUri remains uninitialized");
                return(new OneTimeJobRawResult()
                {
                    Success = false,
                    Error = Resources.get_TestErrorJobFailed()
                });
            }
            if (jobCredential != null)
            {
                jobDescription.set_Credential(this.EncryptCredentials(jobCredential));
            }
            if (jobDescription.get_SupportedRoles() == null)
            {
                jobDescription.set_SupportedRoles((PackageType)7);
            }
            ScheduledJob scheduledJob = new ScheduledJob();

            scheduledJob.set_NotificationAddress(this.listenerUri);
            scheduledJob.set_State("CoreOneTimeJob");
            scheduledJob.set_RunOnce(true);
            scheduledJob.set_IsOneShot(true);
            scheduledJob.set_Job(jobDescription);
            ScheduledJob job = scheduledJob;
            Guid         scheduler;

            try
            {
                scheduler = this.SubmitScheduledJobToScheduler(job);
                OneTimeJobManager.Logger.DebugFormat("Job {0} scheduled", (object)scheduler);
            }
            catch (Exception ex)
            {
                OneTimeJobManager.Logger.ErrorFormat("Failed to submit job: {0}", (object)ex);
                OneTimeJobRawResult timeJobRawResult = new OneTimeJobRawResult();
                timeJobRawResult.Success          = false;
                timeJobRawResult.Error            = Resources.get_TestErrorJobFailed();
                timeJobRawResult.ExceptionFromJob = ex;
                timeJobRawResult = timeJobRawResult;
                return(timeJobRawResult);
            }
            TimeSpan timeout = jobDescription.get_Timeout().Add(this.jobTimeoutTolerance);

            OneTimeJobManager.PendingJobItem pendingJobItem = new OneTimeJobManager.PendingJobItem();
            this.pendingJobs[scheduler] = pendingJobItem;
            if (this.JobStarted != null)
            {
                this.JobStarted((object)this, (EventArgs) new OneTimeJobManager.JobStartedEventArgs(scheduler));
            }
            OneTimeJobRawResult timeJobRawResult1;

            if (pendingJobItem.WaitHandle.WaitOne(timeout))
            {
                timeJobRawResult1 = pendingJobItem.RawResult;
            }
            else
            {
                OneTimeJobManager.Logger.ErrorFormat("No result from job {0} received before timeout ({1})", (object)scheduler, (object)timeout);
                timeJobRawResult1 = new OneTimeJobRawResult()
                {
                    Success = false,
                    Error   = Resources.get_TestErrorTimeout()
                };
            }
            this.pendingJobs.TryRemove(scheduler, out pendingJobItem);
            return(timeJobRawResult1);
        }
        // Token: 0x060005A6 RID: 1446 RVA: 0x00022104 File Offset: 0x00020304
        public OneTimeJobRawResult ExecuteJob(JobDescription jobDescription, CredentialBase jobCredential = null)
        {
            if (this.listenerUri == string.Empty)
            {
                JobSchedulerEventServicev2.log.Error("ListenerUri remains uninitialized");
                OneTimeJobRawResult result = new OneTimeJobRawResult
                {
                    Success = false,
                    Error   = Resources.TestErrorJobFailed
                };
                return(result);
            }
            if (jobCredential != null)
            {
                jobDescription.Credential = this.EncryptCredentials(jobCredential);
            }
            if (jobDescription.SupportedRoles == null)
            {
                jobDescription.SupportedRoles = 7;
            }
            ScheduledJob job = new ScheduledJob
            {
                NotificationAddress = this.listenerUri,
                State     = "CoreOneTimeJob",
                RunOnce   = true,
                IsOneShot = true,
                Job       = jobDescription
            };
            Guid guid;

            try
            {
                guid = this.SubmitScheduledJobToScheduler(job);
                OneTimeJobManager.Logger.DebugFormat("Job {0} scheduled", guid);
            }
            catch (Exception ex)
            {
                OneTimeJobManager.Logger.ErrorFormat("Failed to submit job: {0}", ex);
                OneTimeJobRawResult result = default(OneTimeJobRawResult);
                result.Success          = false;
                result.Error            = Resources.TestErrorJobFailed;
                result.ExceptionFromJob = ex;
                return(result);
            }
            TimeSpan timeSpan = jobDescription.Timeout.Add(this.jobTimeoutTolerance);

            OneTimeJobManager.PendingJobItem pendingJobItem = new OneTimeJobManager.PendingJobItem();
            this.pendingJobs[guid] = pendingJobItem;
            if (this.JobStarted != null)
            {
                this.JobStarted(this, new OneTimeJobManager.JobStartedEventArgs(guid));
            }
            OneTimeJobRawResult result2;

            if (pendingJobItem.WaitHandle.WaitOne(timeSpan))
            {
                result2 = pendingJobItem.RawResult;
            }
            else
            {
                OneTimeJobManager.Logger.ErrorFormat("No result from job {0} received before timeout ({1})", guid, timeSpan);
                result2 = new OneTimeJobRawResult
                {
                    Success = false,
                    Error   = Resources.TestErrorTimeout
                };
            }
            this.pendingJobs.TryRemove(guid, out pendingJobItem);
            return(result2);
        }