Exemplo n.º 1
0
        /// <summary>
        /// Validate the client.
        /// </summary>
        /// <param name="user">Defines the basic functionality of a principal object.</param>
        /// <param name="authenticationSchemes">Specifies protocols for authentication.</param>
        /// <returns>True if the client has been validated; else false.</returns>
        protected override bool ClientValidation(System.Security.Principal.IPrincipal user, AuthenticationSchemes authenticationSchemes)
        {
            // Does the user priciple exist.
            if (user != null)
            {
                // Does the user identity exist.
                if (user.Identity != null)
                {
                    // If the client was not authenticated.
                    if (!user.Identity.IsAuthenticated)
                    {
                        return(false);
                    }
                    else
                    {
                        // Select the curent Authentication Schemes
                        switch (authenticationSchemes)
                        {
                        case System.Net.AuthenticationSchemes.Basic | System.Net.AuthenticationSchemes.IntegratedWindowsAuthentication:
                        case System.Net.AuthenticationSchemes.Basic:
                        case System.Net.AuthenticationSchemes.IntegratedWindowsAuthentication:
                            // Specifies Windows authentication. Is the user in the roles
                            // then the users has been valiadted.

                            // If the authentication type is 'IntegratedWindowsAuthentication'
                            if (user.Identity is System.Security.Principal.WindowsIdentity)
                            {
                                WindowsIdentity windowsIdentity = (WindowsIdentity)user.Identity;
                                if (user.IsInRole("Administrators") || user.IsInRole("Users"))
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            // If the authentication type is 'Basic'
                            else if (user.Identity is HttpListenerBasicIdentity)
                            {
                                // The username and password are passed for
                                // Basic authentication type.
                                HttpListenerBasicIdentity httpListenerBasicIdentity = (HttpListenerBasicIdentity)user.Identity;
                                string userName = httpListenerBasicIdentity.Name;
                                string password = httpListenerBasicIdentity.Password;
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }

                        default:
                            return(false);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 public bool IsAuthorized(System.Security.Principal.IPrincipal user, IEnumerable <string> roles)
 {
     foreach (string role in roles)
     {
         if (user.IsInRole(role))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 /// <summary>Determines wether a user is permitted according to this role.</summary>
 /// <param name="user">The user to check.</param>
 /// <returns>True if the user is permitted.</returns>
 public virtual bool IsAuthorized(System.Security.Principal.IPrincipal user)
 {
     if (IsEveryone)
     {
         return(true);
     }
     else if (user != null && user.IsInRole(Role))
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 4
0
 public static bool HasUserAccess(System.Security.Principal.IPrincipal user, string requiredRole)
 {
     if ((requiredRole == null ||
          (requiredRole != null && user.Identity.IsAuthenticated && user.IsInRole(requiredRole))))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 5
0
 public bool IsAdmin(System.Security.Principal.IPrincipal principal)
 {
     return(principal != null && string.Equals(principal.Identity.Name, "Admin", System.StringComparison.InvariantCultureIgnoreCase) || principal.IsInRole("Administrators"));
 }
Exemplo n.º 6
0
 public bool IsEditor(System.Security.Principal.IPrincipal principal)
 {
     return(principal != null && principal.Identity.Name == "Editor" || principal.IsInRole("Editors"));
 }
Exemplo n.º 7
0
 public bool IsAdmin(System.Security.Principal.IPrincipal principal)
 {
     return(principal != null && principal.Identity.Name == "Admin" || principal.IsInRole("Administrators"));
 }
Exemplo n.º 8
0
        /// <summary>
        /// Validate the current client.
        /// </summary>
        /// <param name="user">The current user principal.</param>
        /// <param name="authenticationSchemes">The authentication type.</param>
        /// <returns>True if the client has been validated; else false.</returns>
        public override bool ClientValidation(System.Security.Principal.IPrincipal user, Nequeo.Security.AuthenticationType authenticationSchemes)
        {
            // Does the user priciple exist.
            if (user != null)
            {
                // Does the user identity exist.
                if (user.Identity != null)
                {
                    // Select the curent Authentication Schemes
                    switch (authenticationSchemes)
                    {
                    case Nequeo.Security.AuthenticationType.User:
                    case Nequeo.Security.AuthenticationType.Basic:
                        // If the authentication type is 'Basic'

                        // If the identity is IIdentityMember.
                        if (user.Identity is Nequeo.Security.IdentityMember)
                        {
                            // The username and password are passed for
                            // Basic authentication type.
                            Nequeo.Security.IdentityMember identityMember = (Nequeo.Security.IdentityMember)user.Identity;

                            // Return the result of the authentication.
                            return(_provider.AuthenticateUser(identityMember.GetCredentials()));
                        }

                        // If the identity is HttpListenerBasicIdentity.
                        if (user.Identity is HttpListenerBasicIdentity)
                        {
                            // The username and password are passed for
                            // Basic authentication type.
                            HttpListenerBasicIdentity httpListenerBasicIdentity = (HttpListenerBasicIdentity)user.Identity;
                            string userName = httpListenerBasicIdentity.Name;
                            string password = httpListenerBasicIdentity.Password;

                            // Create the user credentials.
                            Nequeo.Security.UserCredentials credentials = new Nequeo.Security.UserCredentials();
                            credentials.Username = userName;
                            credentials.Password = password;

                            // Return the result of the authentication.
                            return(_provider.AuthenticateUser(credentials));
                        }
                        return(false);

                    case Nequeo.Security.AuthenticationType.Integrated:
                        // If the authentication type is WindowsIdentity
                        if (user.Identity is System.Security.Principal.WindowsIdentity)
                        {
                            WindowsIdentity windowsIdentity = (WindowsIdentity)user.Identity;
                            if (user.IsInRole("Administrators") || user.IsInRole("Users"))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        break;

                    case Nequeo.Security.AuthenticationType.None:
                    case Nequeo.Security.AuthenticationType.Anonymous:
                        return(true);

                    default:
                        return(false);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        public Models.PerfilesEdicion obtenerPerfilesEdicionUsuario(System.Security.Principal.IPrincipal User, bool soyLider, int ta201_idsubareapreventa)
        {
            OpenDbConn();

            Models.PerfilesEdicion oPE = new Models.PerfilesEdicion();

            //ficepi
            oPE.idficepi = int.Parse(HttpContext.Current.Session["IDFICEPI_PC_ACTUAL"].ToString());

            //Lider
            oPE.soyLider = soyLider;

            //Administrador
            if (User.IsInRole("A") || User.IsInRole("SA"))
            {
                oPE.soyAdministrador = true;
            }

            //Super editor
            if (oPE.soyAdministrador || oPE.soyLider)
            {
                oPE.soySuperEditor = true;
            }

            //Figura área
            if (User.IsInRole("RAPREV") || User.IsInRole("DAPREV") || User.IsInRole("CAPREV") || User.IsInRole("IAPREV"))
            {
                oPE.soyFiguraArea = true;
            }

            //Figura subárea
            if (User.IsInRole("RSAPREV") || User.IsInRole("DSAPREV") || User.IsInRole("CSAPREV"))
            {
                oPE.soyFiguraSubarea = true;
            }

            //Figura subarea actual y posible lider
            DAL.SubareaPreventa    cSubarea = new DAL.SubareaPreventa(cDblib);
            Models.SubareaPreventa oSubarea = cSubarea.Select(ta201_idsubareapreventa);

            if (oSubarea != null && oSubarea.t001_idficepi_responsable == oPE.idficepi)
            {
                oPE.soyFiguraSubareaActual = true;
            }

            DAL.FiguraSubareaPreventa           cFSP   = new DAL.FiguraSubareaPreventa(cDblib);
            List <Models.FiguraSubareaPreventa> lstFSP = cFSP.ObtenerFigurasSubareaUsuario(ta201_idsubareapreventa, oPE.idficepi);

            foreach (Models.FiguraSubareaPreventa o in lstFSP)
            {
                if (o.ta203_figura == "L")
                {
                    oPE.soyPosibleLider = true;
                }
                else
                {
                    oPE.soyFiguraSubareaActual = true;
                }
            }

            //Figura area actual
            if (oSubarea != null)
            {
                DAL.AreaPreventa    cArea = new DAL.AreaPreventa(cDblib);
                Models.AreaPreventa oArea = cArea.Select(oSubarea.ta200_idareapreventa);

                if (oArea != null && oArea.t001_idficepi_responsable == oPE.idficepi)
                {
                    oPE.soyFiguraAreaActual = true;
                }

                DAL.FiguraAreaPreventa           cFAP   = new DAL.FiguraAreaPreventa(cDblib);
                List <Models.FiguraAreaPreventa> lstFAP = cFAP.ObtenerFigurasAreaUsuario(oArea.ta200_idareapreventa, oPE.idficepi);

                if (lstFAP.Count > 0)
                {
                    oPE.soyFiguraAreaActual = true;
                }
            }

            //comercial
            if (User.IsInRole("COMS"))
            {
                oPE.soyComercial = true;
            }

            return(oPE);
        }