Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="domain"></param>
        /// <returns></returns>
        public String Authenticate(string username, string password, string domain)
        {
            FunctionalException fe = null;

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

                if (res.LogResult == "LOGIN_USER_OR_PASSWORD_INCORRECT")
                //    if (res.Autenticated == false)
                {
                    fe         = new FunctionalException("El usuario y/o contraseña es incorrecto");
                    fe.ErrorId = HttpStatusCode.Unauthorized.ToString();
                    throw fe;
                    //return BadRequest(new ApiErrorResponse(HttpStatusCode.Unauthorized, "El usuario y/o contraseña es incorrecto"));
                }

                if (res.LogResult == "LOGIN_USER_DOESNT_EXIST")
                {
                    fe         = new FunctionalException("El usuario no existe en el dominio ");
                    fe.ErrorId = HttpStatusCode.Unauthorized.ToString();
                    throw fe;
                    //return BadRequest(new ApiErrorResponse(HttpStatusCode.Unauthorized, "El usuario no existe en el dominio "));
                }

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



                var emmpleadoBE = MeucciDAC.VirifyUser(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)
                {
                    fe         = new FunctionalException("Usuario no registrado en Meucci ");
                    fe.ErrorId = HttpStatusCode.Unauthorized.ToString();
                    throw fe;
                    //return BadRequest(new ApiErrorResponse(HttpStatusCode.Unauthorized, "Usuario no registrado en Meucci "));
                }

                if (string.IsNullOrEmpty(emmpleadoBE.Cuenta) && emmpleadoBE.CAIS == false)
                {
                    fe         = new FunctionalException("Usuario no habilitado ");
                    fe.ErrorId = HttpStatusCode.Unauthorized.ToString();
                    throw fe;
                    //return BadRequest(new ApiErrorResponse(HttpStatusCode.Unauthorized, "Usuario no habilitado"));
                }
                emmpleadoBE.Dominio = domain;


                var jwtTokenString = TokenGenerator.GenerateTokenMeucci(emmpleadoBE);
                return(jwtTokenString);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #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);
            }
        }