示例#1
0
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            if (File.Exists(ServerSecurityService.FileName))
            {
                string encryptedData;
                using (var inStream = new FileStream(ServerSecurityService.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var reader = new StreamReader(inStream))
                    {
                        encryptedData = reader.ReadToEnd();
                    }
                }

                try
                {
                    var decryptData = SecurityEncryption.Decrypt(encryptedData);
                    var currentSecuritySettingsTo = JsonConvert.DeserializeObject <SecuritySettingsTO>(decryptData);
                    var permissionGroup           = currentSecuritySettingsTo.WindowsGroupPermissions;

                    // We need to change BuiltIn\Administrators to -> Warewolf Administrators ;)
                    if (permissionGroup.Count > 0)
                    {
                        var adminGrp = permissionGroup[0].WindowsGroup;
                        if (adminGrp == "BuiltIn\\Administrators")
                        {
                            permissionGroup[0].WindowsGroup = WindowsGroupPermission.BuiltInAdministratorsText;
                            decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                        }
                    }

                    var hasGuestPermission = permissionGroup.Any(permission => permission.IsBuiltInGuests);
                    var hasAdminPermission = permissionGroup.Any(permission => permission.IsBuiltInAdministrators);
                    if (!hasAdminPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateAdministrators());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    if (!hasGuestPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateGuests());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    return(new StringBuilder(decryptData));
                }
                catch (Exception e)
                {
                    Dev2Logger.Log.Error("SecurityRead", e);
                }
            }

            var serializer         = new Dev2JsonSerializer();
            var securitySettingsTo = new SecuritySettingsTO(DefaultPermissions)
            {
                CacheTimeout = _cacheTimeout
            };

            return(serializer.SerializeToBuilder(securitySettingsTo));
        }
示例#2
0
        StringBuilder Execute(string encryptedData)
        {
            var decryptData = SecurityEncryption.Decrypt(encryptedData);

            Dev2Logger.Debug(decryptData, GlobalConstants.WarewolfDebug);
            var currentSecuritySettingsTo = JsonConvert.DeserializeObject <SecuritySettingsTO>(decryptData);

            if (currentSecuritySettingsTo.WindowsGroupPermissions.Any(a => a.ResourceID != Guid.Empty))
            {
                foreach (var perm in currentSecuritySettingsTo.WindowsGroupPermissions.Where(a => a.ResourceID != Guid.Empty))
                {
                    perm.ResourceName = Catalog.GetResourcePath(GlobalConstants.ServerWorkspaceID, perm.ResourceID);
                }
            }
            decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
            var permissionGroup = currentSecuritySettingsTo.WindowsGroupPermissions;

            // We need to change BuiltIn\Administrators to -> Warewolf Administrators ;)
            if (permissionGroup.Count > 0)
            {
                var adminGrp = permissionGroup[0].WindowsGroup;
                if (adminGrp == "BuiltIn\\Administrators")
                {
                    permissionGroup[0].WindowsGroup = WindowsGroupPermission.BuiltInAdministratorsText;
                    decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                }
            }

            var hasGuestPermission = permissionGroup.Any(permission => permission.IsBuiltInGuests);
            var hasAdminPermission = permissionGroup.Any(permission => permission.IsBuiltInAdministrators);

            if (!hasAdminPermission)
            {
                permissionGroup.Add(WindowsGroupPermission.CreateAdministrators());
                permissionGroup.Sort(QuickSortForPermissions);
                decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
            }
            if (!hasGuestPermission)
            {
                permissionGroup.Add(WindowsGroupPermission.CreateGuests());
                permissionGroup.Sort(QuickSortForPermissions);
                decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
            }
            return(new StringBuilder(decryptData));
        }
示例#3
0
        public void WindowsGroupPermission_CreateAdministrators_IsNotNull()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var p = WindowsGroupPermission.CreateAdministrators();

            //------------Assert Results-------------------------
            Assert.IsTrue(p.IsServer);
            Assert.IsTrue(p.View);
            Assert.IsTrue(p.Execute);
            Assert.IsTrue(p.Contribute);
            Assert.IsTrue(p.DeployTo);
            Assert.IsTrue(p.DeployFrom);
            Assert.IsTrue(p.Administrator);
            Assert.AreEqual(WindowsGroupPermission.BuiltInAdministratorsText, p.WindowsGroup);
            Assert.AreEqual(Guid.Empty, p.ResourceID);
        }
        public StringBuilder Execute(Dictionary <string, StringBuilder> values, IWorkspace theWorkspace)
        {
            Dev2Logger.Debug("Start Security Read");
            var serverSecuritySettingsFile = EnvironmentVariables.ServerSecuritySettingsFile;

            if (File.Exists(serverSecuritySettingsFile))
            {
                string encryptedData;
                using (var inStream = new FileStream(serverSecuritySettingsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var reader = new StreamReader(inStream))
                    {
                        encryptedData = reader.ReadToEnd();
                    }
                }
                Dev2Logger.Debug("Security Data Read");
                try
                {
                    var decryptData = SecurityEncryption.Decrypt(encryptedData);
                    Dev2Logger.Debug(decryptData);
                    var currentSecuritySettingsTo = JsonConvert.DeserializeObject <SecuritySettingsTO>(decryptData);
                    if (currentSecuritySettingsTo.WindowsGroupPermissions.Any(a => a.ResourceID != Guid.Empty))
                    {
                        foreach (var perm in currentSecuritySettingsTo.WindowsGroupPermissions.Where(a => a.ResourceID != Guid.Empty))
                        {
                            perm.ResourceName = Catalog.GetResourcePath(GlobalConstants.ServerWorkspaceID, perm.ResourceID);
                        }
                    }
                    decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    var permissionGroup = currentSecuritySettingsTo.WindowsGroupPermissions;

                    // We need to change BuiltIn\Administrators to -> Warewolf Administrators ;)
                    if (permissionGroup.Count > 0)
                    {
                        var adminGrp = permissionGroup[0].WindowsGroup;
                        if (adminGrp == "BuiltIn\\Administrators")
                        {
                            permissionGroup[0].WindowsGroup = WindowsGroupPermission.BuiltInAdministratorsText;
                            decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                        }
                    }

                    var hasGuestPermission = permissionGroup.Any(permission => permission.IsBuiltInGuests);
                    var hasAdminPermission = permissionGroup.Any(permission => permission.IsBuiltInAdministrators);
                    if (!hasAdminPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateAdministrators());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    if (!hasGuestPermission)
                    {
                        permissionGroup.Add(WindowsGroupPermission.CreateGuests());
                        permissionGroup.Sort(QuickSortForPermissions);
                        decryptData = JsonConvert.SerializeObject(currentSecuritySettingsTo);
                    }
                    return(new StringBuilder(decryptData));
                }
                catch (Exception e)
                {
                    Dev2Logger.Error("SecurityRead", e);
                }
            }

            var serializer         = new Dev2JsonSerializer();
            var securitySettingsTo = new SecuritySettingsTO(DefaultPermissions)
            {
                CacheTimeout = _cacheTimeout
            };

            return(serializer.SerializeToBuilder(securitySettingsTo));
        }