Exemplo n.º 1
0
        /// <summary>
        /// Creates a PermissionSetDefinition for the specified assembly.
        /// </summary>
        /// <param name="assembly"></param>
        /// <returns></returns>
        private PermissionSetDefinition CreatePermissionSetDefinition(AssemblyDefinition assembly)
        {
            PermissionSetDefinition wspPermissionSet = new PermissionSetDefinition();

            wspPermissionSet.Name        = assembly.Name.Name + Guid.NewGuid().ToString();
            wspPermissionSet.@class      = PermssionSetClassAttr.NamedPermissionSet;
            wspPermissionSet.version     = "1";
            wspPermissionSet.Description = "WSPBuilder generated permissionSet";

            StringBuilder    permissionBlob = new StringBuilder();
            StringDictionary permissions    = new StringDictionary();

            PermissionSet assemblyPermissionSet = GetAssemblyDefinedPermissions(assembly);


            // Add all permissions found in assembly to the list of permissions
            if (assemblyPermissionSet != null)
            {
                foreach (IPermission permission in assemblyPermissionSet)
                {
                    SecurityElement element          = permission.ToXml();
                    string          assemblyFullName = element.Attributes["class"] as string;

                    // Check that the permission is not already added and that it is not in the standard permission set.
                    if (!permissions.ContainsKey(assemblyFullName))
                    {
                        permissions.Add(assemblyFullName, permission.ToString());
                    }
                }
            }

            // Add all the standard permissions
            foreach (string key in Config.Current.PermissionSet.Keys)
            {
                string assemblyFullName = SecurityClasses.GetReference(key);
                // Only add permissions not specified in the assembly
                if (!permissions.ContainsKey(assemblyFullName))
                {
                    permissions.Add(assemblyFullName, Config.Current.PermissionSet[key]);
                }
            }

            // Write out all permissions to blob
            foreach (string permissionItem in permissions.Values)
            {
                permissionBlob.Append(permissionItem);
                if (!permissionItem.EndsWith("\r\n"))
                {
                    permissionBlob.Append("\r\n");
                }
            }

            // Save the permissions until the manifest file has been serialized.
            if (!PolicyPermissionList.ContainsKey(wspPermissionSet.Name))
            {
                PolicyPermissionList.Add(wspPermissionSet.Name, permissionBlob.ToString());
            }

            return(wspPermissionSet);
        }
Exemplo n.º 2
0
        public static SecuritySchemes GetSecurityScheme(SecurityClasses securityClass)
        {
            SecuritySchemes ret = SecuritySchemes.NONE;

            switch (securityClass)
            {
            case SecurityClasses.S2Class0:
                ret = SecuritySchemes.S2_UNAUTHENTICATED;
                break;

            case SecurityClasses.S2Class1:
                ret = SecuritySchemes.S2_AUTHENTICATED;
                break;

            case SecurityClasses.S2Class2:
                ret = SecuritySchemes.S2_ACCESS;
                break;

            case SecurityClasses.S0:
                ret = SecuritySchemes.S0;
                break;
            }
            return(ret);
        }
Exemplo n.º 3
0
        public static SecurityClasses GetSecurityClass(SecuritySchemes scheme)
        {
            SecurityClasses ret = SecurityClasses.None;

            switch (scheme)
            {
            case SecuritySchemes.S2_UNAUTHENTICATED:
                ret = SecurityClasses.S2Class0;
                break;

            case SecuritySchemes.S2_AUTHENTICATED:
                ret = SecurityClasses.S2Class1;
                break;

            case SecuritySchemes.S2_ACCESS:
                ret = SecurityClasses.S2Class2;
                break;

            case SecuritySchemes.S0:
                ret = SecurityClasses.S0;
                break;
            }
            return(ret);
        }