Struct Resource

Source
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: String

The 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

Source

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 identifier
  • data - 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(())
}
Source

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.

Source

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.

Source

pub fn get_id(&self) -> Option<&str>

Get the unique identifier of this resource.

Source

pub fn set_id(&mut self, id: &str) -> ValidationResult<()>

Set the unique identifier of this resource.

Source

pub fn get(&self, key: &str) -> Option<&Value>

Get an attribute value from the resource.

Source

pub fn get_username(&self) -> Option<&str>

Get the userName field for User resources.

Source

pub fn get_name(&self) -> Option<&Name>

Get the name field for User resources.

Source

pub fn get_addresses(&self) -> Option<&MultiValuedAddresses>

Get all addresses for the resource.

Source

pub fn get_phone_numbers(&self) -> Option<&MultiValuedPhoneNumbers>

Get all phone numbers for the resource.

Source

pub fn get_emails(&self) -> Option<&MultiValuedEmails>

Get all emails for the resource.

Source

pub fn get_members(&self) -> Option<&GroupMembers>

Get all group members for the resource.

Source

pub fn set_name(&mut self, name: Name)

Set the name for the resource.

Source

pub fn set_addresses(&mut self, addresses: MultiValuedAddresses)

Set addresses for the resource.

Source

pub fn set_phone_numbers(&mut self, phone_numbers: MultiValuedPhoneNumbers)

Set phone numbers for the resource.

Source

pub fn set_emails(&mut self, emails: MultiValuedEmails)

Set emails for the resource.

Source

pub fn set_members(&mut self, members: GroupMembers)

Set group members for the resource.

Source

pub fn add_address(&mut self, address: Address) -> ValidationResult<()>

Add an address to the resource.

Source

pub fn add_phone_number( &mut self, phone_number: PhoneNumber, ) -> ValidationResult<()>

Add a phone number to the resource.

Source

pub fn add_email(&mut self, email: EmailAddress) -> ValidationResult<()>

Add an email to the resource.

Source

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
Source

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 set
  • value - The value to set
Source

pub fn get_schemas(&self) -> Vec<String>

Get the schemas associated with this resource.

Source

pub fn get_schema_uris(&self) -> &[SchemaUri]

Get the validated schema URIs.

Source

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.

Source

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.

Source

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.

Source

pub fn get_external_id(&self) -> Option<&str>

Get the external id if present.

Source

pub fn get_meta(&self) -> Option<&Meta>

Get the meta attributes if present.

Source

pub fn set_meta(&mut self, meta: Meta)

Set meta attributes for the resource.

Source

pub fn create_meta(&mut self, base_url: &str) -> ValidationResult<()>

Create meta attributes for a new resource.

Source

pub fn update_meta(&mut self)

Update meta attributes with current timestamp.

Trait Implementations§

Source§

impl Clone for Resource

Source§

fn clone(&self) -> Resource

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Resource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Resource

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Resource

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> TenantValidator for T

Source§

fn validate_tenant_context( &self, expected_tenant_id: &str, context: &RequestContext, ) -> Result<(), String>

Validate that the context has the expected tenant.
Source§

fn validate_single_tenant_context( &self, context: &RequestContext, ) -> Result<(), String>

Validate that the context is for single-tenant operation.
Source§

fn require_tenant_context(&self, context: &RequestContext) -> Result<(), String>

Extract tenant context or return error for multi-tenant operations.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,