예제 #1
0
        public Task <HttpResponseMessage> ExecuteAuthorizationFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation)
        {
            if (!actionContext.ActionDescriptor.GetCustomAttributes <DontValidateApiAntiForgeryRulesAttribute>().Any())
            {
                WebReturn <bool> retr = new WebReturn <bool>();
                try
                {
                    if (actionContext == null)
                    {
                        throw new ArgumentNullException("actionContext null ( ExecuteAuthorizationFilterAsync -> ValidateJsonAntiForgeryTokenAttribute )");
                    }

                    AntiForgery.Validate(actionContext.Request.Headers.GetCookies(AntiForgeryConfig.CookieName).FirstOrDefault()[AntiForgeryConfig.CookieName].Value, actionContext.Request.Headers.GetValues("__RequestVerificationToken").FirstOrDefault());
                }
                catch (Exception ex)
                {
                    retr.Code    = 1;
                    retr.Message = ex.Message;
                    Utilitarios.CriaLogErro(ex);
                    Utilitarios.InserirLog(ex,
                                           System.Reflection.MethodInfo.GetCurrentMethod().Name,
                                           string.Join(";", System.Reflection.MethodInfo.GetCurrentMethod().GetParameters().Select(val => val.Name)),
                                           ex.GetType().Name,
                                           "ERRO NO METODO ExecuteAuthorizationFilterAsync.!!");

                    var response = actionContext.Request.CreateResponse(HttpStatusCode.Moved);
                    //response.Headers.Location = actionContext.Request.RequestUri;
                    response.Headers.Location = new Uri(new UrlHelper().Content("~") + "/Paginas/Login/Index");
                    return(FromResult(response));
                }
            }

            return(continuation());
        }
예제 #2
0
    public static PortalApiModel.RetornoTransicionarSistema TransicionarSistema(PortalApiModel.TransicionarSistema parametros)
    {
        //
        WebReturn <bool> retr = new WebReturn <bool>();

        try
        {
            PortalApiModel.RetornoTransicionarSistema retorno = new PortalApiModel.RetornoTransicionarSistema();
            //
            ControleDeAcessoTO.ObterSistemasPermitidos sistemaSelecionado;
            if (ControleDeAcesso.MODODESENVOLVIMENTO == 0)
            {
                sistemaSelecionado = ControleDeAcesso.ObterConjuntoDePermissoesUsuario(HttpContext.Current.Session).SistemasPermitidos.Where(x => x.CODSISINF == parametros.CODSISINF).FirstOrDefault();
            }
            else
            {
                sistemaSelecionado = new ControleDeAcessoTO.ObterSistemasPermitidos()
                {
                    DESURLLNK = ControleDeAcesso.URLSISTEMAMODODESENVOLVIMENTO
                }
            };
            if (sistemaSelecionado != null)
            {
                var PRIVATEKEY = GerarChavePrivada();
                var codFnc     = ControleDeAcesso.ObterConjuntoDePermissoesUsuario(HttpContext.Current.Session).InformacoesUsuario.CODFNC;
                //
                retorno.PUBLICTOKEN = Encriptar(PRIVATEKEY, new JavaScriptSerializer().Serialize(new ControleDeAcesso.ParametrosCriptografia()
                {
                    ParametrosTransicao = parametros, CODFNC = codFnc
                }));
                //
                retorno.PUBLICKEY = CalcularMD5(PRIVATEKEY);
                retorno.DESURLLNK = sistemaSelecionado.DESURLLNK + CAMINHOAPISISTEMAS + "?PUBLICKEY=" + HttpUtility.UrlEncode(retorno.PUBLICKEY) + "&PUBLICTOKEN=" + HttpUtility.UrlEncode(retorno.PUBLICTOKEN);
                //
                lock (ControleDeAcesso.PENDINGTOKENS)
                    ControleDeAcesso.PENDINGTOKENS.Add(new ControleDeAcesso.PENDINGTOKEN
                                                           ()
                    {
                        DTEXP      = DateTime.Now.AddSeconds(10),
                        PRIVATEKEY = PRIVATEKEY,
                        PUBLICKEY  = retorno.PUBLICKEY
                    });
            }
            return(retorno);
        }
        catch (Exception ex)
        {
            retr.Code    = 1;
            retr.Message = ex.Message;
            Utilitarios.CriaLogErro(ex);
            Utilitarios.InserirLog(ex,
                                   System.Reflection.MethodInfo.GetCurrentMethod().Name,
                                   string.Join(";", System.Reflection.MethodInfo.GetCurrentMethod().GetParameters().Select(val => val.Name)),
                                   ex.GetType().Name,
                                   "ERRO TRANSACIONAR SISTEMA.!!");
            return(null /* TODO Change to default(_) if this is not a reference type */);
        }
    }
    public static List <string> AutenticaUsuario(string usuario, string senha)
    {
        List <string>    retorno = new List <string>();
        WebReturn <bool> retr    = new WebReturn <bool>();

        try
        {
            if (MODODESENVOLVIMENTO != 1)
            {
                LdapConnection con = new LdapConnection(new LdapDirectoryIdentifier(CAMINHO_LDAP, PORTA_LDAP));
                con.SessionOptions.ProtocolVersion = 3;
                //
                con.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((LdapConnection l, X509Certificate x) => { return(true); });
                //
                con.Credential = new NetworkCredential(usuario, senha);
                con.AuthType   = AuthType.Negotiate;
                //
                var ldapFilter = string.Format("(&(objectCategory=person)(objectClass=user)(&(sAMAccountName={0})))", usuario);
                //
                var getUserRequest = new SearchRequest(DISTINGUISHEDNAME_LDAP, ldapFilter, SearchScope.Subtree, new[] { "MemberOf" })
                {
                    SizeLimit = 1
                };
                //
                var SearchControl = new SearchOptionsControl(SearchOption.DomainScope);
                getUserRequest.Controls.Add(SearchControl);
                //
                var userResponse = (SearchResponse)con.SendRequest(getUserRequest);
                retorno.AddRange(ObterGruposRedeUsuario(userResponse.Entries[0]));
            }
            else
            {
                //retorno.Add("SMART.GESTAOACESSOSMART");
                //retorno.Add("SMART.POS.GESTAOVISITA");
                //retorno.Add("SMART.FINANCEIRO");
                //retorno.Add("SMART.CENTRALCOMPRAS");
                //retorno.Add("SMART.PORTAL.TECNOLOGIAINFO");

                //return retorno;

                return(null);
            }
        }
        catch (Exception ex)
        {
            retr.Code    = 1;
            retr.Message = ex.Message;
            Utilitarios.CriaLogErro(ex);
            Utilitarios.InserirLog(ex,
                                   System.Reflection.MethodInfo.GetCurrentMethod().Name,
                                   string.Join(";", System.Reflection.MethodInfo.GetCurrentMethod().GetParameters().Select(val => val.Name)),
                                   ex.GetType().Name,
                                   "ERRO AUTENTICAR USUARIO SISTEMA.!!");

            return(new List <string>());
        }
        return(retorno);
    }
예제 #4
0
    public static ControleDeAcesso.ConjuntoDePermissoesUsuarioModulos ObterInformacoesUsuario(PortalApiModel.ObterInformacoesUsuario parametros)
    {
        //
        WebReturn <bool> retr = new WebReturn <bool>();

        try
        {
            ControleDeAcesso.ConjuntoDePermissoesUsuarioModulos retorno = null /* TODO Change to default(_) if this is not a reference type */;
            //
            var pendingToken = ControleDeAcesso.PENDINGTOKENS.Where(x => x.PUBLICKEY == parametros.PUBLICKEY).FirstOrDefault();
            if (pendingToken != null)
            {
                var desCriptografia             = Decriptar(pendingToken.PRIVATEKEY, parametros.PUBLICTOKEN);
                var parametrosDescriptografados = new JavaScriptSerializer().Deserialize <ControleDeAcesso.ParametrosCriptografia>(desCriptografia);
                if (parametrosDescriptografados.ParametrosTransicao.CODSISINF == parametros.CODSISINF)
                {
                    lock (ControleDeAcesso.PENDINGTOKENS)
                        ControleDeAcesso.PENDINGTOKENS.Remove(pendingToken);
                    retorno = ControleDeAcesso.ObterConjuntoDeModulosUsuario(parametrosDescriptografados.CODFNC, parametrosDescriptografados.ParametrosTransicao.CODSISINF);
                }
            }
            //
            return(retorno);
        }
        catch (Exception ex)
        {
            retr.Code    = 1;
            retr.Message = ex.Message;
            Utilitarios.CriaLogErro(ex);
            Utilitarios.InserirLog(ex,
                                   System.Reflection.MethodInfo.GetCurrentMethod().Name,
                                   string.Join(";", System.Reflection.MethodInfo.GetCurrentMethod().GetParameters().Select(val => val.Name)),
                                   ex.GetType().Name,
                                   "ERRO AO OBTER INFORMAÇÕES DO USUARIO.!!");
            return(null /* TODO Change to default(_) if this is not a reference type */);
        }
    }