Skip to content

Commit e2aab90

Browse files
Ticket #332 : Can disable / enable bulk
1 parent 3bb65a6 commit e2aab90

4 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/Scim/SimpleIdServer.Scim/Api/BulkController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using SimpleIdServer.Scim.DTOs;
1515
using SimpleIdServer.Scim.Exceptions;
1616
using SimpleIdServer.Scim.Extensions;
17+
using SimpleIdServer.Scim.Infrastructure;
1718
using SimpleIdServer.Scim.Persistence;
1819
using SimpleIdServer.Scim.Resources;
1920
using SimpleIdServer.Scim.Serialization;
@@ -28,6 +29,7 @@
2829
namespace SimpleIdServer.Scim.Api
2930
{
3031
[Route(SCIMEndpoints.Bulk)]
32+
[TypeFilter(typeof(ActivatorActionFilter), Arguments = new object[] { "IsBulkEnabled" })]
3133
public class BulkController : Controller
3234
{
3335
private readonly SCIMHostOptions _options;

src/Scim/SimpleIdServer.Scim/Api/ServiceProviderConfigController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public virtual IActionResult Get()
4646
})
4747
.AddComplexAttribute("bulk", schema.Id, c =>
4848
{
49-
c.AddBooleanAttribute("supported", new List<bool> { true });
49+
c.AddBooleanAttribute("supported", new List<bool> { _options.IsBulkEnabled });
5050
c.AddIntegerAttribute("maxOperations", new List<int> { _options.MaxOperations });
5151
c.AddIntegerAttribute("maxPayloadSize", new List<int> { _options.MaxPayloadSize });
5252
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) SimpleIdServer. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.Mvc.Filters;
5+
using Microsoft.Extensions.Options;
6+
using System.Net;
7+
using System.Reflection;
8+
using System.Threading.Tasks;
9+
10+
namespace SimpleIdServer.Scim.Infrastructure
11+
{
12+
public class ActivatorActionFilter : ActionFilterAttribute
13+
{
14+
private readonly bool _isEnabled = true;
15+
16+
public ActivatorActionFilter(IOptions<SCIMHostOptions> options, string propertyName)
17+
{
18+
var propertyInfo = typeof(SCIMHostOptions).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
19+
if(propertyInfo != null)
20+
{
21+
var val = propertyInfo.GetValue(options.Value);
22+
if (val != null && val.GetType() == typeof(bool)) _isEnabled = (bool)val;
23+
}
24+
}
25+
26+
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
27+
{
28+
if (!_isEnabled)
29+
{
30+
context.Result = new StatusCodeResult((int)HttpStatusCode.NotFound);
31+
return;
32+
}
33+
34+
await next();
35+
}
36+
}
37+
}

src/Scim/SimpleIdServer.Scim/SCIMHostOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,9 @@ public SCIMHostOptions()
6565
/// Function used to generate ServiceProviderConfig identifier.
6666
/// </summary>
6767
public Func<string> ServiceProviderConfigIdGenerator { get; set; } = () => Guid.NewGuid().ToString();
68+
/// <summary>
69+
/// Enable or disable bulk operations.
70+
/// </summary>
71+
public bool IsBulkEnabled { get; set; } = true;
6872
}
6973
}

0 commit comments

Comments
 (0)