pub struct Pending<Message: PendingMessage> { /* private fields */ }Expand description
Pending SAML message correlation state.
Implementations§
Source§impl<Message: PendingMessage> Pending<Message>
impl<Message: PendingMessage> Pending<Message>
Sourcepub fn with_issue_instant(self, issued_at: SamlInstant) -> Self
pub fn with_issue_instant(self, issued_at: SamlInstant) -> Self
Record an issue instant.
Sourcepub fn with_expiration(self, expires_at: SamlInstant) -> Self
pub fn with_expiration(self, expires_at: SamlInstant) -> Self
Record an expiration instant.
Sourcepub fn id(&self) -> &MessageId
pub fn id(&self) -> &MessageId
SAML protocol message ID.
Examples found in repository?
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 use saml_rs::{
13 AcsEndpoint, AuthnRequest, BrowserInput, CertificatePem, Credentials, EntityId, IdpConfig,
14 IdpDescriptor, IdpValidationPolicy, LogoutRequest, LogoutResponse, MetadataTrustPolicy,
15 NameId, PrivateKeyPem, ReplayPolicy, RespondSlo, RespondSso, Saml, SamlValidationContext,
16 SloEndpoint, SpConfig, SpDescriptor, SpValidationPolicy, SsoEndpoint, SsoResponse,
17 StartSlo, StartSso, Subject,
18 };
19 use std::time::SystemTime;
20
21 let privkey = include_str!("../tests/fixtures/key/sp_privkey.pem");
22 let cert = include_str!("../tests/fixtures/key/sp_signing_cert.cer");
23 let credentials = || Credentials {
24 signing_key: Some(PrivateKeyPem::new(privkey)),
25 signing_certificate: Some(CertificatePem::new(cert)),
26 ..Credentials::default()
27 };
28 let validation =
29 || SamlValidationContext::new(SystemTime::now(), ReplayPolicy::DisabledForCompatibility);
30
31 let sp = Saml::sp(
32 SpConfig::builder(EntityId::try_new("https://sp.example.com/metadata")?)
33 .acs_endpoint(AcsEndpoint::post("https://sp.example.com/acs")?)
34 .slo_endpoint(SloEndpoint::post("https://sp.example.com/slo")?)
35 .credentials(credentials())
36 .validation(SpValidationPolicy::strict())
37 .build()?,
38 )?;
39 let idp = Saml::idp(
40 IdpConfig::builder(EntityId::try_new("https://idp.example.com/metadata")?)
41 .sso_endpoint(SsoEndpoint::post("https://idp.example.com/sso")?)
42 .slo_endpoint(SloEndpoint::post("https://idp.example.com/slo")?)
43 .credentials(credentials())
44 .validation(IdpValidationPolicy::strict())
45 .build()?,
46 )?;
47 let sp_descriptor = SpDescriptor::from_metadata_xml_for(
48 EntityId::try_new("https://sp.example.com/metadata")?,
49 sp.metadata_xml(),
50 MetadataTrustPolicy::UnsignedForCompatibility,
51 )?;
52 let idp_descriptor = IdpDescriptor::from_metadata_xml_for(
53 EntityId::try_new("https://idp.example.com/metadata")?,
54 idp.metadata_xml(),
55 MetadataTrustPolicy::UnsignedForCompatibility,
56 )?;
57
58 let sso = sp.start_sso(&idp_descriptor, StartSso::post())?;
59 let request = idp.receive_sso(
60 &sp_descriptor,
61 BrowserInput::<AuthnRequest>::post(sso.outbound.post_form()?.fields().to_vec()),
62 validation(),
63 )?;
64 let response = idp.respond_sso(
65 &sp_descriptor,
66 &request,
67 Subject::new(NameId::new("alice@example.com", None), Vec::new()),
68 RespondSso::post(),
69 )?;
70 let session = sp.finish_sso(
71 &idp_descriptor,
72 &sso.pending,
73 BrowserInput::<SsoResponse>::post(response.post_form()?.fields().to_vec()),
74 validation(),
75 )?;
76
77 let subject = session
78 .logout_subject()
79 .ok_or("session has no logout subject")?;
80 let logout = sp.start_slo(&idp_descriptor, subject, StartSlo::post())?;
81 println!("SP -> LogoutRequest id = {}", logout.pending.id().as_str());
82
83 let logout_request = idp.receive_slo(
84 &sp_descriptor,
85 BrowserInput::<LogoutRequest>::post(logout.outbound.post_form()?.fields().to_vec()),
86 validation(),
87 )?;
88 let logout_response = idp.respond_slo(
89 &sp_descriptor,
90 &logout_request,
91 RespondSlo::post().relay_state(logout.pending.relay_state().clone()),
92 )?;
93 let completed = sp.finish_slo(
94 &idp_descriptor,
95 &logout.pending,
96 BrowserInput::<LogoutResponse>::post(logout_response.post_form()?.fields().to_vec()),
97 validation(),
98 )?;
99 println!(
100 "SP <- LogoutResponse status = {}",
101 completed.status().unwrap_or("missing")
102 );
103 Ok(())
104}Sourcepub fn relay_state(&self) -> &RelayStateParam
pub fn relay_state(&self) -> &RelayStateParam
RelayState state.
Examples found in repository?
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 use saml_rs::{
13 AcsEndpoint, AuthnRequest, BrowserInput, CertificatePem, Credentials, EntityId, IdpConfig,
14 IdpDescriptor, IdpValidationPolicy, LogoutRequest, LogoutResponse, MetadataTrustPolicy,
15 NameId, PrivateKeyPem, ReplayPolicy, RespondSlo, RespondSso, Saml, SamlValidationContext,
16 SloEndpoint, SpConfig, SpDescriptor, SpValidationPolicy, SsoEndpoint, SsoResponse,
17 StartSlo, StartSso, Subject,
18 };
19 use std::time::SystemTime;
20
21 let privkey = include_str!("../tests/fixtures/key/sp_privkey.pem");
22 let cert = include_str!("../tests/fixtures/key/sp_signing_cert.cer");
23 let credentials = || Credentials {
24 signing_key: Some(PrivateKeyPem::new(privkey)),
25 signing_certificate: Some(CertificatePem::new(cert)),
26 ..Credentials::default()
27 };
28 let validation =
29 || SamlValidationContext::new(SystemTime::now(), ReplayPolicy::DisabledForCompatibility);
30
31 let sp = Saml::sp(
32 SpConfig::builder(EntityId::try_new("https://sp.example.com/metadata")?)
33 .acs_endpoint(AcsEndpoint::post("https://sp.example.com/acs")?)
34 .slo_endpoint(SloEndpoint::post("https://sp.example.com/slo")?)
35 .credentials(credentials())
36 .validation(SpValidationPolicy::strict())
37 .build()?,
38 )?;
39 let idp = Saml::idp(
40 IdpConfig::builder(EntityId::try_new("https://idp.example.com/metadata")?)
41 .sso_endpoint(SsoEndpoint::post("https://idp.example.com/sso")?)
42 .slo_endpoint(SloEndpoint::post("https://idp.example.com/slo")?)
43 .credentials(credentials())
44 .validation(IdpValidationPolicy::strict())
45 .build()?,
46 )?;
47 let sp_descriptor = SpDescriptor::from_metadata_xml_for(
48 EntityId::try_new("https://sp.example.com/metadata")?,
49 sp.metadata_xml(),
50 MetadataTrustPolicy::UnsignedForCompatibility,
51 )?;
52 let idp_descriptor = IdpDescriptor::from_metadata_xml_for(
53 EntityId::try_new("https://idp.example.com/metadata")?,
54 idp.metadata_xml(),
55 MetadataTrustPolicy::UnsignedForCompatibility,
56 )?;
57
58 let sso = sp.start_sso(&idp_descriptor, StartSso::post())?;
59 let request = idp.receive_sso(
60 &sp_descriptor,
61 BrowserInput::<AuthnRequest>::post(sso.outbound.post_form()?.fields().to_vec()),
62 validation(),
63 )?;
64 let response = idp.respond_sso(
65 &sp_descriptor,
66 &request,
67 Subject::new(NameId::new("alice@example.com", None), Vec::new()),
68 RespondSso::post(),
69 )?;
70 let session = sp.finish_sso(
71 &idp_descriptor,
72 &sso.pending,
73 BrowserInput::<SsoResponse>::post(response.post_form()?.fields().to_vec()),
74 validation(),
75 )?;
76
77 let subject = session
78 .logout_subject()
79 .ok_or("session has no logout subject")?;
80 let logout = sp.start_slo(&idp_descriptor, subject, StartSlo::post())?;
81 println!("SP -> LogoutRequest id = {}", logout.pending.id().as_str());
82
83 let logout_request = idp.receive_slo(
84 &sp_descriptor,
85 BrowserInput::<LogoutRequest>::post(logout.outbound.post_form()?.fields().to_vec()),
86 validation(),
87 )?;
88 let logout_response = idp.respond_slo(
89 &sp_descriptor,
90 &logout_request,
91 RespondSlo::post().relay_state(logout.pending.relay_state().clone()),
92 )?;
93 let completed = sp.finish_slo(
94 &idp_descriptor,
95 &logout.pending,
96 BrowserInput::<LogoutResponse>::post(logout_response.post_form()?.fields().to_vec()),
97 validation(),
98 )?;
99 println!(
100 "SP <- LogoutResponse status = {}",
101 completed.status().unwrap_or("missing")
102 );
103 Ok(())
104}Sourcepub fn peer_entity_id(&self) -> &EntityId
pub fn peer_entity_id(&self) -> &EntityId
Peer entity ID.
Sourcepub fn issued_at(&self) -> Option<&SamlInstant>
pub fn issued_at(&self) -> Option<&SamlInstant>
Issue instant, if recorded.
Sourcepub fn expires_at(&self) -> Option<&SamlInstant>
pub fn expires_at(&self) -> Option<&SamlInstant>
Expiration instant, if recorded.
Source§impl Pending<AuthnRequest>
impl Pending<AuthnRequest>
Sourcepub fn try_new(
request_id: MessageId,
relay_state: RelayStateParam,
acs: AcsEndpoint,
response_binding: SsoResponseBinding,
idp_entity_id: EntityId,
) -> Result<Self, SamlError>
pub fn try_new( request_id: MessageId, relay_state: RelayStateParam, acs: AcsEndpoint, response_binding: SsoResponseBinding, idp_entity_id: EntityId, ) -> Result<Self, SamlError>
Create pending AuthnRequest state without storing keys or metadata.
§Errors
Returns SamlError::Invalid when the RelayState state is malformed,
the IdP entity ID is empty, or the selected ACS binding does not match
the expected response binding.
Sourcepub fn with_request_binding(self, request_binding: SsoRequestBinding) -> Self
pub fn with_request_binding(self, request_binding: SsoRequestBinding) -> Self
Record the outbound AuthnRequest binding selected for dispatch.
Sourcepub fn from_snapshot(
snapshot: PendingSnapshot<AuthnRequest>,
) -> Result<Self, SamlError>
pub fn from_snapshot( snapshot: PendingSnapshot<AuthnRequest>, ) -> Result<Self, SamlError>
Reconstruct pending AuthnRequest state from a snapshot.
§Errors
Returns SamlError when any snapshot field is malformed or
inconsistent.
§Examples
use saml_rs::{AuthnRequest, Pending, PendingSnapshot, RelayStateParam};
let snapshot = PendingSnapshot::<AuthnRequest>::authn_request(
"_request123",
RelayStateParam::absent(),
"https://idp.example.com/metadata",
"post",
"https://sp.example.com/acs",
"post",
);
let pending = Pending::<AuthnRequest>::from_snapshot(snapshot)?;
assert_eq!(pending.idp_entity_id().as_str(), "https://idp.example.com/metadata");Sourcepub fn snapshot(&self) -> PendingSnapshot<AuthnRequest>
pub fn snapshot(&self) -> PendingSnapshot<AuthnRequest>
Build a persistable snapshot.
Sourcepub fn request_id(&self) -> &MessageId
pub fn request_id(&self) -> &MessageId
Request ID.
Examples found in repository?
12fn main() -> Result<(), Box<dyn std::error::Error>> {
13 use saml_rs::{
14 AcsEndpoint, AuthnRequest, BrowserInput, CertificatePem, Credentials, EntityId, IdpConfig,
15 IdpDescriptor, IdpValidationPolicy, MetadataTrustPolicy, NameId, PrivateKeyPem,
16 RelayStateParam, ReplayPolicy, RespondSso, Saml, SamlValidationContext, SpConfig,
17 SpDescriptor, SpValidationPolicy, SsoEndpoint, SsoResponse, StartSso, Subject,
18 };
19 use std::time::SystemTime;
20
21 let privkey = include_str!("../tests/fixtures/key/sp_privkey.pem");
22 let cert = include_str!("../tests/fixtures/key/sp_signing_cert.cer");
23 let credentials = || Credentials {
24 signing_key: Some(PrivateKeyPem::new(privkey)),
25 signing_certificate: Some(CertificatePem::new(cert)),
26 ..Credentials::default()
27 };
28 let validation =
29 || SamlValidationContext::new(SystemTime::now(), ReplayPolicy::DisabledForCompatibility);
30
31 let sp = Saml::sp(
32 SpConfig::builder(EntityId::try_new("https://sp.example.com/metadata")?)
33 .acs_endpoint(AcsEndpoint::post("https://sp.example.com/acs")?)
34 .credentials(credentials())
35 .validation(SpValidationPolicy::strict())
36 .build()?,
37 )?;
38 let idp = Saml::idp(
39 IdpConfig::builder(EntityId::try_new("https://idp.example.com/metadata")?)
40 .sso_endpoint(SsoEndpoint::post("https://idp.example.com/sso")?)
41 .credentials(credentials())
42 .validation(IdpValidationPolicy::strict())
43 .build()?,
44 )?;
45
46 let sp_descriptor = SpDescriptor::from_metadata_xml_for(
47 EntityId::try_new("https://sp.example.com/metadata")?,
48 sp.metadata_xml(),
49 MetadataTrustPolicy::UnsignedForCompatibility,
50 )?;
51 let idp_descriptor = IdpDescriptor::from_metadata_xml_for(
52 EntityId::try_new("https://idp.example.com/metadata")?,
53 idp.metadata_xml(),
54 MetadataTrustPolicy::UnsignedForCompatibility,
55 )?;
56
57 let relay_state = RelayStateParam::try_from_option(Some("demo-state".to_string()))?;
58 let started = sp.start_sso(&idp_descriptor, StartSso::post().relay_state(relay_state))?;
59 println!(
60 "SP -> AuthnRequest id = {}",
61 started.pending.request_id().as_str()
62 );
63
64 let request = idp.receive_sso(
65 &sp_descriptor,
66 BrowserInput::<AuthnRequest>::post(started.outbound.post_form()?.fields().to_vec()),
67 validation(),
68 )?;
69 println!(
70 "IdP <- request issuer = {}",
71 request.message().issuer().as_str()
72 );
73
74 let response = idp.respond_sso(
75 &sp_descriptor,
76 &request,
77 Subject::new(NameId::new("alice@example.com", None), Vec::new()),
78 RespondSso::post(),
79 )?;
80
81 let session = sp.finish_sso(
82 &idp_descriptor,
83 &started.pending,
84 BrowserInput::<SsoResponse>::post(response.post_form()?.fields().to_vec()),
85 validation(),
86 );
87 let session = session?;
88 println!("SP <- authenticated = {}", session.name_id().value());
89 Ok(())
90}Sourcepub fn request_binding(&self) -> Option<SsoRequestBinding>
pub fn request_binding(&self) -> Option<SsoRequestBinding>
Request binding, when tracked.
Sourcepub fn response_binding(&self) -> SsoResponseBinding
pub fn response_binding(&self) -> SsoResponseBinding
Expected response binding.
Sourcepub fn acs(&self) -> &AcsEndpoint
pub fn acs(&self) -> &AcsEndpoint
Selected ACS endpoint.
Sourcepub fn idp_entity_id(&self) -> &EntityId
pub fn idp_entity_id(&self) -> &EntityId
Selected IdP entity ID.
Source§impl Pending<LogoutRequest>
impl Pending<LogoutRequest>
Sourcepub fn try_new(
request_id: MessageId,
relay_state: RelayStateParam,
binding: LogoutBinding,
peer_entity_id: EntityId,
) -> Result<Self, SamlError>
pub fn try_new( request_id: MessageId, relay_state: RelayStateParam, binding: LogoutBinding, peer_entity_id: EntityId, ) -> Result<Self, SamlError>
Create pending LogoutRequest state without storing keys or metadata.
§Errors
Returns SamlError::Invalid when RelayState or peer entity ID are malformed.
Sourcepub fn from_snapshot(
snapshot: PendingSnapshot<LogoutRequest>,
) -> Result<Self, SamlError>
pub fn from_snapshot( snapshot: PendingSnapshot<LogoutRequest>, ) -> Result<Self, SamlError>
Reconstruct pending LogoutRequest state from a snapshot.
AuthnRequest-only ACS snapshot fields are ignored.
§Errors
Returns SamlError when any snapshot field is malformed or
inconsistent.
§Examples
use saml_rs::{LogoutBinding, LogoutRequest, Pending, PendingSnapshot, RelayStateParam};
let snapshot = PendingSnapshot::<LogoutRequest>::logout_request(
"_logout123",
RelayStateParam::absent(),
"https://idp.example.com/metadata",
LogoutBinding::Post,
);
let pending = Pending::<LogoutRequest>::from_snapshot(snapshot)?;
assert_eq!(pending.peer_entity_id().as_str(), "https://idp.example.com/metadata");Sourcepub fn snapshot(&self) -> PendingSnapshot<LogoutRequest>
pub fn snapshot(&self) -> PendingSnapshot<LogoutRequest>
Build a persistable snapshot.
Sourcepub fn request_binding(&self) -> LogoutBinding
pub fn request_binding(&self) -> LogoutBinding
Logout request binding selected for dispatch.
Sourcepub fn response_binding(&self) -> LogoutBinding
pub fn response_binding(&self) -> LogoutBinding
Expected logout response binding.