コード例 #1
0
        public override ReadOnlyCollection <ClaimsIdentity> ValidateToken(SecurityToken token)
        {
            if (!(token is UserNameSecurityToken userNameToken))
            {
                throw new SecurityTokenException("The security token is not a valid username security token.");
            }

            if (DI.DefaultServiceProvider == null)
            {
                throw new InvalidOperationException("Default service provider is not initialized.");
            }

            try
            {
                IPersonService svc         = DI.DefaultServiceProvider.GetService <IPersonService>();
                var            credentials = new Credentials()
                {
                    Email    = userNameToken.UserName,
                    Password = userNameToken.Password
                };
                Task.Run(async() => await svc.AuthenticateAsync(credentials)).Wait();
                ClaimsIdentity identity = new ClaimsIdentity(AuthenticationTypes.Password);
                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userNameToken.UserName));
                identity.AddClaim(new Claim(ClaimTypes.Name, userNameToken.UserName));
                return(Array.AsReadOnly(new[] { identity }));
            }
            catch (Exception ex)
            {
                ErrorParser errorParser = DI.DefaultServiceProvider.GetService <ErrorParser>();
                ErrorList   errors      = errorParser.FromException(ex);
                throw new SecurityTokenException(errors.ErrorsText, ex);
            }
        }
コード例 #2
0
ファイル: AppSts.cs プロジェクト: ksharma7/Test
        protected override ClaimsIdentity GetOutputClaimsIdentity(ClaimsPrincipal principal, RequestSecurityToken request, Scope scope)
        {
            if (principal == null)
            {
                throw new InvalidRequestException("The caller's principal is null.");
            }
            AppStsConfig cfg = SecurityTokenServiceConfiguration as AppStsConfig;

            if (cfg == null)
            {
                throw new InvalidOperationException("SecurityTokenServiceConfiguration should be AppStsConfig");
            }
            if (!principal.Identity.IsAuthenticated || principal.Identity.Name == null)
            {
                throw new UnauthorizedAccessException("User is not authorized.");
            }

            try
            {
                IPersonService svc  = cfg.ServiceProvider.GetService <IPersonService>();
                PersonInfo     info = svc.Read(principal.Identity.Name).Result;
                return(SecurityManager.CreateIdentity(principal.Identity.AuthenticationType, info));
            }
            catch (Exception ex)
            {
                ErrorParser errorParser = cfg.ServiceProvider.GetService <ErrorParser>();
                ErrorList   errors      = errorParser.FromException(ex);
                throw new RequestFailedException(errors.ErrorsText, ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Performs asynchronous search with the current criteria and populates the list.
        /// </summary>
        /// <param name="preserveSelection">A flag indicating whether or not to preserve selection.</param>
        /// <param name="token">Cancellation token.</param>
        /// <returns>True on success, false in case of errors.</returns>
        public virtual async Task <bool> SearchAsync(bool preserveSelection, CancellationToken token = default)
        {
            if (List == null)
            {
                return(false);
            }
            try
            {
                List.Validate(true);
                ErrorList msgList = List.GetValidationErrors();
                msgList.AbortIfHasErrors();
                var res = await List.ReadAsync(new DataObject.CrudOptions {
                    PreserveSelection = preserveSelection
                }, token);

                msgList.MergeWith(res);
                Errors = msgList;
                return(!msgList.HasErrors());
            }
            catch (Exception ex)
            {
                Errors = ErrorParser.FromException(ex);
                return(false);
            }
        }
コード例 #4
0
ファイル: LoginViewCustomized.cs プロジェクト: ksharma7/Test
        protected override void Save(object sender, EventArgs e)
        {
            DetailsViewModel     dvm     = Model as DetailsViewModel;
            AuthenticationObject authObj = dvm.DetailsObject as AuthenticationObject;

            try
            {
                dvm.Save(sender, e);
                if (dvm.Errors != null && dvm.Errors.HasErrors())
                {
                    return;
                }
                PersonInfo     userInfo = dvm.ServiceProvider.GetService <IPersonService>().Read(authObj.EmailProperty.Value).Result;
                ClaimsIdentity ci       = SecurityManager.CreateIdentity(AuthenticationTypes.Password, userInfo);
                Thread.CurrentPrincipal = new ClaimsPrincipal(ci);

                MainView.Start();
                Close();
            }
            catch (Exception ex)
            {
                ErrorParser ep     = dvm.ServiceProvider.GetService <ErrorParser>();
                ErrorList   errors = ep.FromException(ex);
                ErrorPresenter.Show(errors);
            }
        }
コード例 #5
0
        private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            ErrorParser     errorParser    = Services.GetService <ErrorParser>();
            IErrorPresenter errorPresenter = Services.GetService <IErrorPresenter>();

            if (errorPresenter != null && errorParser != null)
            {
                e.Handled = true;
                errorPresenter.Show(errorParser.FromException(e.Exception));
            }
        }
コード例 #6
0
        public ActionResult Read([FromRoute] int _salesOrderId)
        {
            ActionResult response = null;

            try
            {
                if (ModelState.IsValid)
                {
                    Output <SalesOrder_ReadOutput> output = svc.Read(_salesOrderId);
                    response = StatusCode((int)output.HttpStatus, output);
                    return(response);
                }
                else
                {
                    ModelValidation.AddModelErrors(currentErrors, ModelState);
                }
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorsParser.FromException(ex));
            }
            response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors));
            return(response);
        }
コード例 #7
0
        protected override void Save(object sender, EventArgs e)
        {
            DetailsViewModel     dvm     = Model as DetailsViewModel;
            AuthenticationObject authObj = dvm.DetailsObject as AuthenticationObject;

            try
            {
                authObj.Validate(true);
                authObj.GetValidationErrors().AbortIfHasErrors();
                WcfServices.Authenticate(authObj.EmailProperty.Value, authObj.PasswordProperty.Value);
                authObj.TrackModifications = false; // to prevent confirmation on closing of the login view

                MainView.Start();
                Close();
            }
            catch (Exception ex)
            {
                ErrorParser ep     = dvm.ServiceProvider.GetService <ErrorParser>();
                ErrorList   errors = ep.FromException(ex);
                ErrorPresenter.Show(errors);
            }
        }
コード例 #8
0
 /// <summary>
 /// Performs the search with the current criteria and populates the list
 /// </summary>
 /// <param name="preserveSelection">A flag indicating whether or not to preserve selection.</param>
 /// <returns>True on success, false in case of errors.</returns>
 public virtual bool Search(bool preserveSelection)
 {
     if (List == null)
     {
         return(false);
     }
     try
     {
         List.Validate(true);
         ErrorList msgList = List.GetValidationErrors();
         msgList.AbortIfHasErrors();
         msgList.MergeWith(List.Read(new DataObject.CrudOptions {
             PreserveSelection = preserveSelection
         }));
         Errors = msgList;
         return(!msgList.HasErrors());
     }
     catch (Exception ex)
     {
         Errors = ErrorParser.FromException(ex);
         return(false);
     }
 }
コード例 #9
0
ファイル: ShipMethodController.cs プロジェクト: ksharma7/Test
        public ActionResult ReadList()
        {
            ActionResult response = null;

            try
            {
                if (ModelState.IsValid)
                {
                    Output <ICollection <ShipMethod_ReadListOutput> > output = svc.ReadList();
                    response = StatusCode((int)output.HttpStatus, output);
                    return(response);
                }
                else
                {
                    ModelValidation.AddModelErrors(currentErrors, ModelState);
                }
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorsParser.FromException(ex));
            }
            response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors));
            return(response);
        }
コード例 #10
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            if (DI.DefaultServiceProvider == null)
            {
                throw new InvalidOperationException("Default service provider is not initialized.");
            }

            try
            {
                // TODO: validate context.UserName and context.Password here.
                // Use DI.DefaultServiceProvider to access any services.
                string         user          = string.IsNullOrEmpty(context.UserName) ? "Guest" : context.UserName;
                ClaimsIdentity guestIdentity = new ClaimsIdentity();
                guestIdentity.AddClaim(new Claim(ClaimTypes.Name, user));
                context.Validated(new AuthenticationTicket(guestIdentity, new AuthenticationProperties()));
            }
            catch (Exception ex)
            {
                ErrorParser errorParser = DI.DefaultServiceProvider.GetService <ErrorParser>();
                ErrorList   errors      = errorParser.FromException(ex);
                context.SetError("invalid_grant", errors.ErrorsText);
            }
            return(Task.FromResult <object>(null));
        }
コード例 #11
0
        public ActionResult ReadList([FromRoute] int _businessEntityId)
        {
            ActionResult response = null;

            try
            {
                if (ModelState.IsValid)
                {
                    Output <ICollection <PersonCreditCard_ReadListOutput> > output = svc.ReadList(_businessEntityId);
                    response = StatusCode((int)output.HttpStatus, output);
                    return(response);
                }
                else
                {
                    ModelValidation.AddModelErrors(currentErrors, ModelState);
                }
            }
            catch (Exception ex)
            {
                currentErrors.MergeWith(errorsParser.FromException(ex));
            }
            response = StatusCode((int)currentErrors.HttpStatus, new Output(currentErrors));
            return(response);
        }