SCIM v2
`scim_v2` is a Rust crate that provides utilities for working with the System for Cross-domain Identity Management ( SCIM) version 2.0 protocol.
Description
This crate provides functionalities for:
- Models for various SCIM resources such as `User`, `Group`, `ResourceType`, `ServiceProviderConfig`, and ` EnterpriseUser`.
- Functions for validating these resources.
- Functions for serializing these resources to JSON.
- Functions for deserializing these resources from JSON.
- SCIM filter expression parsing (RFC 7644 §3.4.2.2) via the
filtermodule. servers can return an RFC 7644 §3.12invalidFilterresponse instead of a generic parse error.
Installation
To use `scim_v2` in your project, add the following to your `Cargo.toml`:
[]
= "0.4"
Usage
Here are some examples of how you can use this crate:
Validating a User
use User;
let user = User ;
match user.validate
Serializing a User to JSON
use User;
use schema_urns;
let user = User ;
match user.serialize
Deserializing a User from JSON
use User;
let user_json = r#"{"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"], "userName": "jdoe@example.com"}"#;
match
You can also use a built-in deserialize function if you'd prefer.
use User;
let user_json = r#"{"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"], "userName": "jdoe@example.com"}"#;
match deserialize
Parsing a SCIM filter
use FromStr;
use Filter;
let filter = from_str
.expect;
println!;
Filters parsed via Filter::from_str or deserialization are rejected if their
AST exceeds filter::MAX_FILTER_DEPTH (64) to prevent stack-overflow DoS from
pathologically nested input.
Tolerant filter parsing for servers
Use TolerantListQuery / TolerantSearchRequest so a malformed filter= does
not fail the whole request — letting you return an RFC 7644 §3.12
invalidFilter response while keeping startIndex, count, etc.
The suggested pattern is to deserialize into the tolerant variant, then call
.into_strict() and map_err the resulting InvalidFilterError into your
SCIM error response. After the conversion you have a StrictListQuery /
StrictSearchRequest with a fully-parsed Filter.
use ;
# ;
#
If you need to inspect the variant directly (for example, to log the raw input
without aborting), match on MaybeFilter before converting:
use MaybeFilter;
use TolerantListQuery;
let query: TolerantListQuery =
from_str
.expect;
match &query.filter
Parsing a SCIM PATCH operation
use ;
let body = r#"{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
"Operations": [
{ "op": "replace", "path": "userName", "value": "new@example.com" }
]
}"#;
let patch: PatchOp = from_str.expect;
for op in &patch.operations
Using custom ID types
User, Group, Member, Resource, and ListResponse are generic over their
ID type, defaulting to String. Substitute uuid::Uuid, i64, or any
Serialize + DeserializeOwned type.
use User;
use Uuid;
let user: = User ;
For more examples and usage details, refer to the documentation of each function and struct.
Regenerating the filter parser
The SCIM filter parser (src/filter_parser.rs) is pre-generated from src/filter_parser.lalrpop
using LALRPOP. The generated file is committed
to the repository so no build script is required.
If you modify src/filter_parser.lalrpop, regenerate src/filter_parser.rs by running:
Commit both src/filter_parser.lalrpop and the updated src/filter_parser.rs together.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.