예제 #1
0
        public override SearchRolesForUserRes Execute(SearchRolesForUserReq pServiceRequest)
        {
            SearchRolesForUserRes wRes = new SearchRolesForUserRes();


            wRes.BusinessData.RolList = FwkMembership.GetRolesForUser(pServiceRequest.BusinessData.Username, pServiceRequest.SecurityProviderName);
            //Implement your code here
            return(wRes);
        }
예제 #2
0
        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gridView1.GetRow(e.FocusedRowHandle) == null)
            {
                return;
            }
            CurrentUser = ((User)gridView1.GetRow(e.FocusedRowHandle));
            if (CurrentUser == null)
            {
                return;
            }

            if (OnUserChange != null)
            {
                OnUserChange(CurrentUser, FwkMembership.GetRolesForUser(CurrentUser.UserName, frmAdmin.Provider.Name));
            }
        }
예제 #3
0
        /// <summary>
        /// Actualiza los datos del usuario.
        /// </summary>
        /// <param name="pUser">Usuario que se desea actualizar.</param>
        /// <param name="userName">Nombre no modificado del usuario.- El nuevo nombre de usuario en caso de modifucacion     va en el parametro pUser </param>
        public void Update(User pUser, string userName)
        {
            Validate(pUser, false);


            // Actualizacion del usuario de las membership
            FwkMembership.UpdateUser(pUser, userName, _ProviderName);

            // Se actualizan los roles que posee el usuario
            if (pUser.Roles != null)
            {
                RolList usrRoles = FwkMembership.GetRolesForUser(pUser.UserName, _ProviderName);
                FwkMembership.RemoveUserFromRoles(pUser.UserName, usrRoles, _ProviderName);
                RolList newRolList = pUser.GetRolList();
                FwkMembership.CreateRolesToUser(newRolList, pUser.UserName, _ProviderName);
            }
        }
예제 #4
0
        private void btnAsignarRoles_Click(object sender, EventArgs e)
        {
            if (usersGrid1.CurrentUser == null)
            {
                return;
            }
            RolList wNewRolList = new RolList();

            using (new WaitCursorHelper(this))
            {
                foreach (object obj in lstBoxRoles.CheckedItems)
                {
                    wNewRolList.Add((Rol)obj);
                }

                try
                {
                    if (selectedRolList != null)
                    {
                        FwkMembership.RemoveUserFromRoles(usersGrid1.CurrentUser.UserName, selectedRolList, frmAdmin.Provider.Name);
                        selectedRolList = null;
                    }
                    FwkMembership.CreateRolesToUser(wNewRolList, usersGrid1.CurrentUser.UserName, frmAdmin.Provider.Name);
                    selectedRolList = wNewRolList;
                }
                catch (Exception ex)
                {
                    if (((Fwk.Exceptions.TechnicalException)ex).InnerException != null)
                    {
                        MessageBox.Show(((Fwk.Exceptions.TechnicalException)ex).InnerException.Message);
                    }

                    else
                    {
                        MessageBox.Show(ex.Message);
                    }
                }

                bindingSourceUserRole.DataSource = FwkMembership.GetRolesForUser(usersGrid1.CurrentUser.UserName, frmAdmin.Provider.Name);

                NewSecurityInfoCreatedHandler();
            }
        }
예제 #5
0
        public override AuthenticateUserRes Execute(AuthenticateUserReq pServiceRequest)
        {
            AuthenticateUserRes wRes = new AuthenticateUserRes();
            UserBC  wUserBC          = new UserBC(pServiceRequest.ContextInformation.AppId, pServiceRequest.SecurityProviderName);
            RolList wRolList         = new RolList();
            User    wUser            = new User();

            switch (pServiceRequest.BusinessData.AuthenticationMode)
            {
            case AuthenticationModeEnum.ASPNETMemberShips:
            {
                wUserBC.AuthenticateUser(pServiceRequest.BusinessData.UserName,
                                         pServiceRequest.BusinessData.Password,
                                         out wUser);

                wRolList = FwkMembership.GetRolesForUser(pServiceRequest.BusinessData.UserName, pServiceRequest.SecurityProviderName);

                break;
            }

            case AuthenticationModeEnum.LDAP:
            case AuthenticationModeEnum.FingerPrint:
            case AuthenticationModeEnum.Mixed:
            case AuthenticationModeEnum.WindowsIntegrated:
            {
                throw new Fwk.Exceptions.FunctionalException("Metodo de autenticacion no soportado por el servicio de autenticacion ASPNETMemberShips");
            }
            }
            if (wUser.MustChangePassword == null)
            {
                wUser.MustChangePassword = false;
            }

            wRes.BusinessData.UserInfo       = wUser;
            wRes.BusinessData.UserInfo.Roles = wRolList.GetArrayNames();
            wRes.BusinessData.UserInfo.AuthenticationMode = pServiceRequest.BusinessData.AuthenticationMode;
            return(wRes);
        }
예제 #6
0
        public override AuthenticateUserRes Execute(AuthenticateUserReq pServiceRequest)
        {
            AuthenticateUserRes wRes = new AuthenticateUserRes();
            UserBC  wUserBC          = new UserBC(pServiceRequest.ContextInformation.AppId, pServiceRequest.SecurityProviderName);
            RolList wRolList         = new RolList();
            User    wUser            = new User();

            switch (pServiceRequest.BusinessData.AuthenticationMode)
            {
            case AuthenticationModeEnum.LDAP:
                //Se debe validar el usuario en LDAP contra el dominio seleccionado
                //wRes.BusinessData.UserInfo = wUserBC.AuthenticateUser(pServiceRequest.BusinessData.UserName, pServiceRequest.BusinessData.Password, pServiceRequest.BusinessData.Domain, pServiceRequest.BusinessData.SiteName);

                if (wUserBC.AuthenticateUser_AD(pServiceRequest.BusinessData.UserName,
                                                pServiceRequest.BusinessData.Password,
                                                pServiceRequest.BusinessData.Domain)
                    == Fwk.Security.ActiveDirectory.LoginResult.LOGIN_OK)
                {
                    wUserBC.GetUserByParams(pServiceRequest.BusinessData.UserName, out wUser, out wRolList);
                }

                // Cuando es autenticación de windows, nunca debe pedir que cambie el password
                wRes.BusinessData.UserInfo.MustChangePassword = false;
                break;

            case AuthenticationModeEnum.Mixed:
                //utiliza autenticación mixta. Valida contra el usuario de memberships
                ///wRes.BusinessData.UserInfo = wUserBC.AuthenticateUser(pServiceRequest.BusinessData.UserName, pServiceRequest.BusinessData.Password, pServiceRequest.BusinessData.SiteName);

                //utiliza autenticación mixta. Valida contra el usuario de bigbang
                wUserBC.AuthenticateUser(pServiceRequest.BusinessData.UserName,
                                         pServiceRequest.BusinessData.Password,
                                         out wUser);

                wRolList = FwkMembership.GetRolesForUser(pServiceRequest.BusinessData.UserName, pServiceRequest.SecurityProviderName);

                break;

            case AuthenticationModeEnum.WindowsIntegrated:
                // el modo de autenticación es integrada de windows (usuario por defecto o validación LDAP)
                if (pServiceRequest.BusinessData.IsEnvironmentUser)
                {
                    // el usuario se toma por defecto del environment por tanto se recupera el user info sin necesidad de validar
                    // El usuario se toma por defecto del environment por tanto se recupera el user info sin necesidad de validar
                    wUserBC.GetUserByParams(pServiceRequest.BusinessData.UserName, out wUser, out wRolList);
                }
                else
                {
                    //Se debe validar el usuario en LDAP contra el dominio seleccionado
                    //wRes.BusinessData.UserInfo = wUserBC.AuthenticateUser(pServiceRequest.BusinessData.UserName, pServiceRequest.BusinessData.Password, pServiceRequest.BusinessData.Domain, pServiceRequest.BusinessData.SiteName);
                    if (wUserBC.AuthenticateUser_AD(pServiceRequest.BusinessData.UserName,
                                                    pServiceRequest.BusinessData.Password,
                                                    pServiceRequest.BusinessData.Domain)
                        == Fwk.Security.ActiveDirectory.LoginResult.LOGIN_OK)
                    {
                        wUserBC.GetUserByParams(pServiceRequest.BusinessData.UserName, out wUser, out wRolList);
                    }
                }
                // Cuando es autenticación de windows, nunca debe pedir que cambie el password de las memberships
                wRes.BusinessData.UserInfo.MustChangePassword = false;
                break;

            default:
                throw new NotImplementedException("Modo de autenticación no implementado");
            }
            if (wUser.MustChangePassword == null)
            {
                wUser.MustChangePassword = false;
            }
            wRes.BusinessData.UserInfo       = wUser;
            wRes.BusinessData.UserInfo.Roles = wRolList.GetArrayNames();
            wRes.BusinessData.UserInfo.AuthenticationMode = pServiceRequest.BusinessData.AuthenticationMode;
            return(wRes);
        }
예제 #7
0
        public override UpdateProfesionalRes Execute(UpdateProfesionalReq pServiceRequest)
        {
            RolList lst = null;
            UpdateProfesionalRes wRes = new UpdateProfesionalRes();

            pServiceRequest.BusinessData.profesional.LastAccessUserId         = Guid.Parse(pServiceRequest.ContextInformation.UserId);
            pServiceRequest.BusinessData.profesional.Persona.LastAccessUserId = Guid.Parse(pServiceRequest.ContextInformation.UserId);
            ProfesionalesDAC.Update(pServiceRequest.BusinessData.profesional);
            ///Ejemplo
            //A = 1,2,3, existent_roles
            //B = 2,3,5,  vienen del servicio q son los que quedan
            //B-A = 5, roles a agregar
            //A-B = 1, roles a eliminar
            #region ROLES A NIVEL DE SF
            if (pServiceRequest.BusinessData.User != null)
            {
                //Elimino todos los roles del usuario
                Fwk.Security.Common.RolList rolList_sf_A = FwkMembership.GetRolesForUser(pServiceRequest.BusinessData.User.UserName, pServiceRequest.SecurityProviderName);
                var roles_sf_A_ids = from r in rolList_sf_A select r.RolName;
                var roles_sf_B_ids = from r in pServiceRequest.BusinessData.User.GetRolList() where r.RolName.StartsWith("sf_") select r.RolName;

                //A-B roles a eliminar
                var roles_To_Delette_ids = roles_sf_A_ids.Except <string>(roles_sf_B_ids);

                if (roles_To_Delette_ids.Count() != 0)
                {
                    lst = new RolList();

                    var to_remove = rolList_sf_A.Where(r => roles_To_Delette_ids.Contains(r.RolName.Trim()));
                    lst.AddRange(to_remove);
                    FwkMembership.RemoveUserFromRoles(pServiceRequest.BusinessData.User.UserName, lst, pServiceRequest.SecurityProviderName);
                }

                //A-B roles a eliminar
                var roles_To_Add_ids = roles_sf_B_ids.Except <string>(roles_sf_A_ids);


                //B-A  roles a agregar
                if (roles_To_Add_ids.Count() != 0)
                {
                    lst = new RolList();
                    foreach (string rolName in roles_To_Add_ids)
                    {
                        lst.Add(new Rol(rolName));
                    }
                    //Asigno los nuevos roles del usuario
                    FwkMembership.CreateRolesToUser(lst, pServiceRequest.BusinessData.User.UserName, pServiceRequest.SecurityProviderName);
                }
                #endregion

                #region ROLES A NIVEL INSTITUCIONAL
                if (pServiceRequest.BusinessData.HealthInstitutionId.HasValue)
                {
                    Guid userId = new Guid(pServiceRequest.BusinessData.User.ProviderId.ToString());
                    ///Obtener los roles asignados previamente
                    string[] existent_roles_A = ProfesionalesDAC.Get_HealtInstitute_UsersInRoles(userId, pServiceRequest.BusinessData.HealthInstitutionId.Value);
                    //vienen del servicio q son los que quedan
                    var roles_B = from r in pServiceRequest.BusinessData.User.GetRolList() where r.RolName.StartsWith("inst_") select r.RolName;
                    //Agregar
                    foreach (string rolName in roles_B.Except(existent_roles_A))
                    {
                        HealthInstitutionDAC.Profesional_UsersInRoles_Assign(
                            pServiceRequest.BusinessData.HealthInstitutionId.Value,
                            pServiceRequest.BusinessData.profesional.IdProfesional,
                            userId,
                            rolName);
                    }
                    //Quitar roles
                    foreach (string rolName in existent_roles_A.Except(roles_B))
                    {
                        HealthInstitutionDAC.Profesional_RemoveRol(
                            pServiceRequest.BusinessData.HealthInstitutionId.Value,
                            pServiceRequest.BusinessData.profesional.IdProfesional,
                            userId, rolName);
                    }
                }
            }
            return(wRes);
        }
예제 #8
0
 /// <summary>
 /// Obtiene la informacion de un usuario y su Custom de un usuario, junto a sus roles
 /// </summary>
 /// <param name="pUserName"></param>
 /// <param name="pRolList"></param>
 /// <returns></returns>
 public void GetUserByParams(String pUserName, out User pUser, out RolList pRolList)
 {
     pUser    = FwkMembership.GetUser(pUserName, _ProviderName);
     pRolList = FwkMembership.GetRolesForUser(pUserName, _ProviderName);
 }