Skip to content

Commit c3c38a3

Browse files
committed
feat: Improve filter error handling
- Fixes #76
1 parent 190b081 commit c3c38a3

File tree

10 files changed

+224
-37
lines changed

10 files changed

+224
-37
lines changed

Microsoft.SCIM.WebHostSample/Provider/InMemoryGroupProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
122122

123123
if (queryFilter.FilterOperator != ComparisonOperator.Equals)
124124
{
125-
throw new NotSupportedException(string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, queryFilter.FilterOperator));
125+
throw new ScimTypeException(ErrorType.invalidFilter,string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, queryFilter.FilterOperator));
126126
}
127127

128128

@@ -135,7 +135,7 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
135135
}
136136
else
137137
{
138-
throw new NotSupportedException(string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterAttributePathNotSupportedTemplate, queryFilter.AttributePath));
138+
throw new ScimTypeException(ErrorType.invalidFilter,string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterAttributePathNotSupportedTemplate, queryFilter.AttributePath));
139139
}
140140
}
141141

Microsoft.SCIM.WebHostSample/Provider/InMemoryUserProvider.cs

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
134134
{
135135
if (andFilter.FilterOperator != ComparisonOperator.Equals)
136136
{
137-
throw new NotSupportedException(
138-
string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
137+
throw new ScimTypeException(ErrorType.invalidFilter,
138+
string.Format(
139+
SystemForCrossDomainIdentityManagementServiceResources
140+
.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
139141
}
140142

141143
var id = andFilter.ComparisonValue;
@@ -147,7 +149,7 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
147149
{
148150
if (andFilter.FilterOperator != ComparisonOperator.Equals)
149151
{
150-
throw new NotSupportedException(
152+
throw new ScimTypeException(ErrorType.invalidFilter,
151153
string.Format(
152154
SystemForCrossDomainIdentityManagementServiceResources
153155
.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
@@ -164,8 +166,10 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
164166
{
165167
if (andFilter.FilterOperator != ComparisonOperator.Equals)
166168
{
167-
throw new NotSupportedException(
168-
string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
169+
throw new ScimTypeException(ErrorType.invalidFilter,
170+
string.Format(
171+
SystemForCrossDomainIdentityManagementServiceResources
172+
.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
169173
}
170174

171175
string externalIdentifier = andFilter.ComparisonValue;
@@ -179,8 +183,10 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
179183
{
180184
if (andFilter.FilterOperator != ComparisonOperator.Equals)
181185
{
182-
throw new NotSupportedException(
183-
string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
186+
throw new ScimTypeException(ErrorType.invalidFilter,
187+
string.Format(
188+
SystemForCrossDomainIdentityManagementServiceResources
189+
.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
184190
}
185191

186192
bool active = bool.Parse(andFilter.ComparisonValue);
@@ -192,8 +198,10 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
192198
{
193199
if (andFilter.FilterOperator != ComparisonOperator.Equals)
194200
{
195-
throw new NotSupportedException(
196-
string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
201+
throw new ScimTypeException(ErrorType.invalidFilter,
202+
string.Format(
203+
SystemForCrossDomainIdentityManagementServiceResources
204+
.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
197205
}
198206

199207
var displayName = andFilter.ComparisonValue;
@@ -216,15 +224,16 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
216224
predicateAnd = predicateAnd.And(p => p.Metadata.LastModified <= comparisonValue);
217225
}
218226
else
219-
throw new NotSupportedException(
220-
string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
221-
222-
223-
227+
throw new ScimTypeException(ErrorType.invalidFilter,
228+
string.Format(
229+
SystemForCrossDomainIdentityManagementServiceResources
230+
.ExceptionFilterOperatorNotSupportedTemplate, andFilter.FilterOperator));
224231
}
225232
else
226-
throw new NotSupportedException(
227-
string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterAttributePathNotSupportedTemplate, andFilter.AttributePath));
233+
throw new ScimTypeException(ErrorType.invalidFilter,
234+
string.Format(
235+
SystemForCrossDomainIdentityManagementServiceResources
236+
.ExceptionFilterAttributePathNotSupportedTemplate, andFilter.AttributePath));
228237

229238
currentFilter = andFilter;
230239
andFilter = andFilter.AdditionalFilter;

Microsoft.SystemForCrossDomainIdentityManagement/Protocol/Filter.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private enum ComparisonOperatorValue
9191
co,
9292
sw,
9393
ew,
94+
pr,
9495
ge,
9596
gt,
9697
includes,
@@ -200,9 +201,15 @@ public string Serialize()
200201
case ComparisonOperator.BitAnd:
201202
operatorValue = ComparisonOperatorValue.bitAnd;
202203
break;
204+
case ComparisonOperator.StartsWith:
205+
operatorValue = ComparisonOperatorValue.sw;
206+
break;
203207
case ComparisonOperator.EndsWith:
204208
operatorValue = ComparisonOperatorValue.ew;
205209
break;
210+
case ComparisonOperator.Present:
211+
operatorValue = ComparisonOperatorValue.pr;
212+
break;
206213
case ComparisonOperator.Equals:
207214
operatorValue = ComparisonOperatorValue.eq;
208215
break;
@@ -218,6 +225,9 @@ public string Serialize()
218225
case ComparisonOperator.LessThan:
219226
operatorValue = ComparisonOperatorValue.lt;
220227
break;
228+
case ComparisonOperator.Contains:
229+
operatorValue = ComparisonOperatorValue.co;
230+
break;
221231
case ComparisonOperator.Includes:
222232
operatorValue = ComparisonOperatorValue.includes;
223233
break;
@@ -238,7 +248,8 @@ public string Serialize()
238248
break;
239249
default:
240250
string notSupportedValue = Enum.GetName(typeof(ComparisonOperator), this.FilterOperator);
241-
throw new NotSupportedException(notSupportedValue);
251+
252+
throw new ScimTypeException(ErrorType.invalidFilter, string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, notSupportedValue));
242253
}
243254

244255
string rightHandSide;
@@ -305,7 +316,7 @@ public static string ToString(IReadOnlyCollection<IFilter> filters)
305316
Filter clone = new Filter(filter);
306317
clone.ComparisonValue = placeholder;
307318
string currentFilter = clone.Serialize();
308-
string encodedFilter =
319+
string encodedFilter =
309320
HttpUtility
310321
.UrlEncode(currentFilter)
311322
.Replace(placeholder, filter.ComparisonValueEncoded, StringComparison.InvariantCulture);
@@ -414,4 +425,4 @@ private static void Validate(AttributeDataType? dataType, string value)
414425
}
415426
}
416427
}
417-
}
428+
}

Microsoft.SystemForCrossDomainIdentityManagement/Protocol/FilterExpression.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ private enum ComparisonOperatorValue
185185
co,
186186
sw,
187187
ew,
188+
pr,
188189
ge,
189190
gt,
190191
includes,
@@ -271,9 +272,15 @@ private ComparisonOperatorValue Operator
271272
case ComparisonOperatorValue.bitAnd:
272273
this.filterOperator = ComparisonOperator.BitAnd;
273274
break;
275+
case ComparisonOperatorValue.sw:
276+
this.filterOperator = ComparisonOperator.StartsWith;
277+
break;
274278
case ComparisonOperatorValue.ew:
275279
this.filterOperator = ComparisonOperator.EndsWith;
276280
break;
281+
case ComparisonOperatorValue.pr:
282+
this.filterOperator = ComparisonOperator.Present;
283+
break;
277284
case ComparisonOperatorValue.eq:
278285
this.filterOperator = ComparisonOperator.Equals;
279286
break;
@@ -289,6 +296,9 @@ private ComparisonOperatorValue Operator
289296
case ComparisonOperatorValue.lt:
290297
this.filterOperator = ComparisonOperator.LessThan;
291298
break;
299+
case ComparisonOperatorValue.co:
300+
this.filterOperator = ComparisonOperator.Contains;
301+
break;
292302
case ComparisonOperatorValue.includes:
293303
this.filterOperator = ComparisonOperator.Includes;
294304
break;
@@ -309,7 +319,7 @@ private ComparisonOperatorValue Operator
309319
break;
310320
default:
311321
string notSupported = Enum.GetName(typeof(ComparisonOperatorValue), this.Operator);
312-
throw new NotSupportedException(notSupported);
322+
throw new ScimTypeException(ErrorType.invalidFilter,string.Format(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterOperatorNotSupportedTemplate, notSupported));
313323
}
314324
this.comparisonOperator = value;
315325
}
@@ -842,4 +852,4 @@ public override string ToString()
842852
}
843853
}
844854
}
845-
}
855+
}

Microsoft.SystemForCrossDomainIdentityManagement/Schemas/ComparisonOperator.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ namespace Microsoft.SCIM
77
public enum ComparisonOperator
88
{
99
BitAnd,
10+
StartsWith,
1011
EndsWith,
1112
Equals,
1213
EqualOrGreaterThan,
1314
GreaterThan,
1415
EqualOrLessThan,
1516
LessThan,
17+
Contains,
1618
Includes,
1719
IsMemberOf,
1820
MatchesExpression,
1921
NotBitAnd,
2022
NotEquals,
21-
NotMatchesExpression
23+
NotMatchesExpression,
24+
Present
2225
}
23-
}
26+
}

0 commit comments

Comments
 (0)