saml_rs/browser/
endpoints.rs1use super::bindings::{LogoutBinding, SsoRequestBinding, SsoResponseBinding};
6use crate::error::SamlError;
7use crate::metadata::Endpoint;
8use crate::model::EndpointUrl;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct SsoEndpoint {
13 binding: SsoRequestBinding,
14 url: EndpointUrl,
15}
16
17impl SsoEndpoint {
18 pub fn new(binding: SsoRequestBinding, url: EndpointUrl) -> Self {
20 Self { binding, url }
21 }
22
23 pub fn redirect(url: impl Into<String>) -> Result<Self, SamlError> {
30 Ok(Self::new(
31 SsoRequestBinding::Redirect,
32 EndpointUrl::try_new(url)?,
33 ))
34 }
35
36 pub fn post(url: impl Into<String>) -> Result<Self, SamlError> {
43 Ok(Self::new(
44 SsoRequestBinding::Post,
45 EndpointUrl::try_new(url)?,
46 ))
47 }
48
49 pub fn simple_sign(url: impl Into<String>) -> Result<Self, SamlError> {
56 Ok(Self::new(
57 SsoRequestBinding::SimpleSign,
58 EndpointUrl::try_new(url)?,
59 ))
60 }
61
62 pub fn try_from_raw(endpoint: Endpoint) -> Result<Self, SamlError> {
69 Ok(Self::new(
70 SsoRequestBinding::try_from(endpoint.binding)?,
71 EndpointUrl::try_new(endpoint.location)?,
72 ))
73 }
74
75 pub fn to_raw(&self) -> Endpoint {
77 Endpoint {
78 binding: self.binding.as_binding(),
79 location: self.url.as_str().to_string(),
80 index: None,
81 is_default: false,
82 }
83 }
84
85 pub fn binding(&self) -> SsoRequestBinding {
87 self.binding
88 }
89
90 pub fn location(&self) -> &EndpointUrl {
92 &self.url
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, Eq)]
98pub struct AcsEndpoint {
99 binding: SsoResponseBinding,
100 url: EndpointUrl,
101 index: Option<u16>,
102 is_default: bool,
103}
104
105impl AcsEndpoint {
106 pub fn new(binding: SsoResponseBinding, url: EndpointUrl) -> Self {
108 Self {
109 binding,
110 url,
111 index: None,
112 is_default: false,
113 }
114 }
115
116 pub fn post(url: impl Into<String>) -> Result<Self, SamlError> {
123 Ok(Self::new(
124 SsoResponseBinding::Post,
125 EndpointUrl::try_new(url)?,
126 ))
127 }
128
129 pub fn simple_sign(url: impl Into<String>) -> Result<Self, SamlError> {
136 Ok(Self::new(
137 SsoResponseBinding::SimpleSign,
138 EndpointUrl::try_new(url)?,
139 ))
140 }
141
142 pub fn with_index(mut self, index: u16) -> Self {
144 self.index = Some(index);
145 self
146 }
147
148 pub fn mark_default(mut self) -> Self {
150 self.is_default = true;
151 self
152 }
153
154 pub(crate) fn with_default_flag(mut self, is_default: bool) -> Self {
155 self.is_default = is_default;
156 self
157 }
158
159 pub fn try_from_raw(endpoint: Endpoint) -> Result<Self, SamlError> {
166 Ok(Self {
167 binding: SsoResponseBinding::try_from(endpoint.binding)?,
168 url: EndpointUrl::try_new(endpoint.location)?,
169 index: endpoint.index,
170 is_default: endpoint.is_default,
171 })
172 }
173
174 pub fn to_raw(&self) -> Endpoint {
176 Endpoint {
177 binding: self.binding.as_binding(),
178 location: self.url.as_str().to_string(),
179 index: self.index,
180 is_default: self.is_default,
181 }
182 }
183
184 pub fn binding(&self) -> SsoResponseBinding {
186 self.binding
187 }
188
189 pub fn location(&self) -> &EndpointUrl {
191 &self.url
192 }
193
194 pub fn index(&self) -> Option<u16> {
196 self.index
197 }
198
199 pub fn is_default(&self) -> bool {
201 self.is_default
202 }
203}
204
205#[derive(Debug, Clone, PartialEq, Eq)]
207pub struct SloEndpoint {
208 binding: LogoutBinding,
209 url: EndpointUrl,
210}
211
212impl SloEndpoint {
213 pub fn new(binding: LogoutBinding, url: EndpointUrl) -> Self {
215 Self { binding, url }
216 }
217
218 pub fn redirect(url: impl Into<String>) -> Result<Self, SamlError> {
225 Ok(Self::new(
226 LogoutBinding::Redirect,
227 EndpointUrl::try_new(url)?,
228 ))
229 }
230
231 pub fn post(url: impl Into<String>) -> Result<Self, SamlError> {
238 Ok(Self::new(LogoutBinding::Post, EndpointUrl::try_new(url)?))
239 }
240
241 pub fn simple_sign(url: impl Into<String>) -> Result<Self, SamlError> {
248 Ok(Self::new(
249 LogoutBinding::SimpleSign,
250 EndpointUrl::try_new(url)?,
251 ))
252 }
253
254 pub fn try_from_raw(endpoint: Endpoint) -> Result<Self, SamlError> {
261 Ok(Self::new(
262 LogoutBinding::try_from(endpoint.binding)?,
263 EndpointUrl::try_new(endpoint.location)?,
264 ))
265 }
266
267 pub fn to_raw(&self) -> Endpoint {
269 Endpoint {
270 binding: self.binding.as_binding(),
271 location: self.url.as_str().to_string(),
272 index: None,
273 is_default: false,
274 }
275 }
276
277 pub fn binding(&self) -> LogoutBinding {
279 self.binding
280 }
281
282 pub fn location(&self) -> &EndpointUrl {
284 &self.url
285 }
286}