public AbstractReader(IEncryption encryption = null, ISecurityRole securityRole = null, string userName = null, string roleName = null) { ReaderEncryption = encryption; SecurityRole = securityRole; UserName = userName; RoleName = roleName; }
public DroitResource[] GetDroitsByRole(ISecurityRole role) { string sql = string.Format("SELECT * FROM {0} WHERE RoleID=@RoleID", this.TableName); return new SqlEntityMap<DroitResource>(this.ContractProvider, sql) .AddString("RoleID", role.ID) .SetMap(Resource_Map) .AsList().ToArray(); }
static string GetSecurityOperation(ISecurityRole securityRole, XPMemberInfo memberInfo) { var typeInfo = XafTypesInfo.Instance.FindTypeInfo(memberInfo.CollectionElementType.ClassType); var roleTypeInfo = XafTypesInfo.Instance.FindTypeInfo(securityRole.GetType()); var operationsAttribute = typeInfo.FindAttributes <SecurityOperationsAttribute>().FirstOrDefault(attribute => attribute.CollectionName == memberInfo.Name); return(operationsAttribute != null?Convert(securityRole, roleTypeInfo, operationsAttribute) : null); }
public DroitResource[] GetDroitsByRole(ISecurityRole role) { string sql = string.Format("SELECT * FROM {0} WHERE RoleID=@RoleID", this.TableName); return(new SqlEntityMap <DroitResource>(this.ContractProvider, sql) .AddString("RoleID", role.ID) .SetMap(Resource_Map) .AsList().ToArray()); }
public static void GrantPermissionsForModelDifferenceObjects(this ISecurityRole securityRole) { var types = new List <Type> { typeof(ModelDifferenceObject), typeof(UserModelDifferenceObject), typeof(RoleModelDifferenceObject), typeof(IntermediateObject), typeof(AspectObject), typeof(PersistentApplication), typeof(XPObjectType), SecuritySystem.UserType }; securityRole.GrantPermissionsObjects(types); }
public virtual void EnsureAnonymousUser(ISecurityRole anonymousRole) { var anonymousUser = (ISecurityUser)ObjectSpace.FindObject(UserType, new BinaryOperator("UserName", SecurityStrategy.AnonymousUserName)); if (anonymousUser == null) { anonymousUser = (ISecurityUser)ObjectSpace.CreateObject(UserType); var baseObject = ((XPBaseObject)anonymousUser); baseObject.SetMemberValue("UserName", SecurityStrategy.AnonymousUserName); anonymousUser.IsActive = true; ((IAuthenticationStandardUser)anonymousUser).SetPassword(""); ((XPBaseCollection)baseObject.GetMemberValue("Roles")).BaseAdd(anonymousRole); } }
public static void AddNewFullPermissionAttributes(this ISecurityRole securityRole, Action <SecuritySystemTypePermissionObject> action = null, bool defaultAllowValues = true) { var persistentTypes = XafTypesInfo.Instance.PersistentTypes.Where(info => info.FindAttribute <FullPermissionAttribute>() != null); foreach (var typeInfo in persistentTypes) { var securitySystemRole = securityRole as SecuritySystemRoleBase; securitySystemRole?.AddNewTypePermission(typeInfo.Type, action, defaultAllowValues); var permissionPolicyRole = securityRole as IPermissionPolicyRole; permissionPolicyRole?.AddTypePermission(typeInfo.Type, SecurityOperations.FullAccess, defaultAllowValues?SecurityPermissionState.Allow : SecurityPermissionState.Deny); } }
public static void CreatePermissionBehaviour(this ISecurityRole systemRole, Enum behaviourEnum, Action <ISecurityRole, ITypeInfo> action) { var typeInfos = XafTypesInfo.Instance.PersistentTypes.Where(info => { var permissionBehaviorAttribute = info.FindAttribute <PermissionBehaviorAttribute>(); return(permissionBehaviorAttribute != null && permissionBehaviorAttribute.Name.Equals(Enum.GetName(behaviourEnum.GetType(), behaviourEnum))); }); foreach (var typeInfo in typeInfos) { action.Invoke(systemRole, typeInfo); } }
public static SecuritySystemTypePermissionObject AddNewTypePermission(this ISecurityRole role, Type targetType) { var objectSpace = XPObjectSpace.FindObjectSpaceByObject(role); if (role is SecuritySystemRoleBase systemRole) { var permissionObject = objectSpace.CreateObject <SecuritySystemTypePermissionObject>(); permissionObject.TargetType = targetType; systemRole.TypePermissions.Add(permissionObject); return(permissionObject); } return(null); }
private AbstractReader GetReaderByIndex(int index, IEncryption encryption, ISecurityRole securityRole, string user, string role) { switch (index) { case 0: return(new TextReader(encryption, securityRole, user, role)); case 1: return(new XmlReader(encryption, securityRole, user, role)); case 2: return(new JsonReader(encryption, securityRole, user, role)); default: return(null); } }
public virtual void EnsureAnonymousUser(ISecurityRole anonymousRole) { throw new NotImplementedException(); // var anonymousUser = (ISecurityUser)ObjectSpace.FindObject(UserType, new BinaryOperator("UserName", SecurityStrategy.AnonymousUserName)); // if (anonymousUser == null) { // anonymousUser = (ISecurityUser)ObjectSpace.CreateObject(UserType); // var baseObject = ((XPBaseObject)anonymousUser); // baseObject.SetMemberValue("UserName", SecurityStrategy.AnonymousUserName); // anonymousUser.IsActive = true; // ((IAuthenticationStandardUser)anonymousUser).SetPassword(""); // ((XPBaseCollection)baseObject.GetMemberValue("Roles")).BaseAdd(anonymousRole); // } }
public IDroit[] GetDroitsByRole(ISecurityRole role) { List <Droit> droits = new List <Droit>(); DroitResource [] drs = new DroitResourceRepository(this).GetDroitsByRole(role); if (drs.IsNotNullAndEmpty()) { foreach (DroitResource resource in drs) { droits.Add(ConvertToDroit(resource)); } } return(droits.ToArray()); }
static string Convert(ISecurityRole securityRole, ITypeInfo roleTypeInfo, SecurityOperationsAttribute operationsAttribute) { var memberInfo = MemberInfo(roleTypeInfo, operationsAttribute); if (memberInfo != null) { var value = memberInfo.GetValue(securityRole); if (value == null || ReferenceEquals(value, "")) return null; var securityOperations = (SecurityOperationsEnum)value; var fieldInfo = typeof(SecurityOperations).GetField(securityOperations.ToString(), BindingFlags.Public | BindingFlags.Static); if (fieldInfo != null) return fieldInfo.GetValue(null).ToString(); throw new NotImplementedException(value.ToString()); } return null; }
static IEnumerable <IOperationPermission> ObjectOperationPermissions(this ISecurityRole securityRole, XPMemberInfo member) { var collection = ((XPBaseCollection)member.GetValue(securityRole)).OfType <object>().ToArray(); var securityOperation = GetSecurityOperation(securityRole, member); if (!string.IsNullOrEmpty(securityOperation)) { foreach (var operation in securityOperation.Split(ServerPermissionRequestProcessor.Delimiters, StringSplitOptions.RemoveEmptyEntries)) { foreach (var obj in collection) { yield return(ObjectOperationPermissions(member, obj, operation, securityRole.Name)); } } } }
public static void GrantPermissionsObjects(this ISecurityRole securityRole, List <Type> types) { if (SecuritySystem.Instance is ISecurityComplex) { types.Add(((ISecurityComplex)SecuritySystem.Instance).RoleType); } foreach (var type in types) { TypeOperationPermissionDescriptor descriptor = ((TypePermissionDescriptorsList)((XPBaseObject)securityRole).GetMemberValue("Permissions"))[type]; if (descriptor != null) { descriptor.Grant(SecurityOperations.Create); descriptor.Grant(SecurityOperations.Write); descriptor.Grant(SecurityOperations.Read); descriptor.Grant(SecurityOperations.Delete); } } }
private void button1_Click(object sender, EventArgs e) { IEncryption encryption = null; ISecurityRole securityRole = null; AbstractReader reader = null; if (checkBox1.Checked) { encryption = new ReverseEncryption(); } if (checkBox2.Checked) { securityRole = new ClassicSecurityRole(); } reader = GetReaderByIndex(comboBox1.SelectedIndex, encryption, securityRole, textBox3.Text, textBox4.Text); textBox2.Text = reader.Read(textBox1.Text); }
static string Convert(ISecurityRole securityRole, ITypeInfo roleTypeInfo, SecurityOperationsAttribute operationsAttribute) { var memberInfo = MemberInfo(roleTypeInfo, operationsAttribute); if (memberInfo != null) { var value = memberInfo.GetValue(securityRole); if (value == null || ReferenceEquals(value, "")) { return(null); } var securityOperations = (SecurityOperationsEnum)value; var fieldInfo = typeof(SecurityOperations).GetField(securityOperations.ToString()); if (fieldInfo != null) { return(fieldInfo.GetValue(null).ToString()); } throw new NotImplementedException(value.ToString()); } return(null); }
private List <object> GetPermissions(ISecurityRole securityRole, List <object> permissions) { if (securityRole.Name == SecurityStrategy.AdministratorRoleName) { // var modelPermission = ObjectSpace.CreateObject<ModelOperationPermissionData>(); // modelPermission.Save(); // ((ISupportUpdate)securityRole).BeginUpdate(); // ((XPBaseObject)securityRole).GetMemberValue("Permissions"); // var descriptorsList = (TypePermissionDescriptorsList)((XPBaseObject)securityRole).GetMemberValue("Permissions"); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Read); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Write); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Create); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Delete); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Navigate); // ((ISupportUpdate)securityRole).EndUpdate(); // permissions.Add(modelPermission); } else if (securityRole.Name == "Anonymous") { throw new NotImplementedException(); // securityRole.GrantPermissionsForModelDifferenceObjects(); } return(permissions); }
/// <summary> /// /Handle the click event in the OnClick method. Here we will test the selected object, get the object’s model and label file, and create the label. /// </summary> /// <param name="e">The context of the VS tools and metadata</param> public override void OnClick(AddinDesignerEventArgs e) { try { // Get the metamodel service IMetaModelService metaModelService = helper.MetaModelService; // Is the selected element a table? if (e.SelectedElement is ITable) { ITable table = e.SelectedElement as ITable; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); labelPrefix = table.Name; } else if (e.SelectedElement is IBaseField) { IBaseField baseField = e.SelectedElement as IBaseField; var table = baseField.Table; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(table.Name)); labelPrefix = String.Format("{0}_{1}", baseField.Table.Name, baseField.Name); } if (e.SelectedElement is IView) { IView view = e.SelectedElement as IView; helper.setModelAndLabelFile(metaModelService.GetTableModelInfo(view.Name)); labelPrefix = view.Name; } else if (e.SelectedElement is IViewBaseField) { IViewBaseField baseField = e.SelectedElement as IViewBaseField; var view = baseField.View; helper.setModelAndLabelFile(metaModelService.GetViewModelInfo(view.Name)); labelPrefix = String.Format("{0}_{1}", baseField.View.Name, baseField.Name); } else if (e.SelectedElement is IFormDesign) { IFormDesign formDesign = e.SelectedElement as IFormDesign; var form = formDesign.Form; helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(form.Name)); labelPrefix = formDesign.Form.Name; } else if (e.SelectedElement is IFormControl) { IFormControl formControl = e.SelectedElement as IFormControl; IRootElement rootElement = formControl.RootElement as IRootElement; if (rootElement is IFormExtension) { helper.setModelAndLabelFile(metaModelService.GetFormExtensionModelInfo(rootElement.Name)); labelPrefix = String.Format("{0}_{1}", rootElement.Name, formControl.Name); labelPrefix = labelPrefix.Replace(".","_"); } else { helper.setModelAndLabelFile(metaModelService.GetFormModelInfo(rootElement.Name)); labelPrefix = String.Format("{0}_{1}", rootElement.Name, formControl.Name); } } else if (e.SelectedElement is ISecurityPrivilege) { ISecurityPrivilege securityObject = e.SelectedElement as ISecurityPrivilege; helper.setModelAndLabelFile(metaModelService.GetSecurityPrivilegeModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.PrivilegeTag, securityObject.Name); } else if (e.SelectedElement is ISecurityDuty) { ISecurityDuty securityObject = e.SelectedElement as ISecurityDuty; helper.setModelAndLabelFile(metaModelService.GetSecurityDutyModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.DutyTag, securityObject.Name); } else if (e.SelectedElement is ISecurityRole) { ISecurityRole securityObject = e.SelectedElement as ISecurityRole; helper.setModelAndLabelFile(metaModelService.GetSecurityRoleModelInfo(securityObject.Name)); labelPrefix = String.Format("{0}_{1}", Tags.RoleTag, securityObject.Name); } else if (e.SelectedElement is IEdtBase) { IEdtBase edt = e.SelectedElement as IEdtBase; helper.setModelAndLabelFile(metaModelService.GetExtendedDataTypeModelInfo(edt.Name)); labelPrefix = String.Format("{0}_{1}", Tags.EDTTag, edt.Name); } else if (e.SelectedElement is IMenuItem) { IMenuItem AxMenuItem = e.SelectedElement as IMenuItem; labelPrefix = String.Format("{0}_{1}", Tags.MenuItemTag, AxMenuItem.Name); if (AxMenuItem is IMenuItemAction) { helper.setModelAndLabelFile(metaModelService.GetMenuItemActionModelInfo(AxMenuItem.Name)); } else if (AxMenuItem is IMenuItemDisplay) { helper.setModelAndLabelFile(metaModelService.GetMenuItemDisplayModelInfo(AxMenuItem.Name)); } else if (AxMenuItem is IMenuItemOutput) { helper.setModelAndLabelFile(metaModelService.GetMenuItemOutputModelInfo(AxMenuItem.Name)); } } else if (e.SelectedElement is IReportDataSetField) { IReportDataSetField dataField = e.SelectedElement as IReportDataSetField; helper.setModelAndLabelFile(metaModelService.GetReportModelInfo(dataField.DataSet.Report.Name)); labelPrefix = String.Format("{0}_{1}_{2}", dataField.DataSet.Report.Name, dataField.DataSet.Name, dataField.Name); } helper.createPropertyLabels(e.SelectedElement, labelPrefix); } catch (Exception ex) { Microsoft.Dynamics.Framework.Tools.MetaModel.Core.CoreUtility.HandleExceptionWithErrorMessage(ex); } }
public override void setElementType(IRootElement selectedElement) { this.iSecurityRole = selectedElement as ISecurityRole; }
public IEnumerable <IOperationPermission> GetPermissions(ISecurityRole securityRole) { return(true.Equals(((IXPClassInfoProvider)securityRole).ClassInfo.GetMember("ModifyLayout").GetValue(securityRole)) ? new[] { new OverallCustomizationAllowedPermission() } : Enumerable.Empty <IOperationPermission>()); }
static bool IsInRole(ISecurityRole securityRole) { return(((ISecurityUserWithRoles)SecuritySystem.CurrentUser).Roles.Select(role => role.Name).Contains(securityRole.Name)); }
public TextReader(IEncryption encryption = null, ISecurityRole securityRole = null, string userName = null, string roleName = null) : base(encryption, securityRole, userName, roleName) { }
private List<object> GetPermissions(ISecurityRole securityRole, List<object> permissions) { if (securityRole.Name == SecurityStrategy.AdministratorRoleName) { // var modelPermission = ObjectSpace.CreateObject<ModelOperationPermissionData>(); // modelPermission.Save(); // ((ISupportUpdate)securityRole).BeginUpdate(); // ((XPBaseObject)securityRole).GetMemberValue("Permissions"); // var descriptorsList = (TypePermissionDescriptorsList)((XPBaseObject)securityRole).GetMemberValue("Permissions"); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Read); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Write); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Create); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Delete); // descriptorsList.GrantRecursive(typeof(object), SecurityOperations.Navigate); // ((ISupportUpdate)securityRole).EndUpdate(); // permissions.Add(modelPermission); } else if (securityRole.Name == "Anonymous") { throw new NotImplementedException(); // securityRole.GrantPermissionsForModelDifferenceObjects(); } return permissions; }
private SecurityTypePermission FindFirstTypePermission(ISecurityRole role, Type type) { CriteriaSerializer criteriaSerializer = new CriteriaSerializer(); return(role.TypePermissions.OfType <SecurityTypePermission>().FirstOrDefault(p => ((ParameterExpression)criteriaSerializer.Deserialize(p.StringType)).Type == type)); }
public static ISecurityUserWithRoles GetUser(this ISecurityRole systemRole, string userName, string passWord = "") { var objectSpace = XPObjectSpace.FindObjectSpaceByObject(systemRole); return(objectSpace.GetUser(userName, passWord, systemRole)); }
static string GetSecurityOperation(ISecurityRole securityRole, XPMemberInfo memberInfo) { var typeInfo = XafTypesInfo.Instance.FindTypeInfo(memberInfo.CollectionElementType.ClassType); var roleTypeInfo = XafTypesInfo.Instance.FindTypeInfo(securityRole.GetType()); var operationsAttribute = typeInfo.FindAttributes<SecurityOperationsAttribute>().FirstOrDefault(attribute => attribute.CollectionName == memberInfo.Name); return operationsAttribute != null ? Convert(securityRole, roleTypeInfo, operationsAttribute) : null; }
static bool IsInRole(ISecurityRole securityRole) { return ((ISecurityUserWithRoles)SecuritySystem.CurrentUser).Roles.Select(role => role.Name).Contains(securityRole.Name); }