1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// *VslmSessionManager* managed object manages client sessions.
///
/// Login to VSLM service is done through this interface.
/// It is SSO enabled so only login by using SamlToken is allowed.
/// This API is intended for internal use only.
#[derive(Clone)]
pub struct VslmSessionManager {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl VslmSessionManager {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// Login to the VSLM service by using SSO token.
///
/// VSLM will validate the user
/// token from the context. The delegated token passed as a parameter will be
/// used by VSLM to login to VC for authorization purposes.
/// Once login successfully returns, a new session is established for the
/// client. This session is only valid for the lifetime of the supplied
/// delegated token. Any calls made on a session which exceeds this lifetime
/// will result in a SecurityError. The client is expected to logout of the
/// current session and subsequently re-login with a new delegated token to
/// establish a new session.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### delegated_token_xml
/// The delegated token will be retrieved by the
/// client and delegated to VSLM. VSLM will use this token, on user's
/// behalf, to login to VC for authorization purposes. It is necessary
/// to convert the token to XML because the SAML token itself is
/// not a VMODL Data Object and cannot be used as a parameter.
///
/// ## Errors:
///
/// ***InvalidLogin***: if there is no token provided or the token
/// could not be validated.
pub async fn vslm_login_by_token(&self, delegated_token_xml: &str) -> Result<()> {
let input = VslmLoginByTokenRequestType {delegated_token_xml, };
self.client.invoke_void("vslm", "VslmSessionManager", &self.mo_id, "VslmLoginByToken", Some(&input)).await
}
/// Logs out of the VSLM Service.
///
/// ***Required privileges:*** StoragLifecycle.View
pub async fn vslm_logout(&self) -> Result<()> {
self.client.invoke_void("vslm", "VslmSessionManager", &self.mo_id, "VslmLogout", None).await
}
}
struct VslmLoginByTokenRequestType<'a> {
delegated_token_xml: &'a str,
}
impl<'a> miniserde::Serialize for VslmLoginByTokenRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(VslmLoginByTokenRequestTypeSer { data: self, seq: 0 }))
}
}
struct VslmLoginByTokenRequestTypeSer<'b, 'a> {
data: &'b VslmLoginByTokenRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for VslmLoginByTokenRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"VslmLoginByTokenRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("delegatedTokenXml"), &self.data.delegated_token_xml as &dyn miniserde::Serialize)),
_ => return None,
}
}
}