public HttpResponseMessage UpdateGeneralSettings(AzureADProviderSettings settings)
        {
            try
            {
                var config = new AzureConfig(AzureConfig.ServiceName, PortalId);
                if (!UserInfo.IsSuperUser)
                {
                    if (config.UseGlobalSettings || config.UseGlobalSettings != settings.UseGlobalSettings)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Forbidden, "Only super users can change this setting"));
                    }
                }

                AzureADProviderSettings.SaveGeneralSettings(AzureConfig.ServiceName, PortalId, settings);

                // If UseGlobalSettigns was set to false, we have to create mappings if there're no mappings for the current portal
                if (config.UseGlobalSettings != settings.UseGlobalSettings && settings.UseGlobalSettings == false)
                {
                    PrepareUserMappingsForCurrentPortal();
                }
                return(Request.CreateResponse(HttpStatusCode.OK, new { }));
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
 public HttpResponseMessage UpdateSettings(AzureADProviderSettings settings)
 {
     try
     {
         AzureADProviderSettings.SaveSettings("Azure", PortalId, settings);
         return(Request.CreateResponse(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
 public HttpResponseMessage GetSettings()
 {
     try
     {
         var settings = AzureADProviderSettings.LoadSettings("Azure", PortalId);
         return(Request.CreateResponse(HttpStatusCode.OK, settings));
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }
示例#4
0
        public static void SaveSettings(string service, int portalId, AzureADProviderSettings settings)
        {
            var config = new AzureConfig(service, portalId)
            {
                TenantId     = settings.TenantId,
                APIKey       = settings.ApiKey,
                APISecret    = settings.ApiSecret,
                AutoRedirect = settings.AutoRedirect,
                Enabled      = settings.Enabled
            };

            AzureConfig.UpdateConfig(config);
        }
        public static void SaveGeneralSettings(string service, int portalId, AzureADProviderSettings settings)
        {
            var config = new AzureConfig(service, portalId)
            {
                TenantId          = settings.TenantId,
                APIKey            = settings.ApiKey,
                APISecret         = settings.ApiSecret,
                RedirectUri       = settings.RedirectUri,
                OnErrorUri        = settings.OnErrorUri,
                AutoRedirect      = settings.AutoRedirect,
                AutoAuthorize     = settings.AutoAuthorize,
                Enabled           = settings.Enabled,
                UseGlobalSettings = settings.UseGlobalSettings
            };

            AzureConfig.UpdateConfig(config);
        }
        public static void SaveAdvancedSettings(string service, int portalId, AzureADProviderSettings settings)
        {
            var config = new AzureConfig(service, portalId)
            {
                AADApplicationId       = settings.AadAppClientId,
                AADApplicationKey      = settings.AadAppSecret,
                JwtAudiences           = settings.JwtAudiences,
                RoleSyncEnabled        = settings.RoleSyncEnabled,
                ProfileSyncEnabled     = settings.ProfileSyncEnabled,
                JwtAuthEnabled         = settings.JwtAuthEnabled,
                APIResource            = settings.ApiResource + (!string.IsNullOrEmpty(settings.ApiResource.Trim()) && !settings.ApiResource.EndsWith("/") ? "/" : ""),
                Scopes                 = settings.Scopes,
                UsernamePrefixEnabled  = settings.UsernamePrefixEnabled,
                GroupNamePrefixEnabled = settings.GroupNamePrefixEnabled
            };

            AzureConfig.UpdateConfig(config);
        }
 public HttpResponseMessage UpdateAdvancedSettings(AzureADProviderSettings settings)
 {
     try
     {
         if (!UserInfo.IsSuperUser)
         {
             var config = new AzureConfig(AzureConfig.ServiceName, PortalId);
             if (config.UseGlobalSettings || config.UseGlobalSettings != settings.UseGlobalSettings)
             {
                 return(Request.CreateResponse(HttpStatusCode.Forbidden, "Only super users can change this setting"));
             }
         }
         AzureADProviderSettings.SaveAdvancedSettings(AzureConfig.ServiceName, PortalId, settings);
         return(Request.CreateResponse(HttpStatusCode.OK, new { Success = true }));
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
     }
 }