public override object ReadJson(JsonReader reader, Type type, object existingValue, JsonSerializer serializer) { IAccessControlEntry ace = null; Dictionary <string, string> props = new Dictionary <string, string>(); JObject aceJson = JObject.Load(reader); foreach (JProperty prop in aceJson.Properties()) { props[prop.Name] = prop.Value.ToString(); } bool isAuditAce = typeof(IAccessControlEntryAudit).IsAssignableFrom(type) || props.ContainsKey(RightFields.Denied); if (props.ContainsKey(RightFields.RightData)) { props.Remove(RightFields.RightData); props[RightFields.RightType] = aceJson[RightFields.RightData].SelectToken(RightFields.RightType).ToString(); } if (props.ContainsKey(RightFields.RightType)) { ace = AccessControlEntryUtilities.MakeAceFromRightType(props[RightFields.RightType], props, isAuditAce); } return(ace); }
static void Main(string[] args) { string pace = " {\r\n \"UId\": \"5595682b-1045-4114-af8b-090307242578\",\r\n \"RightType\": \"Suplex.Security.AclModel.FileSystemRight, Suplex.Security.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\",\r\n \"Right\": \"TakeOwnership\",\r\n \"Allowed\": true,\r\n \"Inheritable\": true,\r\n \"InheritedFrom\": \"9570128e-fba8-4455-b328-f30af56eabef\",\r\n \"TrusteeUId\": \"d8adefb2-a142-4397-82b3-9b0d9df37d08\"\r\n }"; string aace = "{\r\n \"UId\": \"3ac08eaa-700a-4ab4-9a90-1659db9ea25d\",\r\n \"RightType\": \"Suplex.Security.AclModel.RecordRight, Suplex.Security.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\",\r\n \"Right\": \"List, Insert, Delete\",\r\n \"Allowed\": true,\r\n \"Denied\": false,\r\n \"Inheritable\": true,\r\n \"InheritedFrom\": \"9733efc2-1cde-415e-af79-ff2d74f5e69d\",\r\n \"TrusteeUId\": \"d8adefb2-a142-4397-82b3-9b0d9df37d08\"\r\n}"; JsonAceConverter aceConverter = new JsonAceConverter(); IAccessControlEntry ace = JsonConvert.DeserializeObject <IAccessControlEntry>(aace, aceConverter); string json = JsonConvert.SerializeObject(ace, aceConverter); SuplexSecurityHttpApiClient client = new SuplexSecurityHttpApiClient("http://localhost:20000/suplex/"); // test secure object SecureObject so = client.GetSecureObjectByUniqueName("New Root1", includeChildren: false, includeDisabled: true); Console.WriteLine($"Original Parent {so.ParentUId}"); SecureObject soDest = client.GetSecureObjectByUniqueName("top.edited", includeChildren: false, includeDisabled: true); //client.UpdateSecureObjectParentUId( so, soDest.UId ); //client.UpdateSecureObjectParentUId( so, null ); //client.UpdateSecureObjectParentUId( so.UId, soDest.UId ); client.UpdateSecureObjectParentUId(so.UId, null); SecureObject found = client.GetSecureObjectByUniqueName("New Root1", includeChildren: false, includeDisabled: true); Console.WriteLine($"After update Parent {found.ParentUId}"); Console.WriteLine("pause"); }
public object ReadYaml(IParser parser, Type type) { IAccessControlEntry ace = null; if (typeof(IAccessControlEntry).IsAssignableFrom(type) && parser.Current.GetType() == typeof(MappingStart)) { parser.MoveNext(); // skip the sequence start Dictionary <string, string> props = new Dictionary <string, string>(); while (parser.Current.GetType() != typeof(MappingEnd)) { string prop = ((Scalar)parser.Current).Value; parser.MoveNext(); string value = ((Scalar)parser.Current).Value; parser.MoveNext(); props[prop] = value; } parser.MoveNext(); bool isAuditAce = typeof(IAccessControlEntryAudit).IsAssignableFrom(type); if (props.ContainsKey(RightFields.RightType)) { ace = AccessControlEntryUtilities.MakeAceFromRightType(props[RightFields.RightType], props, isAuditAce); } } return(ace); }
public static IAccessControlEntry MakeGenericAceFromType(Type rightType, Dictionary <string, string> props = null, bool isAuditAce = false) { rightType.ValidateIsEnum(); IAccessControlEntry ace = null; Type objectType = isAuditAce ? typeof(AccessControlEntryAudit <>) : typeof(AccessControlEntry <>); Type genericType = objectType.MakeGenericType(rightType); object instance = Activator.CreateInstance(genericType); ace = (IAccessControlEntry)instance; IAccessControlEntryAudit auditAce = isAuditAce ? (IAccessControlEntryAudit)ace : null; if (props?.Count > 0) { foreach (string prop in props.Keys) { if (prop.Equals(nameof(ace.UId))) { ace.UId = Guid.Parse(props[prop]); } else if (prop.Equals(RightFields.Right)) { ace.SetRight(props[prop]); } else if (prop.Equals(nameof(ace.Allowed))) { ace.Allowed = bool.Parse(props[prop]); } else if (isAuditAce && prop.Equals(nameof(auditAce.Denied))) { auditAce.Denied = bool.Parse(props[prop]); } else if (prop.Equals(nameof(ace.Inheritable))) { ace.Inheritable = bool.Parse(props[prop]); } else if (prop.Equals(nameof(ace.InheritedFrom))) { ace.InheritedFrom = Guid.Parse(props[prop]); } else if (prop.Equals(nameof(ace.TrusteeUId))) { ace.TrusteeUId = Guid.Parse(props[prop]); } } } return(ace); }
public void SetAccessControlEntry_UnitTest() { IAccessControlEntry accessControlEntry = default(IAccessControlEntry); Boolean merge = default(Boolean); ExecuteMethod( () => { return((IAccessControlList)GetInstance()); }, instance => { accessControlEntry = AccessControlEntryImpl_UnitTests.GetInstance(); merge = default(Boolean); //No Constructor SetAccessControlEntry_PreCondition(instance, ref accessControlEntry, ref merge); }, instance => { instance.SetAccessControlEntry(accessControlEntry, merge); }, instance => { SetAccessControlEntry_PostValidate(instance, accessControlEntry, merge); }); }
int EvalRights(int allowedMask, int deniedMask) { Type rightType = Ace.RightData.RightType; IAccessControlEntry allowedAce = AccessControlEntryUtilities.MakeGenericAceFromType(rightType); allowedAce.Allowed = true; allowedAce.SetRight(allowedMask.ToString()); IAccessControlEntry deniedAce = AccessControlEntryUtilities.MakeGenericAceFromType(rightType); deniedAce.Allowed = false; deniedAce.SetRight(deniedMask.ToString()); _sd.Clear(); _sd.Dacl.Add(allowedAce); _sd.Dacl.Add(deniedAce); _sd.Eval(rightType); //suppress reentrancy into this function: IsChecked=true fires CheckBox_Checked _suppressRightsEval = true; int mask = 0; foreach (CheckBox cb in this.Items) { cb.IsChecked = _sd.Results.GetByTypeRight(rightType, (int)cb.Content).AccessAllowed; if (cb.IsChecked.Value) { mask |= (int)cb.Content; } } _suppressRightsEval = false; return(mask); }
/// <summary> /// Sets the Access-Control-* headers. /// </summary> /// <param name="response">The <see cref="IResponse"/> instance.</param> /// <param name="accessControl">A <see cref="IAccessControlEntry"/> containing the header values.</param> public static void SetAccessControl(this IResponse response, IAccessControlEntry accessControl) { response.SetHeader(HeaderKeys.AccessControlAllowOrigin, accessControl.Origin); if (!string.IsNullOrWhiteSpace(accessControl.AllowHeaders)) { response.SetHeader(HeaderKeys.AccessControlAllowHeaders, accessControl.AllowHeaders); } if (!string.IsNullOrWhiteSpace(accessControl.ExposeHeaders)) { response.SetHeader(HeaderKeys.AccessControlExposeHeaders, accessControl.ExposeHeaders); } if (!string.IsNullOrWhiteSpace(accessControl.Methods)) { response.SetHeader(HeaderKeys.AccessControlAllowMethods, accessControl.Methods); } if (accessControl.Credentials.HasValue) { response.SetHeader(HeaderKeys.AccessControlAllowCredentials, accessControl.Credentials.Value.ToString()); } if (accessControl.MaxAge.HasValue) { response.SetHeader(HeaderKeys.AccessControlMaxAge, accessControl.MaxAge.Value.ToString(CultureInfo.InvariantCulture)); } }
/// <summary> /// Sets the access control entry. /// </summary> /// <param name="accessControlEntry">The access control entry.</param> /// <param name="merge">The merge.</param> /// <returns>IAccessControlEntry.</returns> /// <exception cref="DynCon.OSI.Core.Helpers.ToBeImplementedException"></exception> IAccessControlEntry IAccessControlList.SetAccessControlEntry(IAccessControlEntry accessControlEntry, Boolean merge) { throw new ToBeImplementedException(); }
partial void Deny_SetCondition(ref IAccessControlEntry instance, ref Int32 setValue);
partial void ExtendedInfo_SetCondition(ref IAccessControlEntry instance, ref IAceExtendedInformation setValue);
partial void SetAccessControlEntry_PreCondition(IAccessControlList instance, ref IAccessControlEntry accessControlEntry, ref Boolean merge);
partial void SetAccessControlEntry_PostValidate(IAccessControlList instance, IAccessControlEntry accessControlEntry, Boolean merge);