use super::bindings::{LogoutBinding, SsoRequestBinding, SsoResponseBinding};
use crate::error::SamlError;
use crate::metadata::Endpoint;
use crate::model::EndpointUrl;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SsoEndpoint {
binding: SsoRequestBinding,
url: EndpointUrl,
}
impl SsoEndpoint {
pub fn new(binding: SsoRequestBinding, url: EndpointUrl) -> Self {
Self { binding, url }
}
pub fn redirect(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(
SsoRequestBinding::Redirect,
EndpointUrl::try_new(url)?,
))
}
pub fn post(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(
SsoRequestBinding::Post,
EndpointUrl::try_new(url)?,
))
}
pub fn simple_sign(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(
SsoRequestBinding::SimpleSign,
EndpointUrl::try_new(url)?,
))
}
pub fn try_from_raw(endpoint: Endpoint) -> Result<Self, SamlError> {
Ok(Self::new(
SsoRequestBinding::try_from(endpoint.binding)?,
EndpointUrl::try_new(endpoint.location)?,
))
}
pub fn to_raw(&self) -> Endpoint {
Endpoint {
binding: self.binding.as_binding(),
location: self.url.as_str().to_string(),
index: None,
is_default: false,
}
}
pub fn binding(&self) -> SsoRequestBinding {
self.binding
}
pub fn location(&self) -> &EndpointUrl {
&self.url
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AcsEndpoint {
binding: SsoResponseBinding,
url: EndpointUrl,
index: Option<u16>,
is_default: bool,
}
impl AcsEndpoint {
pub fn new(binding: SsoResponseBinding, url: EndpointUrl) -> Self {
Self {
binding,
url,
index: None,
is_default: false,
}
}
pub fn post(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(
SsoResponseBinding::Post,
EndpointUrl::try_new(url)?,
))
}
pub fn simple_sign(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(
SsoResponseBinding::SimpleSign,
EndpointUrl::try_new(url)?,
))
}
pub fn with_index(mut self, index: u16) -> Self {
self.index = Some(index);
self
}
pub fn mark_default(mut self) -> Self {
self.is_default = true;
self
}
pub(crate) fn with_default_flag(mut self, is_default: bool) -> Self {
self.is_default = is_default;
self
}
pub fn try_from_raw(endpoint: Endpoint) -> Result<Self, SamlError> {
Ok(Self {
binding: SsoResponseBinding::try_from(endpoint.binding)?,
url: EndpointUrl::try_new(endpoint.location)?,
index: endpoint.index,
is_default: endpoint.is_default,
})
}
pub fn to_raw(&self) -> Endpoint {
Endpoint {
binding: self.binding.as_binding(),
location: self.url.as_str().to_string(),
index: self.index,
is_default: self.is_default,
}
}
pub fn binding(&self) -> SsoResponseBinding {
self.binding
}
pub fn location(&self) -> &EndpointUrl {
&self.url
}
pub fn index(&self) -> Option<u16> {
self.index
}
pub fn is_default(&self) -> bool {
self.is_default
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SloEndpoint {
binding: LogoutBinding,
url: EndpointUrl,
}
impl SloEndpoint {
pub fn new(binding: LogoutBinding, url: EndpointUrl) -> Self {
Self { binding, url }
}
pub fn redirect(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(
LogoutBinding::Redirect,
EndpointUrl::try_new(url)?,
))
}
pub fn post(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(LogoutBinding::Post, EndpointUrl::try_new(url)?))
}
pub fn simple_sign(url: impl Into<String>) -> Result<Self, SamlError> {
Ok(Self::new(
LogoutBinding::SimpleSign,
EndpointUrl::try_new(url)?,
))
}
pub fn try_from_raw(endpoint: Endpoint) -> Result<Self, SamlError> {
Ok(Self::new(
LogoutBinding::try_from(endpoint.binding)?,
EndpointUrl::try_new(endpoint.location)?,
))
}
pub fn to_raw(&self) -> Endpoint {
Endpoint {
binding: self.binding.as_binding(),
location: self.url.as_str().to_string(),
index: None,
is_default: false,
}
}
pub fn binding(&self) -> LogoutBinding {
self.binding
}
pub fn location(&self) -> &EndpointUrl {
&self.url
}
}