示例#1
0
        public bool AddRole(RoleBE role)
        {
            CommonDAL     commondal = new CommonDAL();
            SqlConnection con       = commondal.Connection();
            SqlCommand    cmd       = new SqlCommand();

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Sp_UM_RolesInsert";

            cmd.Parameters.Add("@RoleShortDesc", SqlDbType.VarChar).Value = role.RoleShortDesc;
            cmd.Parameters.Add("@RoleLongDesc", SqlDbType.VarChar).Value  = role.RoleLongDesc;
            cmd.Parameters.Add("@LastModifiedBy", SqlDbType.Int).Value    = role.LastModifiedBy;
            cmd.Connection = con;

            //con.Open();
            int count = cmd.ExecuteNonQuery();

            con.Close();

            if (count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        //protected void btnUpdate_Click(object sender, EventArgs e)
        //{
        //    RoleBE role = new RoleBE();
        //    RoleBAL roleBAL = new RoleBAL();


        //    role.RoleId = Convert.ToInt32(hdnRoleUpdateId.Value);
        //    //role.RoleShortDesc = txtRoleShortDesc.Text;
        //    //role.RoleLongDesc = txtRolelongDesc.Text;
        //    role.LastModifiedBy = ((UserBE)Session["LoggedInUser"]).UserId;
        //    if (roleBAL.ModifyRole(role))
        //    {
        //        LvRoleItems.EditIndex = -1;
        //        bind();
        //        recalcNoOfPages();
        //        LoggedIn master = (LoggedIn)this.Master;
        //        master.ShowMessage("Role successfully Updated.", true);
        //    }
        //    else
        //    {
        //        LoggedIn master = (LoggedIn)this.Master;
        //        master.ShowMessage("Unsuccessful", true);
        //    }

        //}

        //protected void btnCancel_Click(object sender, EventArgs e)
        //{
        //    LvRoleItems.EditIndex = -1;
        //    bind();
        //    recalcNoOfPages();
        //}

        protected void btnDeleteYes_Click(object sender, EventArgs e)
        {
            RoleBE  role    = new RoleBE();
            RoleBAL roleBAL = new RoleBAL();
            int     RoleId  = Convert.ToInt32(hdnRoleId.Value);

            role.RoleId = Convert.ToInt32(RoleId);
            if (roleBAL.DeleteRole(role))
            {
                if (LvRoleItems.Items.Count == 1)
                {
                    RoleDataPager.SetPageProperties(RoleDataPager.TotalRowCount - RoleDataPager.PageSize - 1,
                                                    RoleDataPager.PageSize, true);
                    bind();
                    recalcNoOfPages();
                    LoggedIn master = (LoggedIn)this.Master;
                    master.ShowMessage("Role successfully deleted.", true);
                }
                else
                {
                    LvRoleItems.EditIndex = -1;
                    bind();
                    recalcNoOfPages();
                    LoggedIn master = (LoggedIn)this.Master;
                    master.ShowMessage("Role successfully deleted.", true);
                }
            }
            else
            {
                LoggedIn master = (LoggedIn)this.Master;
                master.ShowMessage("Sorry You cannot delete Role because it is already in use", false);
                recalcNoOfPages();
            }
        }
示例#3
0
        public static XDoc GetGroupXmlVerbose(GroupBE group, string relation)
        {
            XDoc groupXml = GetGroupXml(group, relation);

            ServiceBE authService = ServiceBL.GetServiceById(group.ServiceId);

            if (authService != null)
            {
                groupXml.Add(ServiceBL.GetServiceXml(authService, "authentication"));
            }

            groupXml.Start("users");
            if (group.UserIdsList != null)
            {
                groupXml.Attr("count", group.UserIdsList.Length);
            }

            groupXml.Attr("href", DekiContext.Current.ApiUri.At("groups", group.Id.ToString(), "users"));
            groupXml.End();

            //Permissions for the group
            RoleBE role = PermissionsBL.GetRoleById(group.RoleId);

            groupXml.Add(PermissionsBL.GetRoleXml(role, "group"));
            return(groupXml);
        }
        void UCRoleAddList_btnUpdateClick(object sender, EventArgs e)
        {
            RoleBE  role    = new RoleBE();
            RoleBAL roleBAL = new RoleBAL();


            role.RoleId        = Convert.ToInt32(hdnRoleUpdateId.Value);
            role.RoleShortDesc = UCRoleAddList.ShortDesc;
            role.RoleLongDesc  = UCRoleAddList.LongDesc;

            role.LastModifiedBy = ((UserBE)Session["LoggedInUser"]).UserId;
            if (roleBAL.ModifyRole(role))
            {
                LoggedIn master = (LoggedIn)this.Master;
                master.ShowMessage("Role successfully Updated.", true);
                LvRoleItems.EditIndex = -1;
                bind();
                recalcNoOfPages();
            }
            else
            {
                LoggedIn master = (LoggedIn)this.Master;
                master.ShowMessage("Unsuccessful", true);
            }
        }
示例#5
0
        public bool ViewRole(RoleBE role)
        {
            CommonDAL     commondal = new CommonDAL();
            SqlConnection con       = commondal.Connection();
            DataTable     dt        = new DataTable();

            SqlDataAdapter da = new SqlDataAdapter("Sp_UM_GetAllRolesByRoleID", con);

            da.SelectCommand.CommandType = CommandType.StoredProcedure;

            SqlParameter p1 = new SqlParameter("@RoleId ", SqlDbType.Int);

            p1.Direction = ParameterDirection.Input;
            p1.Value     = role.RoleId;
            da.SelectCommand.Parameters.Add(p1);

            da.Fill(dt);

            if (dt.Rows.Count > 0)
            {
                //string title = ds.Tables[0].Rows[0]["Title"].ToString();
                role.RoleShortDesc = dt.Rows[0]["RoleLongDesc"].ToString();
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#6
0
        public bool DeleteRole(RoleBE role)
        {
            int msg = 0;

            SqlCommand    cmd       = new SqlCommand();
            CommonDAL     commondal = new CommonDAL();
            SqlConnection con       = commondal.Connection();

            cmd             = new SqlCommand("Sp_UM_RolesDelete", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@RoleId", SqlDbType.Int).Value = role.RoleId;
            cmd.Parameters.Add("@ReturnCode", System.Data.SqlDbType.Int);
            cmd.Parameters["@ReturnCode"].Direction = ParameterDirection.Output;

            //con.Open();
            int count = cmd.ExecuteNonQuery();

            msg = Convert.ToInt32(cmd.Parameters["@ReturnCode"].Value);
            con.Close();

            if (msg == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public Yield GetSiteRole(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            RoleBE role = GetRoleFromUrl();
            XDoc   ret  = PermissionsBL.GetRoleXml(role, null);

            response.Return(DreamMessage.Ok(ret));
            yield break;
        }
示例#8
0
        /// <summary>
        /// The Function is used for Inserting or Updating the data of the Role
        /// </summary>
        /// <param name="objRoleBE">Object of Rolebe to be stored</param>
        /// <returns>Returns the ID of the changed Record</returns>
        public static int Save(RoleBE objRoleBE)
        {
            List<GenralizeParametre> ObjListRoleParam = new List<GenralizeParametre>();
            ObjListRoleParam.Add(new GenralizeParametre("RoleId", objRoleBE.RoleId, DbType.Int32));
            ObjListRoleParam.Add(new GenralizeParametre("RoleName", objRoleBE.RoleName, DbType.String));

            objRoleBE.RoleId = GenralizeStoredProcedure.GetInt(spRoleSave, ObjListRoleParam);
            return objRoleBE.RoleId;
        }
        public Yield PutSiteRole(DreamContext context, DreamMessage request, Result <DreamMessage> response)
        {
            PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN);

            RoleBE role = GetRoleFromUrl(false);

            role = PermissionsBL.PutRole(role, request, context);
            response.Return(DreamMessage.Ok(PermissionsBL.GetRoleXml(role, null)));
            yield break;
        }
        private RoleBE RolesRestrictions_Populate(IDataReader dr, RoleType type)
        {
            RoleBE role = new RoleBE();

            role.CreatorUserId   = dr.Read <uint>("creator_user_id");
            role.ID              = dr.Read <uint>("id");
            role.Name            = dr.Read <string>("name");
            role.PermissionFlags = dr.Read <ulong>("perm_flags");
            role.TimeStamp       = dr.Read <DateTime>("last_edit");
            role.Type            = type;
            return(role);
        }
示例#11
0
        public bool ModifyRole(RoleBE role)
        {
            RoleDAL roleDAL = new RoleDAL();

            if (roleDAL.ModifyRole(role))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
        public uint RolesRestrictions_InsertRole(RoleBE role) {
            string query = @" /*  RolesRestrictions_InsertRole */
INSERT INTO `roles` (`role_name`, `role_perm_flags`, `role_creator_user_id`, `role_last_edit`)
VALUES (?ROLENAME, ?ROLEFLAGS, ?ROLECREATORID, ?TIMESTAMP);
select LAST_INSERT_ID();";
            uint ret = Catalog.NewQuery(query)
    .With("ROLENAME", role.Name)
    .With("ROLEFLAGS", role.PermissionFlags)
    .With("ROLECREATORID", role.CreatorUserId)
    .With("TIMESTAMP", role.TimeStamp)
    .ReadAsUInt() ?? 0;
            return ret;
        }
示例#13
0
        public bool DeleteRole(RoleBE role)
        {
            RoleDAL roleDAL = new RoleDAL();

            if (roleDAL.DeleteRole(role))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#14
0
        public void RolesRestrictions_UpdateRole(RoleBE role) {
            string query = @" /*  RolesRetrictions_UpdateRole */
UPDATE roles SET
role_perm_flags = ?ROLEFLAGS,
role_creator_user_id = ?ROLECREATORID,
role_last_edit = ?TIMESTAMP
WHERE role_name = ?ROLENAME;";
            Catalog.NewQuery(query)
    .With("ROLENAME", role.Name)
    .With("ROLEFLAGS", role.PermissionFlags)
    .With("ROLECREATORID", role.CreatorUserId)
    .With("TIMESTAMP", role.TimeStamp)
    .Execute();
        }
        public uint RolesRestrictions_InsertRole(RoleBE role)
        {
            string query = @" /*  RolesRestrictions_InsertRole */
INSERT INTO `roles` (`role_name`, `role_perm_flags`, `role_creator_user_id`, `role_last_edit`)
VALUES (?ROLENAME, ?ROLEFLAGS, ?ROLECREATORID, ?TIMESTAMP);
select LAST_INSERT_ID();";
            uint   ret   = Catalog.NewQuery(query)
                           .With("ROLENAME", role.Name)
                           .With("ROLEFLAGS", role.PermissionFlags)
                           .With("ROLECREATORID", role.CreatorUserId)
                           .With("TIMESTAMP", role.TimeStamp)
                           .ReadAsUInt() ?? 0;

            return(ret);
        }
        public void RolesRestrictions_UpdateRole(RoleBE role)
        {
            string query = @" /*  RolesRetrictions_UpdateRole */
UPDATE roles SET
role_perm_flags = ?ROLEFLAGS,
role_creator_user_id = ?ROLECREATORID,
role_last_edit = ?TIMESTAMP
WHERE role_name = ?ROLENAME;";

            Catalog.NewQuery(query)
            .With("ROLENAME", role.Name)
            .With("ROLEFLAGS", role.PermissionFlags)
            .With("ROLECREATORID", role.CreatorUserId)
            .With("TIMESTAMP", role.TimeStamp)
            .Execute();
        }
        public IList <RoleBE> RolesRestrictions_GetRestrictions()
        {
            List <RoleBE> roles = new List <RoleBE>();

            Catalog.NewQuery(@" /* RolesRestrictions_GetRestrictions */
select restriction_id as id, restriction_name as `name`, restriction_perm_flags as perm_flags, restriction_last_edit as last_edit, restriction_creator_user_id as creator_user_id 
from	restrictions
order by restriction_id asc;")
            .Execute(delegate(IDataReader dr) {
                while (dr.Read())
                {
                    RoleBE role = RolesRestrictions_Populate(dr, RoleType.RESTRICTION);
                    roles.Add(role);
                }
            });
            return(roles);
        }
示例#18
0
        public static UserBE CreateNewUser(UserBE newUser)
        {
            if (newUser == null)
            {
                return(null);
            }

            //throw exception if licensing does not allow creation of another user
            DekiContext.Current.LicenseManager.IsUserCreationAllowed(true);

            if (newUser.RoleId == 0)
            {
                RoleBE defaultRole = PermissionsBL.RetrieveDefaultRoleForNewAccounts();
                if (defaultRole != null)
                {
                    newUser.RoleId = defaultRole.ID;
                }
            }

            ValidateUser(newUser);
            newUser.CreateTimestamp = DateTime.UtcNow;
            uint userId = DbUtils.CurrentSession.Users_Insert(newUser);

            if (userId == 0)
            {
                return(null);
            }

            newUser.ID = userId;

            PageBE userHomepage = null;

            try {
                // User homepages are created upon user creation (an attempt to create user homepages may also be done upon login)
                userHomepage = PageBL.CreateUserHomePage(newUser);
            } catch (Exception e) {
                _log.WarnExceptionFormat(e, "Error creating user page for {0}", newUser);
            }
            if (userHomepage != null)
            {
                var rcUser = UserBL.GetUserById(userHomepage.UserID) ?? DekiContext.Current.User ?? newUser;
                RecentChangeBL.AddUserCreatedRecentChange(DekiContext.Current.Now, userHomepage, rcUser, DekiResources.USER_ADDED(newUser.Name));
            }
            DekiContext.Current.Instance.EventSink.UserCreate(DekiContext.Current.Now, newUser);
            return(newUser);
        }
示例#19
0
        protected void btnAddRole_Click(object sender, EventArgs e)
        {
            if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "add"))
            {
                LoggedIn master = (LoggedIn)this.Master;
                master.ShowMessage("You are not authorised to Perform any operation on this page. Please contact system administrator.", false);
                //   Server.Transfer("UM_BlankPage.aspx"); //?? send Message through Query String to the BlankPage
                //  string cat = Request.QueryString["Message"];
                //  Response.Redirect("UM_BlankPage.aspx?Message=You are not authorised to Perform any operation on this page. Please contact system administrator.");
                return;
            }
            if (ValidData())
            {
            }
            else
            {
                UserBE  user       = (UserBE)Session["LoggedInUser"];
                RoleBE  addRoleBE  = new RoleBE();
                RoleDAL addRoleDal = new RoleDAL();
                RoleBAL addRoleBal = new RoleBAL();

                addRoleBE.RoleShortDesc  = txtRoleShortDesc.Text;
                addRoleBE.RoleLongDesc   = txtRoleLongDesc.Text;
                addRoleBE.LastModifiedBy = user.UserId;

                if (addRoleBal.AddRole(addRoleBE))
                {
                    txtRoleShortDesc.Text = "";
                    txtRoleLongDesc.Text  = "";
                    LoggedIn master = (LoggedIn)this.Master;
                    master.ShowMessage("Record Inserted Successfully.", true);
                }
                else
                {
                    LoggedIn master = (LoggedIn)this.Master;
                    master.ShowMessage("Unsuccessful.", false);
                }
            }
        }
示例#20
0
        private static void ParseGroupXml(XDoc groupDoc, out uint?id, out string name, out ServiceBE authService, out RoleBE role, out UserBE[] userList)
        {
            name = groupDoc["groupname"].AsText ?? groupDoc["name"].AsText;
            string authserviceidstr = groupDoc["service.authentication/@id"].AsText;
            string rolestr          = groupDoc["permissions.group/role"].AsText;

            authService = null;
            role        = null;
            id          = null;


            if (!groupDoc["@id"].IsEmpty)
            {
                uint id_temp;
                if (!uint.TryParse(groupDoc["@id"].Contents, out id_temp))
                {
                    throw new GroupIdAttributeInvalidArgumentException();
                }
                id = id_temp;
            }

            if (!string.IsNullOrEmpty(authserviceidstr))
            {
                uint serviceid;
                if (!uint.TryParse(authserviceidstr, out serviceid))
                {
                    throw new ServiceAuthIdAttrInvalidArgumentException();
                }

                authService = ServiceBL.GetServiceById(serviceid);
                if (authService == null)
                {
                    throw new ServiceDoesNotExistInvalidArgumentException(serviceid);
                }
            }

            if (!string.IsNullOrEmpty(rolestr))
            {
                role = PermissionsBL.GetRoleByName(rolestr);
                if (role == null)
                {
                    throw new RoleDoesNotExistInvalidArgumentException(rolestr);
                }
            }
            else
            {
                role = PermissionsBL.RetrieveDefaultRoleForNewAccounts();
            }
            if (!groupDoc["users"].IsEmpty)
            {
                userList = ReadUserListXml(groupDoc["users"]);
            }
            else
            {
                userList = new UserBE[] { }
            };
        }
示例#21
0
        public static GroupBE PostGroupFromXml(XDoc groupDoc, GroupBE groupToProcess, string externalusername, string externalpassword)
        {
            GroupBE   group        = null;
            string    groupName    = string.Empty;
            ServiceBE groupService = null;
            RoleBE    groupRole    = null;

            UserBE[] groupMembers = null;
            uint?    groupId      = null;

            ParseGroupXml(groupDoc, out groupId, out groupName, out groupService, out groupRole, out groupMembers);

            //Create new group
            if (groupToProcess == null && (groupId == null || groupId == 0))
            {
                if (groupService == null)
                {
                    groupService = ServiceBL.RetrieveLocalAuthService();
                }

                //External groups should be confirmed with the auth provider
                if (groupService != null && !ServiceBL.IsLocalAuthService(groupService))
                {
                    //username+password from request query params are used here
                    group = ExternalServiceSA.BuildGroupFromAuthService(groupService, groupToProcess, groupName, externalusername, externalpassword);

                    if (group == null)
                    {
                        throw new ExternalGroupNotFoundException(groupName);
                    }
                }

                //Does this group already exist?
                GroupBE tempGroup = GetGroupByName(groupName);
                if (tempGroup != null)
                {
                    throw new GroupExistsWithServiceConflictException(groupName, tempGroup.ServiceId);
                }

                ValidateGroupMemberList(groupService, groupMembers);

                // Insert the group
                GroupBE newGroup = new GroupBE();
                newGroup.Name          = groupName;
                newGroup.RoleId        = groupRole.ID;
                newGroup.ServiceId     = groupService.Id;
                newGroup.CreatorUserId = DekiContext.Current.User.ID;
                newGroup.TimeStamp     = DateTime.UtcNow;
                uint newGroupId = DbUtils.CurrentSession.Groups_Insert(newGroup);
                if (newGroupId == 0)
                {
                    group = null;
                }
                else
                {
                    DbUtils.CurrentSession.GroupMembers_UpdateUsersInGroup(newGroupId, groupMembers.Select(e => e.ID).ToList(), newGroup.TimeStamp);

                    // reload the group to ensure group members are set
                    group = GetGroupById(newGroupId);
                }
            }
            //Edit existing group
            else
            {
                if (groupId != null)
                {
                    groupToProcess = GetGroupById(groupId.Value);
                }

                if (groupToProcess == null)
                {
                    throw new GroupIdNotFoundException(groupId);
                }

                group = groupToProcess;

                //Change the role?
                if (group.RoleId != groupRole.ID)
                {
                    group.RoleId = groupRole.ID;
                }

                //Rename the group?
                if (group.Name != groupName && !string.IsNullOrEmpty(groupName))
                {
                    GroupBE tempGroup = GetGroupByName(groupName);

                    if (tempGroup != null)
                    {
                        throw new GroupExistsWithServiceConflictException(groupName, tempGroup.ServiceId);
                    }

                    if (!ServiceBL.IsLocalAuthService(group.ServiceId))
                    {
                        //TODO MaxM: allow renaming of external groups
                        throw new ExternalGroupRenameNotImplementedException();
                    }

                    //Set the new name of the group.
                    group.Name = groupName;
                }

                DbUtils.CurrentSession.Groups_Update(group);
                //TODO (MaxM): Update group list as well?
                group = GetGroupById(group.Id);
            }

            if (group == null)
            {
                throw new GroupCreateUpdateFatalException();
            }

            return(group);
        }
示例#22
0
        private static RoleBE FillDataRecord(IDataRecord dr)
        {
            RoleBE objRoleBE = new RoleBE();
            if (!dr.IsDBNull(dr.GetOrdinal("RoleId")))
            {
                objRoleBE.RoleId = dr.GetInt32(dr.GetOrdinal("RoleId"));
            }
            if (!dr.IsDBNull(dr.GetOrdinal("RoleName")))
            {
                objRoleBE.RoleName = dr.GetString(dr.GetOrdinal("RoleName"));
            }

            return objRoleBE;
        }
        protected void LvRoleItems_OnItemCommand(object sender, ListViewCommandEventArgs e)
        {
            UM_UC_RoleAdd roleAdd = new UM_UC_RoleAdd();
            HtmlTableRow  SelectedRow;

            if (e.Item.DisplayIndex % 2 == 0) //even
            {
                SelectedRow = e.Item.FindControl("trItemTemplate") as HtmlTableRow;
            }
            else //odd
            {
                SelectedRow = e.Item.FindControl("trAltItemTemplate") as HtmlTableRow;
            }

            SelectedRow.BgColor = "Red";


            if (String.Equals(e.CommandName, "Delete"))
            {
                if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "delete"))
                {
                    LoggedIn master = (LoggedIn)this.Master;
                    master.ShowMessage("You are not authorised to perform this function. Please contact system administrator.", false);

                    return;
                }
                RoleBE   role = new RoleBE();
                string[] arg  = new string[3];
                arg                    = e.CommandArgument.ToString().Split(',');
                hdnRoleId.Value        = arg[0].ToString();
                role.RoleShortDesc     = arg[1].ToString();
                role.RoleLongDesc      = arg[2].ToString();
                RoleShortDescText.Text = role.RoleShortDesc;
                RoleLongDescText.Text  = role.RoleLongDesc;

                mpe_DeleteRole.Show();
            }

            if (String.Equals(e.CommandName, "Edit"))
            {
                if (!commonBAL.isUserAuthorisedForPageFunc(LoggedInUser.UserId, thisPageName, "edit"))
                {
                    LoggedIn master = (LoggedIn)this.Master;
                    master.ShowMessage("You are not authorised to perform this function. Please contact system administrator.", false);
                    return;
                }
                RoleBE   role = new RoleBE();
                string[] arg  = new string[5];
                arg = e.CommandArgument.ToString().Split(',');
                hdnRoleUpdateId.Value = arg[0].ToString();
                role.RoleShortDesc    = arg[1].ToString();
                role.RoleLongDesc     = arg[2].ToString();
                string lastModifiedBy = arg[3].ToString();
                string lastModifiedAt = arg[4].ToString();

                UCRoleAddList.RoleId         = Convert.ToInt32(hdnRoleUpdateId.Value);
                UCRoleAddList.ShortDesc      = role.RoleShortDesc;
                UCRoleAddList.LongDesc       = role.RoleLongDesc;
                UCRoleAddList.LastModifiedBy = lastModifiedBy;
                UCRoleAddList.LastModifiedAt = lastModifiedAt;

                mpe_EditRole.Show();
            }
        }
示例#24
0
        private static UserBE UpdateUserFromXml(UserBE userToUpdate, XDoc userDoc, string username, string email, string fullname, ServiceBE authservice, RoleBE role, bool?active, string externalusername, string externalpassword, string language, string timezone, out List <GroupBE> externalGroups)
        {
            externalGroups = null;
            if (userToUpdate.Name != username && !string.IsNullOrEmpty(username))
            {
                if (UserBL.IsAnonymous(userToUpdate))
                {
                    throw new UserAnonymousEditInvalidOperationException();
                }
                userToUpdate = RenameUser(userToUpdate, username, fullname ?? userToUpdate.RealName);
            }

            //Modify a user's authentication service
            if (authservice != null && authservice.Id != userToUpdate.ServiceId)
            {
                if (UserBL.IsAnonymous(userToUpdate))
                {
                    throw new UserAnonymousEditInvalidOperationException();
                }

                if (ServiceBL.IsLocalAuthService(authservice))
                {
                    //external to local
                    userToUpdate.ExternalName = null;
                    userToUpdate.ServiceId    = authservice.Id;
                }
                else
                {
                    //(local or external) to external
                    userToUpdate = ExternalServiceSA.BuildUserFromAuthService(authservice, userToUpdate, userToUpdate.Name, true, externalusername, externalpassword, out externalGroups);
                    if (userToUpdate == null)
                    {
                        throw new UserAuthChangeFatalException();
                    }

                    //Does the external account already exist?
                    UserBE matchingExternalAccount = DbUtils.CurrentSession.Users_GetByExternalName(userToUpdate.ExternalName, userToUpdate.ServiceId);
                    if (matchingExternalAccount != null)
                    {
                        throw new ExternalUserExistsConflictException(matchingExternalAccount.Name, matchingExternalAccount.ExternalName, matchingExternalAccount.ServiceId);
                    }
                }
            }

            if (email != null)
            {
                if (UserBL.IsAnonymous(userToUpdate) && email != userToUpdate.Email)
                {
                    throw new UserAnonymousEditInvalidOperationException();
                }

                userToUpdate.Email = email;
            }

            if (!string.IsNullOrEmpty(fullname))
            {
                userToUpdate.RealName = fullname;
            }

            if (active != null)
            {
                // disabling user
                if (userToUpdate.UserActive && !active.Value)
                {
                    // cannot disable anonymous user
                    if (UserBL.IsAnonymous(userToUpdate))
                    {
                        throw new UserAnonymousDeactivationInvalidOperationException();
                    }

                    // cannot disable owner
                    if (DekiContext.Current.LicenseManager.GetSiteOwnerUserId().GetValueOrDefault(0) == userToUpdate.ID)
                    {
                        throw new UserOwnerDeactivationConflict();
                    }
                }

                //throw exception if licensing does not allow activating a user
                if (!userToUpdate.UserActive && active.Value)
                {
                    DekiContext.Current.LicenseManager.IsUserCreationAllowed(true);
                }

                userToUpdate.UserActive = active.Value;
            }

            if (role != null && role.ID != userToUpdate.RoleId)
            {
                PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN);
                userToUpdate.RoleId = role.ID;
            }

            if (language != null)
            {
                userToUpdate.Language = language;
            }

            if (timezone != null)
            {
                userToUpdate.Timezone = timezone;
            }

            return(userToUpdate);
        }
示例#25
0
 private RoleBE RolesRestrictions_Populate(IDataReader dr, RoleType type) {
     RoleBE role = new RoleBE();
     role.CreatorUserId = dr.Read<uint>("creator_user_id");
     role.ID = dr.Read<uint>("id");
     role.Name = dr.Read<string>("name");
     role.PermissionFlags = dr.Read<ulong>("perm_flags");
     role.TimeStamp = dr.Read<DateTime>("last_edit");
     role.Type = type;
     return role;
 }
示例#26
0
        private static UserBE ReadUserXml(XDoc userDoc, string username, string email, string fullname, ServiceBE authService, RoleBE role, string language, string timezone)
        {
            UserBE user = new UserBE();

            if (string.IsNullOrEmpty(username))
            {
                throw new UserParameterInvalidArgumentException();
            }

            //TODO (MaxM) Consider validation of fullname, email, username

            //Retrieve default auth service for new user if authservice not given
            if (authService == null)
            {
                authService = ServiceBL.RetrieveLocalAuthService();
            }

            user.Name = username;

            //Default role will be applied if one is not given
            if (role != null)
            {
                user.RoleId = role.ID;
            }

            user.RealName   = fullname ?? string.Empty;
            user.ServiceId  = authService.Id;
            user.UserActive = true;
            user.Email      = email ?? string.Empty;
            user.Language   = language;
            user.Timezone   = timezone;

            return(user);
        }
示例#27
0
        private static void ParseUserXml(XDoc userDoc, out uint?id, out string username, out string email, out string fullname, out ServiceBE authService, out RoleBE role, out bool?active, out string language, out string timezone)
        {
            username = userDoc["username"].AsText;
            email    = userDoc["email"].AsText;
            fullname = userDoc["fullname"].AsText;
            language = userDoc["language"].AsText;
            timezone = userDoc["timezone"].AsText;
            string authserviceidstr = userDoc["service.authentication/@id"].AsText;
            string rolestr          = userDoc["permissions.user/role"].AsText;
            string statusStr        = userDoc["status"].AsText;

            authService = null;
            role        = null;

            id = null;

            if (!userDoc["@id"].IsEmpty)
            {
                uint id_temp;
                if (!uint.TryParse(userDoc["@id"].Contents, out id_temp))
                {
                    throw new UserIdAttrInvalidArgumentException();
                }
                id = id_temp;
            }

            if (!string.IsNullOrEmpty(authserviceidstr))
            {
                uint serviceid;
                if (!uint.TryParse(authserviceidstr, out serviceid))
                {
                    throw new ServiceAuthIdAttrInvalidArgumentException();
                }

                authService = ServiceBL.GetServiceById(serviceid);
                if (authService == null)
                {
                    throw new ServiceDoesNotExistInvalidArgumentException(serviceid);
                }
            }

            if (!string.IsNullOrEmpty(rolestr))
            {
                role = PermissionsBL.GetRoleByName(rolestr);
                if (role == null)
                {
                    throw new RoleDoesNotExistInvalidArgumentException(rolestr);
                }
            }

            if (!string.IsNullOrEmpty(statusStr))
            {
                switch (statusStr.ToLowerInvariant())
                {
                case "active":
                    active = true;
                    break;

                case "inactive":
                    active = false;
                    break;

                default:
                    throw new UserStatusAttrInvalidArgumentException();
                }
            }
            else
            {
                active = null;
            }

            if (!string.IsNullOrEmpty(timezone))
            {
                if (!timeZoneRegex.Match(timezone).Success)
                {
                    throw new UserTimezoneInvalidArgumentException();
                }
            }

            if (!string.IsNullOrEmpty(language))
            {
                string[] validLanguages = DekiContext.Current.Instance.Languages.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string   tempLanguage   = language;
                if (!Array.Exists(validLanguages, delegate(string temp) { return(temp.EqualsInvariantIgnoreCase(tempLanguage)); }))
                {
                    throw new UserInvalidLanguageException();
                }
            }
        }