Beispiel #1
0
        public HttpResponseMessage Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                return(apiHelper.fromEx(new HttpResponseException(HttpStatusCode.BadRequest)));
            }

            if (string.IsNullOrEmpty(login.username))
            {
                return(apiHelper.fromEx(new HttpResponseException(HttpStatusCode.BadRequest)));
            }


            try
            {
                var sec_provider = helper.get_secConfig().GetByName(login.securityProviderName);
                if (sec_provider == null)
                {
                    throw apiHelper.fromErrorString2(String.Format("El porveedor de seguridad {0} provisto no es correcto  ", login.securityProviderName), HttpStatusCode.InternalServerError);
                }

                User user = null;
                if (Fwk.Security.FwkMembership.ValidateUser(login.username, login.password, sec_provider.securityModelContext))
                {
                    user = Fwk.Security.FwkMembership.GetUser(login.username, sec_provider.securityModelContext);
                }

                if (user == null)
                {
                    throw apiHelper.fromErrorString2("El usuario no resitrado  " + login.domain, HttpStatusCode.Unauthorized);
                }

                var token = TokenGenerator.GenerateTokenJwt_ApiBot(user, login.securityProviderName);

                return(apiHelper.fromObject <string>(token));
            }
            catch (Fwk.Exceptions.TechnicalException ex)
            {
                if (ex.ErrorId == "4013")
                {
                    throw apiHelper.fromEx2(ex, HttpStatusCode.Unauthorized);
                }

                throw apiHelper.fromEx2(ex);
            }
            //catch (Exception ex)
            //{
            //    throw apiHelper.fromEx2(ex);

            //}
        }
Beispiel #2
0
        public HttpResponseMessage Authenticate(LoginRequest login)
        {
            if (login == null)
            {
                return(apiHelper.fromEx(new HttpResponseException(HttpStatusCode.BadRequest)));
            }

            if (string.IsNullOrEmpty(login.username))
            {
                return(apiHelper.fromEx(new HttpResponseException(HttpStatusCode.BadRequest)));
            }


            try
            {
                var domName = ActiveDirectoryService.Get_correct_DomainName(login.domain);
                ///Virifica contra domino
                var res = ActiveDirectoryService.User_Logon(login.username, login.password, domName);
                //var resp = apiHelper.fromObject<LoogonUserResult>(res);

                if (res.LogResult == "LOGIN_USER_OR_PASSWORD_INCORRECT")
                //    if (res.Autenticated == false)
                {
                    //return Unauthorized();
                    return(apiHelper.fromErrorString("El usuario y/o contraseña es incorrecto ", HttpStatusCode.Unauthorized));
                }

                if (res.LogResult == "LOGIN_USER_DOESNT_EXIST")
                {
                    return(apiHelper.fromErrorString("El usuario no existe en el dominio  " + login.domain, HttpStatusCode.Unauthorized));
                }

                //si la verificacion contra dominio es OK
                //busco info del dmonio
                int dom_id = MeucciDAC.GetDimainId(login.domain);



                var emmpleadoBE = MeucciDAC.VirifyUser(login.username, dom_id);

                //Emp_Id, legajo correspondiente al usuario reseteador, si devuelve NULL mostrar el mensaje “Usuario no registrado en Meucci” y cerrar aplicación.
                //o Cue_Id, cuenta correspondiente al usuario reseteador, si devuelve NULL y el campo CAIS es 0, mostrar el mensaje “Usuario no habilitado”

                if (emmpleadoBE == null)
                {
                    emmpleadoBE              = new EmpleadoReseteoBE();
                    emmpleadoBE.Emp_id       = -1;
                    emmpleadoBE.WindowsUser  = login.username;
                    emmpleadoBE.Legajo       = -1;
                    emmpleadoBE.Legajo       = -1;
                    emmpleadoBE.CAIS         = false;
                    emmpleadoBE.isRessetUser = false;
                    emmpleadoBE.Cuenta       = "";
                    emmpleadoBE.Cargo        = "";

                    //return apiHelper.fromErrorString("Usuario no registrado en Meucci", HttpStatusCode.Unauthorized);
                }

                if (string.IsNullOrEmpty(emmpleadoBE.Cuenta) && emmpleadoBE.CAIS == false)
                {
                    emmpleadoBE.isRessetUser = false;
                    //return apiHelper.fromErrorString("Usuario no habilitado ", HttpStatusCode.Unauthorized);
                }
                else
                {
                    emmpleadoBE.isRessetUser = true;
                }

                emmpleadoBE.Dominio = login.domain;

                var token = TokenGenerator.GenerateTokenJwt(emmpleadoBE);
                //return Ok(token);
                return(apiHelper.fromObject <string>(token));
            }
            catch (Exception ex)
            {
                return(apiHelper.fromEx(ex));
                //return new  System.Web.Http.Results.ExceptionResult(ex,this);
            }
        }
Beispiel #3
0
        public IActionResult authTest(LoginRequestAuth login)
        {
            ActiveDirectoryUser user = null;

            if (login == null)
            {
                return(BadRequest(new ApiErrorResponse(HttpStatusCode.BadRequest, "Los parámetros del loging no son opcionales")));
            }
            try
            {
                //var res = ActiveDirectoryService.User_Logon(login.username, login.password, login.domain);
                var res = new LoogonUserResult();
                res.Autenticated = true;
                if (res.Autenticated)
                {
                    if (login.includeDomainUserData)
                    {
                        try
                        {
                            //user = ActiveDirectoryService.User_Info(login.username, login.domain);
                            user              = new ActiveDirectoryUser();
                            user.Company      = "contoso";
                            user.Country      = "arg";
                            user.FirstName    = login.username;
                            user.LoginName    = login.username;
                            user.EmailAddress = login.username + "@contoso.co";
                        }
                        catch (Exception ex)
                        {
                            res.ErrorMessage = "No fué posible obtener datos del usuario en el dominio. Razon =  " + ex.Message;
                        }
                    }


                    List <ActiveDirectoryGroup> userGroups = null;
                    if (login.includeGroups)
                    {
                        try
                        {
                            userGroups = new List <ActiveDirectoryGroup>();
                            ActiveDirectoryGroup g = new ActiveDirectoryGroup();
                            g.CN          = "co";
                            g.Description = "co";
                            g.Name        = "contoso";
                            userGroups.Add(g);
                        }
                        catch (Exception ex)
                        {
                            res.ErrorMessage = "No fué posible obtener los grupos usuario en el dominio. Razon =  " + ex.Message;
                        }
                    }


                    var jwt = TokenGenerator.GenerateTokenJwt_test(login.username, user, userGroups);

                    res.Token = jwt;
                }

                return(Ok(res));
            }
            catch (Exception ex)
            {
                var msg = apiHelper.getMessageException(ex);
                return(BadRequest(new ApiErrorResponse(HttpStatusCode.InternalServerError, msg)));
            }
        }