pub struct Resource {
pub resource_type: String,
pub id: Option<ResourceId>,
pub schemas: Vec<SchemaUri>,
pub external_id: Option<ExternalId>,
pub user_name: Option<UserName>,
pub meta: Option<Meta>,
pub name: Option<Name>,
pub addresses: Option<MultiValuedAddresses>,
pub phone_numbers: Option<MultiValuedPhoneNumbers>,
pub emails: Option<MultiValuedEmails>,
pub members: Option<GroupMembers>,
pub attributes: Map<String, Value>,
}Expand description
Generic SCIM resource representation with type-safe core attributes.
This hybrid design uses value objects for core validated primitives while maintaining JSON flexibility for extensible attributes. The design ensures compile-time safety for critical fields while preserving SCIM’s extensibility.
Fields§
§resource_type: StringThe type of this resource (e.g., “User”, “Group”)
id: Option<ResourceId>Validated resource identifier (required for most operations)
schemas: Vec<SchemaUri>Validated schema URIs
external_id: Option<ExternalId>Validated external identifier (optional)
user_name: Option<UserName>Validated username (for User resources)
meta: Option<Meta>Validated meta attributes (optional)
name: Option<Name>Validated name attributes (for User resources)
addresses: Option<MultiValuedAddresses>Validated addresses (multi-valued with primary support)
phone_numbers: Option<MultiValuedPhoneNumbers>Validated phone numbers (multi-valued with primary support)
emails: Option<MultiValuedEmails>Validated email addresses (multi-valued with primary support)
members: Option<GroupMembers>Group members (for Group resources)
attributes: Map<String, Value>Extended attributes and complex data as JSON
Implementations§
Source§impl Resource
impl Resource
Sourcepub fn from_json(resource_type: String, data: Value) -> ValidationResult<Self>
pub fn from_json(resource_type: String, data: Value) -> ValidationResult<Self>
Create a new resource from validated JSON data.
This method extracts and validates core primitives while preserving other attributes in the flexible JSON structure.
§Arguments
resource_type- The SCIM resource type identifierdata- The resource data as a JSON value
§Example
use scim_server::Resource;
use serde_json::json;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let user_data = json!({
"id": "12345",
"schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
"userName": "jdoe",
"displayName": "John Doe"
});
let resource = Resource::from_json("User".to_string(), user_data)?;
Ok(())
}Sourcepub fn new(
resource_type: String,
id: Option<ResourceId>,
schemas: Vec<SchemaUri>,
external_id: Option<ExternalId>,
user_name: Option<UserName>,
attributes: Map<String, Value>,
) -> Self
pub fn new( resource_type: String, id: Option<ResourceId>, schemas: Vec<SchemaUri>, external_id: Option<ExternalId>, user_name: Option<UserName>, attributes: Map<String, Value>, ) -> Self
Create a new resource with validated core fields.
This is the preferred constructor for new resources where core fields are already validated.
Sourcepub fn new_with_meta(
resource_type: String,
id: Option<ResourceId>,
schemas: Vec<SchemaUri>,
external_id: Option<ExternalId>,
user_name: Option<UserName>,
meta: Option<Meta>,
attributes: Map<String, Value>,
) -> Self
pub fn new_with_meta( resource_type: String, id: Option<ResourceId>, schemas: Vec<SchemaUri>, external_id: Option<ExternalId>, user_name: Option<UserName>, meta: Option<Meta>, attributes: Map<String, Value>, ) -> Self
Create a new resource with validated core fields including meta.
Extended constructor that includes meta attributes.
Sourcepub fn set_id(&mut self, id: &str) -> ValidationResult<()>
pub fn set_id(&mut self, id: &str) -> ValidationResult<()>
Set the unique identifier of this resource.
Sourcepub fn get_username(&self) -> Option<&str>
pub fn get_username(&self) -> Option<&str>
Get the userName field for User resources.
Sourcepub fn get_addresses(&self) -> Option<&MultiValuedAddresses>
pub fn get_addresses(&self) -> Option<&MultiValuedAddresses>
Get all addresses for the resource.
Sourcepub fn get_phone_numbers(&self) -> Option<&MultiValuedPhoneNumbers>
pub fn get_phone_numbers(&self) -> Option<&MultiValuedPhoneNumbers>
Get all phone numbers for the resource.
Sourcepub fn get_emails(&self) -> Option<&MultiValuedEmails>
pub fn get_emails(&self) -> Option<&MultiValuedEmails>
Get all emails for the resource.
Sourcepub fn get_members(&self) -> Option<&GroupMembers>
pub fn get_members(&self) -> Option<&GroupMembers>
Get all group members for the resource.
Sourcepub fn set_addresses(&mut self, addresses: MultiValuedAddresses)
pub fn set_addresses(&mut self, addresses: MultiValuedAddresses)
Set addresses for the resource.
Sourcepub fn set_phone_numbers(&mut self, phone_numbers: MultiValuedPhoneNumbers)
pub fn set_phone_numbers(&mut self, phone_numbers: MultiValuedPhoneNumbers)
Set phone numbers for the resource.
Sourcepub fn set_emails(&mut self, emails: MultiValuedEmails)
pub fn set_emails(&mut self, emails: MultiValuedEmails)
Set emails for the resource.
Sourcepub fn set_members(&mut self, members: GroupMembers)
pub fn set_members(&mut self, members: GroupMembers)
Set group members for the resource.
Sourcepub fn add_address(&mut self, address: Address) -> ValidationResult<()>
pub fn add_address(&mut self, address: Address) -> ValidationResult<()>
Add an address to the resource.
Sourcepub fn add_phone_number(
&mut self,
phone_number: PhoneNumber,
) -> ValidationResult<()>
pub fn add_phone_number( &mut self, phone_number: PhoneNumber, ) -> ValidationResult<()>
Add a phone number to the resource.
Sourcepub fn add_email(&mut self, email: EmailAddress) -> ValidationResult<()>
pub fn add_email(&mut self, email: EmailAddress) -> ValidationResult<()>
Add an email to the resource.
Sourcepub fn get_attribute(&self, attribute_name: &str) -> Option<&Value>
pub fn get_attribute(&self, attribute_name: &str) -> Option<&Value>
Get a specific attribute value from the extended attributes.
§Arguments
attribute_name- The name of the attribute to retrieve
Sourcepub fn set_attribute(&mut self, attribute_name: String, value: Value)
pub fn set_attribute(&mut self, attribute_name: String, value: Value)
Set a specific attribute value in the extended attributes.
§Arguments
attribute_name- The name of the attribute to setvalue- The value to set
Sourcepub fn get_schemas(&self) -> Vec<String>
pub fn get_schemas(&self) -> Vec<String>
Get the schemas associated with this resource.
Sourcepub fn get_schema_uris(&self) -> &[SchemaUri]
pub fn get_schema_uris(&self) -> &[SchemaUri]
Get the validated schema URIs.
Sourcepub fn add_metadata(
&mut self,
base_url: &str,
created: &str,
last_modified: &str,
)
pub fn add_metadata( &mut self, base_url: &str, created: &str, last_modified: &str, )
Add metadata to the resource.
This method sets common SCIM metadata fields like resourceType, created, lastModified, and location using the new Meta value object.
§Deprecated
This method is deprecated in favor of create_meta() which uses type-safe Meta value objects.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Check if this resource is active.
Returns the value of the “active” field, defaulting to true if not present.
Sourcepub fn to_json(&self) -> ValidationResult<Value>
pub fn to_json(&self) -> ValidationResult<Value>
Convert the resource to JSON format for serialization.
This combines the type-safe core fields with the extended attributes into a single JSON object.
Sourcepub fn get_external_id(&self) -> Option<&str>
pub fn get_external_id(&self) -> Option<&str>
Get the external id if present.
Sourcepub fn create_meta(&mut self, base_url: &str) -> ValidationResult<()>
pub fn create_meta(&mut self, base_url: &str) -> ValidationResult<()>
Create meta attributes for a new resource.
Sourcepub fn update_meta(&mut self)
pub fn update_meta(&mut self)
Update meta attributes with current timestamp.