示例#1
0
        /// <summary>
        /// Saves the credentials.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public bool SaveCredentials(out string message)
        {
            if (!TestConnection(out message, UserType.ContentManager))
            {
                return(false);
            }

            if (!String.IsNullOrWhiteSpace(BrowserUser) && !BrowserUser.Equals(ContentManagerUser))
            {
                if (!TestConnection(out message, UserType.Browser))
                {
                    return(false);
                }
            }

            using (RockContext context = new RockContext())
            {
                int categoryId = GetReportingServicesCategory(context);
                if (categoryId <= 0)
                {
                    categoryId = CreateReportingServicesCategory(context);
                }

                VerifyAttributes(context, categoryId);

                SaveAttributeValue(context, SERVER_URL_KEY, ServerUrl);
                SaveAttributeValue(context, SERVER_ROOT_PATH_KEY, ReportPath);
                SaveAttributeValue(context, CONTENT_MANAGER_USER_KEY, ContentManagerUser);
                SaveAttributeValue(context, CONTENT_MANAGER_PWD_KEY, Encryption.EncryptString(ContentManagerPassword));
                SaveAttributeValue(context, BROWSER_USER_KEY, BrowserUser);
                SaveAttributeValue(context, BROWSER_PWD_KEY, Encryption.EncryptString(BrowserPassword));
            }
            GlobalAttributesCache.Clear();
            return(true);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string attributeKey = GetAttributeValue("OAuthConfigAttributeKey");
            Dictionary <string, string> settings = GlobalAttributesCache.Value(attributeKey).AsDictionary();

            settings["OAuthAuthorizePath"]        = "/" + ddlAuthorizeRoute.SelectedValue;
            settings["OAuthLoginPath"]            = "/" + ddlLoginRoute.SelectedValue;
            settings["OAuthLogoutPath"]           = "/" + ddlLogoutRoute.SelectedValue;
            settings["OAuthTokenPath"]            = "/" + ddlTokenRoute.SelectedValue;
            settings["OAuthRequireSsl"]           = cbSSLRequired.Checked.ToString();
            settings["OAuthTokenLifespan"]        = tbTokenLifespan.Text;
            settings["OAuthRefreshTokenLifespan"] = tbRefreshTokenLifespan.Text;

            RockContext      context          = new RockContext();
            AttributeService attributeService = new AttributeService(context);

            Rock.Model.Attribute attribute = attributeService.Queryable().Where(a => a.Key == attributeKey).FirstOrDefault();
            if (attribute == null)
            {
                attribute             = new Rock.Model.Attribute();
                attribute.Name        = "OAuth Settings";
                attribute.Description = "Settings for the OAuth server plugin.";
                attribute.Key         = "OAuthSettings";
                FieldTypeService fieldTypeService = new FieldTypeService(context);
                attribute.FieldType = fieldTypeService.Get(Rock.SystemGuid.FieldType.KEY_VALUE_LIST.AsGuid());
                context.SaveChanges();
            }
            // Update the actual attribute value.
            AttributeValueService attributeValueService = new AttributeValueService(context);
            AttributeValue        attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, null);

            if (attributeValue == null)
            {
                attributeValue             = new AttributeValue();
                attributeValue.AttributeId = attribute.Id;
                attributeValueService.Add(attributeValue);
            }
            attributeValue.Value = string.Join("|", settings.Select(a => a.Key + "^" + a.Value).ToList());
            context.SaveChanges();

            // Flush the cache(s)
            AttributeCache.Remove(attribute.Id);
            GlobalAttributesCache.Clear();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string attributeKey = GetAttributeValue("RoomscannerConfigAttributeKey");
            Dictionary <string, string> settings = GlobalAttributesCache.Value(attributeKey).AsDictionary();

            settings["AllowedGroupId"]      = tbAllowedGroupId.Text;
            settings["SubroomLocationType"] = tbSubroomLocationTypeId.Text;

            RockContext      context          = new RockContext();
            AttributeService attributeService = new AttributeService(context);

            Rock.Model.Attribute attribute = attributeService.Queryable().Where(a => a.Key == attributeKey).FirstOrDefault();
            if (attribute == null)
            {
                attribute             = new Rock.Model.Attribute();
                attribute.Name        = "RoomScanner Settings";
                attribute.Description = "Settings for the OAuth server plugin.";
                attribute.Key         = "RoomScannerSettings";
                FieldTypeService fieldTypeService = new FieldTypeService(context);
                attribute.FieldType = fieldTypeService.Get(Rock.SystemGuid.FieldType.KEY_VALUE_LIST.AsGuid());
                context.SaveChanges();
            }
            // Update the actual attribute value.
            AttributeValueService attributeValueService = new AttributeValueService(context);
            AttributeValue        attributeValue        = attributeValueService.GetByAttributeIdAndEntityId(attribute.Id, null);

            if (attributeValue == null)
            {
                attributeValue             = new AttributeValue();
                attributeValue.AttributeId = attribute.Id;
                attributeValueService.Add(attributeValue);
            }
            attributeValue.Value = string.Join("|", settings.Select(a => a.Key + "^" + a.Value).ToList());
            context.SaveChanges();

            // Flush the cache(s)
            AttributeCache.Remove(attribute.Id);
            GlobalAttributesCache.Clear();
        }
示例#4
0
        /// <summary>
        /// Verifies the attributes.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="categoryId">The category identifier.</param>
        private void VerifyAttributes(RockContext context, int categoryId)
        {
            var  attributeService = new AttributeService(context);
            var  category         = new CategoryService(context).Get(categoryId);
            bool hasChanges       = false;

            var serverUrl          = attributeService.GetGlobalAttribute(SERVER_URL_KEY);
            var serverRootPath     = attributeService.GetGlobalAttribute(SERVER_ROOT_PATH_KEY);
            var contentManagerUser = attributeService.GetGlobalAttribute(CONTENT_MANAGER_USER_KEY);
            var contentManagerPwd  = attributeService.GetGlobalAttribute(CONTENT_MANAGER_PWD_KEY);
            var browserUser        = attributeService.GetGlobalAttribute(BROWSER_USER_KEY);
            var browserPwd         = attributeService.GetGlobalAttribute(BROWSER_PWD_KEY);

            if (serverUrl == null)
            {
                serverUrl             = new Rock.Model.Attribute();
                serverUrl.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.URL_LINK).Id;
                serverUrl.IsSystem    = false;
                serverUrl.Name        = "Reporting Service URL";
                serverUrl.Description = "URL to the SQL Reporting Services Reporting Server endpoint.";
                serverUrl.Key         = SERVER_URL_KEY;
                serverUrl.IsRequired  = false;
                serverUrl.AllowSearch = false;
                serverUrl.Categories.Add(category);
                attributeService.Add(serverUrl);
                hasChanges = true;
            }

            if (serverRootPath == null)
            {
                serverRootPath             = new Rock.Model.Attribute();
                serverRootPath.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                serverRootPath.IsSystem    = false;
                serverRootPath.Name        = "Reporting Service Root Folder";
                serverRootPath.Key         = SERVER_ROOT_PATH_KEY;
                serverRootPath.Description = "Root/Base folder for Rock reports in reporting services.";
                serverRootPath.IsRequired  = false;
                serverRootPath.AllowSearch = false;
                serverRootPath.Categories.Add(category);
                attributeService.Add(serverRootPath);
                hasChanges = true;
            }

            if (contentManagerUser == null)
            {
                contentManagerUser             = new Rock.Model.Attribute();
                contentManagerUser.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT).Id;
                contentManagerUser.Name        = "Reporting Service - Content Manager Username";
                contentManagerUser.Key         = CONTENT_MANAGER_USER_KEY;
                contentManagerUser.Description = "The Reporting Server Content Manager (Report Administrator) User Name. (i.e. domain\\user format)";
                contentManagerUser.IsRequired  = false;
                contentManagerUser.AllowSearch = false;
                contentManagerUser.Categories.Add(category);
                attributeService.Add(contentManagerUser);
                hasChanges = true;
            }

            if (contentManagerPwd == null)
            {
                contentManagerPwd             = new Rock.Model.Attribute();
                contentManagerPwd.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.ENCRYPTED_TEXT).Id;
                contentManagerPwd.Name        = "Reporting Service - Content Manager Password";
                contentManagerPwd.Key         = CONTENT_MANAGER_PWD_KEY;
                contentManagerPwd.Description = "The Content Manager Password.";
                contentManagerPwd.IsRequired  = false;
                contentManagerPwd.AllowSearch = false;
                contentManagerPwd.Categories.Add(category);
                contentManagerPwd.AttributeQualifiers.Add(new AttributeQualifier {
                    IsSystem = false, Key = "ispassword", Value = bool.TrueString
                });
                attributeService.Add(contentManagerPwd);
                hasChanges = true;
            }

            if (browserUser == null)
            {
                browserUser             = new Rock.Model.Attribute();
                browserUser.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.ENCRYPTED_TEXT).Id;
                browserUser.Name        = "Reporting Service - Browser User";
                browserUser.Key         = BROWSER_USER_KEY;
                browserUser.Description = "The Reporting Server Browser (Report Viewer) User Name. (i.e. domain\\user format)";
                browserUser.IsRequired  = false;
                browserUser.AllowSearch = false;
                browserUser.Categories.Add(category);
                attributeService.Add(browserUser);
                hasChanges = true;
            }

            if (browserPwd == null)
            {
                browserPwd             = new Rock.Model.Attribute();
                browserPwd.FieldTypeId = FieldTypeCache.Get(Rock.SystemGuid.FieldType.ENCRYPTED_TEXT).Id;
                browserPwd.Name        = "Reporting Service - Browser Password";
                browserPwd.Key         = BROWSER_PWD_KEY;
                browserPwd.Description = "The Reporting Server Browser Password.";
                browserPwd.IsRequired  = false;
                browserPwd.AllowSearch = false;
                browserPwd.Categories.Add(category);
                browserPwd.AttributeQualifiers.Add(new AttributeQualifier {
                    IsSystem = false, Key = "ispassword", Value = bool.TrueString
                });
                attributeService.Add(browserPwd);
                hasChanges = true;
            }

            if (hasChanges)
            {
                context.SaveChanges();
                GlobalAttributesCache.Clear();
            }
        }