Go to the documentation of this file.00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 using System.Configuration;
00005 using System.ComponentModel;
00006 using System.Collections.Specialized;
00007 using N2.Security;
00008
00009 namespace N2.Configuration
00010 {
00011 public class PermissionElement : ConfigurationElement
00012 {
00013 [ConfigurationProperty("dynamic", DefaultValue = false)]
00014 public bool Dynamic
00015 {
00016 get { return (bool)base["dynamic"]; }
00017 set { base["dynamic"] = value; }
00018 }
00019
00020 [ConfigurationProperty("users"), TypeConverter(typeof(CommaDelimitedStringCollectionConverter))]
00021 public StringCollection Users
00022 {
00023 get { return (CommaDelimitedStringCollection)base["users"]; }
00024 set { base["users"] = value; }
00025 }
00026
00027 [ConfigurationProperty("roles"), TypeConverter(typeof(CommaDelimitedStringCollectionConverter))]
00028 public StringCollection Roles
00029 {
00030 get { return (CommaDelimitedStringCollection)base["roles"]; }
00031 set { base["roles"] = value; }
00032 }
00033
00034 public PermissionMap ToPermissionMap(Permission permission, string[] defaultRoles, string[] defaultUsers)
00035 {
00036 PermissionMap map = Dynamic ? new DynamicPermissionMap() : new PermissionMap();
00037 map.Permissions = permission;
00038 map.Roles = ToArray(Roles, defaultRoles);
00039 map.Users = ToArray(Users, defaultUsers);
00040 return map;
00041 }
00042
00043 private string[] ToArray(StringCollection list, string[] defaultValue)
00044 {
00045 if(list == null)
00046 return defaultValue;
00047
00048 string[] array = new string[list.Count];
00049 list.CopyTo(array, 0);
00050 return array;
00051 }
00052 }
00053 }