static CDBehavior() { InitLogger(); cdManager = new CDManager(); user = cdManager.GetUserProfile(Config.WebMessageHandler_Username, Config.WebMessageHandler_Password); }
public WebMessageHandler(ICDManager cdManager) { this.cdManager = cdManager; user = cdManager.GetUserProfile(Config.WebMessageHandler_Username, Config.WebMessageHandler_Password); }
///// <summary> ///// Method for RBAC authorization of action on specific entity ///// </summary> ///// <param name="user"></param> ///// <param name="target"></param> ///// <param name="command"></param> ///// <param name="entity"></param> ///// <returns></returns> //public bool IsActionAllowedOnEntity(UserProfile user, HelpDeskTarget target, string command, /*Incident*/dynamic entity/*incident*/) //{ // var result = false; // if (entity is IEnumerable) // { // var list = Enumerable.ToList(entity); // AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => // { // result = s.IsActionAllowedOnEntity(user, target, command, list); // }); // } // else // { // AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => // { // result = s.IsActionAllowedOnEntity(user, target, command, new List<dynamic>{entity}); // }); // } // return result; //} ///// <summary> ///// Method for RBAC authorization of action on specific entity ///// </summary> ///// <param name="user"></param> ///// <param name="target"></param> ///// <param name="command"></param> ///// <param name="entity"></param> ///// <returns></returns> //public bool IsActionAllowed(UserProfile user, HelpDeskTarget target, string command, string action) //{ // var result = false; // AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => // { // result = s.IsActionAllowed(user, target, command, action); // }); // return result; //} ///// <summary> ///// Method for RBAC authorization of action on list of commands ///// </summary> ///// <param name="user"></param> ///// <param name="target"></param> ///// <param name="command"></param> ///// <param name="entity"></param> ///// <returns></returns> //public IList<string> IsActionAllowedOnEntities(UserProfile user, HelpDeskTarget target, IList entities) //{ // IList<string> result = new List<string>(); // AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => // { // result = s.IsActionAllowedOnEntities(user, target, entities); // }); // return result; //} ///// <summary> ///// Method which is responsible for filtering collection regarding RBAC target and command ///// </summary> ///// <typeparam name="T"></typeparam> ///// <param name="user"></param> ///// <param name="target"></param> ///// <param name="command"></param> ///// <param name="list"></param> ///// <returns></returns> //public IList Filter<T>(UserProfile user, HelpDeskTarget target, string command, List<T> list) //{ // object authorizedList = null; // if (list.Any()) // { // AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => // { // authorizedList = s.Filter(user, target, command, list); // }); // } // return (IList)authorizedList; //} //public List<Incident> AuthorizeAndFilter(UserProfile user, HelpDeskTarget target, string command, List<Incident> list) //{ // List<Incident> authorizedList = null; // if (list.Any()) // { // AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => // { // authorizedList = s.AuthorizeAndFilter(user, target, command, list); // }); // } // return authorizedList; //} ///// <summary> ///// Method for RBAC and workflow definition authorization of specific transition ///// </summary> ///// <param name="transition"></param> ///// <param name="user"></param> ///// <returns></returns> //public bool IsTransitionAllowed(Transition transition, UserProfile user) //{ // return RbacTransionAllowed(user, transition) // && WorkflowTransitionAllowed(transition); //} //private bool RbacTransionAllowed(UserProfile user, Transition transition) //{ // var result = false; // var command = transition.FromStatusSubStatus.Item1 + "-" + transition.ToStatusSubStatus.Item1; // AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => // { // result = s.IsTransitionAllowed(user, command, new List<Incident> { transition.OldIncident }); // }); // return result; //} //private bool WorkflowTransitionAllowed(Transition transition) //{ // //TODO Not finished // transition // = StatusTransitionManager.Instance.IsTransitionAllowed(transition.FromStatusSubStatus, transition.ToStatusSubStatus); // return transition != null; //} /// <summary> /// Return terminal set bitmap for specific user /// </summary> /// <param name="user"></param> /// <returns></returns> public byte[] GetTerminalSetBitmap(UserProfile user) { byte[] bitmap = null; if (user.IsAdmin) { AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => { bitmap = s.CreateDefaultPermissionKey(); }); } else { if (user.AssignedAtmSet != null) { AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService() .ExecuteCommand(s => { bitmap = s.CreatePermissionKey(user.AssignedAtmSet.ToList()); }); } else { AuthorizationServiceProxyProvider.AuthorizationServiceProxyProvider.Instance.GetService().ExecuteCommand(s => { bitmap = s.CreateZeroPermissionKey(); }); } } return bitmap; }
internal static UserProfile FillUserProfileFromReader(SqlDataReader reader) { var userProfile = new UserProfile(); if (reader != null && !reader.IsClosed) { DataTable dt = reader.GetSchemaTable(); if (dt.Select("ColumnName='" + "GroupId" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("GroupId"))) userProfile.GroupId = reader.GetInt16(reader.GetOrdinal("GroupId")); if (dt.Select("ColumnName='" + "UserId" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("UserId"))) userProfile.UserId = reader.GetInt16(reader.GetOrdinal("UserId")); if (dt.Select("ColumnName='" + "UserName" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("UserName"))) userProfile.UserName = reader.GetString(reader.GetOrdinal("UserName")); if (dt.Select("ColumnName='" + "IsAdmin" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("IsAdmin"))) userProfile.IsAdmin = reader.GetInt32(reader.GetOrdinal("IsAdmin")) == 1; if (dt.Select("ColumnName='" + "Active" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("Active"))) userProfile.IsActive = reader.GetInt16(reader.GetOrdinal("Active")) == 1; if (dt.Select("ColumnName='" + "Name" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("Name"))) { userProfile.GroupName = reader.GetString(reader.GetOrdinal("Name")); if (userProfile.GroupName != Config.SuperAdminGroupName) { userProfile.IsAdmin = false; } } if (dt.Select("ColumnName='" + "LoginTime" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("LoginTime"))) userProfile.LastLogin = reader.GetDateTime(reader.GetOrdinal("LoginTime")); if (dt.Select("ColumnName='" + "CurrentTime" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("CurrentTime"))) userProfile.CurrenLogintTime = reader.GetDateTime(reader.GetOrdinal("CurrentTime")); if (dt.Select("ColumnName='" + "GroupRole" + "'").Length > 0) if (!reader.IsDBNull(reader.GetOrdinal("GroupRole"))) userProfile.GroupRole = reader.GetString(reader.GetOrdinal("GroupRole")); userProfile.XmlPreference = DataHelper.GetValue(reader, "Preferences", TypeDefaultValue.StringDefaultValue); userProfile.GUID = Guid.NewGuid().ToString(); } return userProfile; }