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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
use std::sync::Arc;
use crate::core::client::{VimClient, Result};
/// This managed object type includes methods for logging on and
/// logging off clients, determining which clients are currently
/// logged on, and forcing clients to log off.
#[derive(Clone)]
pub struct SessionManager {
client: Arc<dyn VimClient>,
mo_id: String,
}
impl SessionManager {
pub fn new(client: Arc<dyn VimClient>, mo_id: &str) -> Self {
Self {
client,
mo_id: mo_id.to_string(),
}
}
/// Acquire a session-specific ticket string which can be used to clone
/// the current session.
///
/// The caller of this operation can pass the ticket
/// value to another entity on the client. The recipient can then call
/// *SessionManager.CloneSession* with the ticket string on an unauthenticated
/// session and avoid having to re-enter credentials.
///
/// The ticket may only be used once and becomes invalid after use. The
/// ticket is also invalidated when the corresponding session is closed or
/// expires. The ticket is only valid on the server which issued it.
///
/// This sequence of operations is conceptually similar to the
/// functionality provided by *SessionManager.AcquireLocalTicket*, however the
/// methods can be used by remote clients and do not require a shared
/// filesystem for transport.
///
/// See also *SessionManager.CloneSession*.
///
/// ***Required privileges:*** System.View
///
/// ## Returns:
///
/// one-time secret ticket string.
pub async fn acquire_clone_ticket(&self) -> Result<String> {
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "AcquireCloneTicket", None).await?;
let result: String = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Creates and returns a one-time credential that may be used to make the
/// specified request.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### spec
/// specification for the service request which will be
/// invoked with the ticket.
///
/// ## Returns:
///
/// a ticket that may be used to invoke the specified request.
/// The first choice for authenticating the host is
/// *SessionManagerGenericServiceTicket.sslCertificate*.
/// If *SessionManagerGenericServiceTicket.sslCertificate* is unset, the
/// following logic is used to authenticate the host:
/// 1\. If the VC system supports the crypto hash algorithm of
/// the *SessionManagerGenericServiceTicket.sslThumbprint* or
/// *SessionManagerGenericServiceTicket.certThumbprintList* (if set),
/// they will be verified against that of the server certificate. If
/// they doesn't match, the CA certificates will be used to
/// authenticate the host.
/// 2\. If the VC system does not support the crypto hash algorithm
/// of *SessionManagerGenericServiceTicket.sslThumbprint* or
/// *SessionManagerGenericServiceTicket.certThumbprintList*, only the CA
/// certificates will be used to authenticate the host.
pub async fn acquire_generic_service_ticket(&self, spec: &dyn crate::types::traits::SessionManagerServiceRequestSpecTrait) -> Result<crate::types::structs::SessionManagerGenericServiceTicket> {
let input = AcquireGenericServiceTicketRequestType {spec, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "AcquireGenericServiceTicket", Some(&input)).await?;
let result: crate::types::structs::SessionManagerGenericServiceTicket = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Acquires a one-time ticket for mutual authentication between a server and client.
///
/// The caller of this operation can use the user name and file content of
/// the returned object as the userName and password arguments for login
/// operation. The local ticket that is returned becomes invalid either
/// after it is used or after a server-determined ticket expiration time
/// passes. This operation can be used by servers and clients to avoid
/// re-entering user credentials after authentication by the operating
/// system has already happened.
///
/// For example, service console utilities that connect to a host agent
/// should not require users to re-enter their passwords every time the
/// utilities run. Since the one-time password file is readable only by
/// the given user, the identity of the one-time password user is protected
/// by the operating system file permission.
///
/// Only local clients are allowed to call this operation. Remote clients
/// receive an InvalidRequest fault upon calling this operation.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### user_name
/// User requesting one-time password.
///
/// ## Returns:
///
/// LocalTicket object containing userName and path to file
/// containing one-time password for use in login operation.
///
/// ## Errors:
///
/// ***InvalidLogin***: if the userName is invalid.
///
/// ***NoPermission***: if the user and password are valid, but the user has no access
/// granted.
///
/// ***NotSupported***: if the server does not support this operation.
pub async fn acquire_local_ticket(&self, user_name: &str) -> Result<crate::types::structs::SessionManagerLocalTicket> {
let input = AcquireLocalTicketRequestType {user_name, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "AcquireLocalTicket", Some(&input)).await?;
let result: crate::types::structs::SessionManagerLocalTicket = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Clone the session specified by the clone ticket and associate it with
/// the current connection.
///
/// The current session will take on the identity
/// and authorization level of the UserSession associated with the
/// specified cloning ticket.
///
/// See also *SessionManager.AcquireCloneTicket*, *SessionManager.AcquireGenericServiceTicket*.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### clone_ticket
/// ticket string acquired via *SessionManager.AcquireCloneTicket*.
///
/// ## Returns:
///
/// The new/cloned UserSession object.
///
/// ## Errors:
///
/// ***InvalidLogin***: if the specified ticket value is not valid.
///
/// ***NotSupported***: if the server does not support this operation.
pub async fn clone_session(&self, clone_ticket: &str) -> Result<crate::types::structs::UserSession> {
let input = CloneSessionRequestType {clone_ticket, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "CloneSession", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Converts current session to impersonate the specified user.
///
/// The current session will take on the identity and authorization level of
/// the user. That user must have a currently-active session.
/// If the given userName is an extension key and this key does
/// not overlap with a user name of any currently-active session, it will
/// take on the identity and authorization level of that extension provided
/// the current session has the same authorization level of that extension.
///
/// ***Required privileges:*** Sessions.ImpersonateUser
///
/// ## Parameters:
///
/// ### user_name
/// The user or extension key to impersonate.
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Errors:
///
/// Failure
pub async fn impersonate_user(&self, user_name: &str, locale: Option<&str>) -> Result<crate::types::structs::UserSession> {
let input = ImpersonateUserRequestType {user_name, locale, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "ImpersonateUser", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Log on to the server.
///
/// This method fails if the user name and password are
/// incorrect, or if the user is valid but has no permissions granted.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### user_name
/// The *ID*
/// of the user who is logging on to the server.
///
/// ### password
/// The *HostAccountSpec.password*
/// of the user who is logging on to the server.
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Returns:
///
/// The UserSession object.
///
/// As of vSphere API 5.1 for VirtualCenter login use SSO style
/// *SessionManager.LoginByToken*
///
/// ## Errors:
///
/// ***InvalidLogin***: if the user and password combination is invalid.
///
/// ***NoPermission***: if the user is valid, but has no access granted.
///
/// ***InvalidLocale***: if the locale is invalid or unknown to the server.
pub async fn login(&self, user_name: &str, password: &str, locale: Option<&str>) -> Result<crate::types::structs::UserSession> {
let input = LoginRequestType {user_name, password, locale, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "Login", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Deprecated as of vSphere API 5.1 for VirtualCenter login use SSO style
/// *SessionManager.LoginByToken*.
///
/// Log on to the server using SSPI pass-through authentication.
///
/// This method provides support for passing credentials of the calling
/// process to the server without using a password, by leveraging the
/// Windows Security Support Provider Interface (SSPI) library.
///
/// If the function is not supported, this throws a NotSupported fault.
///
/// The client first calls AcquireCredentialsHandle(). If Kerberos is
/// used, this should include the desired credential to pass. The client then
/// calls InitializeSecurityContext(). The resulting partially-formed
/// context is passed in Base-64 encoded form to this method.
///
/// If the context has been successfully formed, the server proceeds with
/// login and behaves like *SessionManager.Login*. If further
/// negotiation is needed, the server throws an SSPIChallenge fault with
/// a challenge token, which the client should again pass to
/// InitializeSecurityContext(), followed by calling this method again.
///
/// For more information, see the MSDN documentation on SSPI.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### base_64_token
/// The partially formed context returned from
/// InitializeSecurityContext().
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Returns:
///
/// The UserSession object.
///
/// ## Errors:
///
/// ***SSPIChallenge***: if further negotiation is required.
///
/// ***InvalidLogin***: if the user context could not be passed successfully,
/// or the context is not valid on the server.
///
/// ***NoPermission***: if the user is valid, but has no access granted.
///
/// ***InvalidLocale***: if the locale is invalid or unknown to the server.
///
/// ***NotSupported***: if the service does not support SSPI authentication.
pub async fn login_by_sspi(&self, base_64_token: &str, locale: Option<&str>) -> Result<crate::types::structs::UserSession> {
let input = LoginBySspiRequestType {base_64_token, locale, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "LoginBySSPI", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Log on to the server through token representing principal identity.
///
/// The token is obtained from SSO (single sign-on) service. This method
/// fails if the token is not valid, or the principal has no permissions
/// granted. Two type of sso tokens are supported by this method: Bearer
/// and Holder-of-Key (HoK). If the token type obliges the method caller
/// to prove his rights to present this token (HoK), then a signature is
/// supplied as well. The token and the security signature if available
/// are provided in a transport specific way.
///
/// If the communication with the VirtualCenter is SOAP based read the
/// WS-Security specification (SAML Token profile) to understand how
/// to transport the SSO token and signature.
///
/// Usual login scenario:
/// 1. Acquire HoK token from the SSO service. Different authentication
/// mechanisms are available for acquiring token (user/password,
/// certificate, SSPI and so on). For more details consult the SSO
/// documentation. To find the location of your SSO service consult the
/// Virtual Infrastructure documentation.
/// 2. Once SSO token is acquired successfully *SessionManager.LoginByToken* could be
/// invoked.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Returns:
///
/// The UserSession object.
///
/// ## Errors:
///
/// ***InvalidLogin***: if there is no token provided or the token
/// could not be validated.
///
/// ***NoPermission***: if the principal is valid, but has no access granted.
///
/// ***InvalidLocale***: if the locale is invalid or unknown to the server.
pub async fn login_by_token(&self, locale: Option<&str>) -> Result<crate::types::structs::UserSession> {
let input = LoginByTokenRequestType {locale, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "LoginByToken", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Deprecated as of vSphere API 4.0, use SSO style of login instead
/// *SessionManager.LoginByToken*.
///
/// Creates a special privileged session that includes
/// the Sessions.ImpersonateUser privilege.
///
/// Requires exchange of
/// a message signed with the extension's registered public key
/// and base-64 encoded.
///
/// As of vSphere API 4.0, the NotFound fault is no longer thrown. Instead, InvalidLogin
/// is thrown if the specified extension is not registered.
///
/// As of vSphere API 5.0, this method always throws a NotSupported exception.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### extension_key
/// Key of extension that is logging in.
///
/// ### base_64_signed_credentials
/// base-64 encoding of the SHA-1
/// digest of the string "login" signed with the extension's
/// private RSA key using PKCS#1 padding.
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Errors:
///
/// Failure
pub async fn login_extension(&self, extension_key: &str, base_64_signed_credentials: &str, locale: Option<&str>) -> Result<crate::types::structs::UserSession> {
let input = LoginExtensionRequestType {extension_key, base_64_signed_credentials, locale, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "LoginExtension", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Deprecated as of vSphere API 6.0, use SSO style of login instead
/// *SessionManager.LoginByToken*.
///
/// Creates a special privileged session that includes
/// the Sessions.ImpersonateUser privilege.
///
/// Requires that the client connect
/// over SSL and provide an X.509 certificate for which they hold the private key.
/// The certificate must match the certificate used in an earlier call to
/// *ExtensionManager.SetExtensionCertificate*.
///
/// NOTE: Verification of the received certificate (such as expiry, revocation,
/// and trust chain) is not required for successful authentication using
/// this method. If certificate verification is desired, use the
/// *SessionManager.LoginExtensionBySubjectName* method instead.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### extension_key
/// Key of extension that is logging in.
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Errors:
///
/// ***InvalidLogin***: if the extension is not registered, or the
/// certificate does not match the expected value.
///
/// ***InvalidLocale***: if the supplied locale is not valid
///
/// ***NoClientCertificate***: if no certificate was used by the client to connect
pub async fn login_extension_by_certificate(&self, extension_key: &str, locale: Option<&str>) -> Result<crate::types::structs::UserSession> {
let input = LoginExtensionByCertificateRequestType {extension_key, locale, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "LoginExtensionByCertificate", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Deprecated as of vSphere API 6.0, use SSO style of login instead
/// *SessionManager.LoginByToken*.
///
/// Creates a special privileged session that includes
/// the Sessions.ImpersonateUser privilege.
///
/// Requires that the extension connected
/// using SSL, with a certificate that has a subject name that matches the subject
/// name registered for the extension.
///
/// As of vSphere API 4.0, the NotFound fault is no longer thrown. Instead, InvalidLogin
/// is thrown if the specified extension is not registered.
///
/// ***Required privileges:*** System.Anonymous
///
/// ## Parameters:
///
/// ### extension_key
/// Key of extension that is logging in.
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Errors:
///
/// ***InvalidLogin***: if the extension is not registered, or the subject name
/// doesn't match the subject name of the extension.
///
/// ***InvalidLocale***: if the supplied locale is not valid
///
/// ***NotFound***: if no extension is associated with the given key
///
/// ***NoClientCertificate***: if no certificate was used by the client to connect
///
/// ***NoSubjectName***: if the extension was registered without a subject name
///
/// ***InvalidClientCertificate***: if the client cerificate fails the verification at the server
pub async fn login_extension_by_subject_name(&self, extension_key: &str, locale: Option<&str>) -> Result<crate::types::structs::UserSession> {
let input = LoginExtensionBySubjectNameRequestType {extension_key, locale, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "LoginExtensionBySubjectName", Some(&input)).await?;
let result: crate::types::structs::UserSession = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Log out and terminate the current session.
///
/// ***Required privileges:*** System.View
pub async fn logout(&self) -> Result<()> {
self.client.invoke_void("", "SessionManager", &self.mo_id, "Logout", None).await
}
/// Validates that a currently-active session exists with the specified
/// sessionID and userName associated with it.
///
/// Returns true
/// if session exists.
///
/// ***Required privileges:*** Sessions.ValidateSession
///
/// ## Parameters:
///
/// ### session_id
/// Session ID to validate.
///
/// ### user_name
/// User name to validate.
pub async fn session_is_active(&self, session_id: &str, user_name: &str) -> Result<bool> {
let input = SessionIsActiveRequestType {session_id, user_name, };
let bytes = self.client.invoke("", "SessionManager", &self.mo_id, "SessionIsActive", Some(&input)).await?;
let result: bool = crate::core::client::unmarshal(self.client.transport(), &bytes)?;
Ok(result)
}
/// Sets the session locale.
///
/// ***Required privileges:*** System.View
///
/// ## Parameters:
///
/// ### locale
/// A two-character ISO-639 language ID (like "en")
/// optionally followed by an
/// underscore and a two-character ISO 3166 country ID (like "US").
///
/// Examples are "de", "fr\_CA", "zh", "zh\_CN", and "zh\_TW".
/// Note: The method uses the server default locale when
/// a locale is not provided. This default can be configured in the
/// server configuration file. If unspecified, it defaults to the
/// locale of the server environment or English ("en") if unsupported.
///
/// ## Errors:
///
/// ***InvalidLocale***: if the locale is invalid or unknown to the server.
pub async fn set_locale(&self, locale: &str) -> Result<()> {
let input = SetLocaleRequestType {locale, };
self.client.invoke_void("", "SessionManager", &self.mo_id, "SetLocale", Some(&input)).await
}
/// Log off and terminate the provided list of sessions.
///
/// This method is only transactional for each session ID. The set of sessions
/// are terminated sequentially, as specified in the list. If a failure
/// occurs, for example, because of an unknown sessionID, the method aborts with
/// an exception. When the method aborts, any sessions that have not yet been
/// terminated are left in their unterminated state.
///
/// ***Required privileges:*** Sessions.TerminateSession
///
/// ## Parameters:
///
/// ### session_id
/// A list of sessions to terminate.
///
/// ## Errors:
///
/// ***NotFound***: if a sessionId could not be found as a valid logged-on session.
///
/// ***InvalidArgument***: if a sessionId matches the current session. Use
/// the logout method to terminate the current session.
pub async fn terminate_session(&self, session_id: &[String]) -> Result<()> {
let input = TerminateSessionRequestType {session_id, };
self.client.invoke_void("", "SessionManager", &self.mo_id, "TerminateSession", Some(&input)).await
}
/// Updates the system global message.
///
/// If not blank, the message is immediately
/// displayed to currently logged-on users. When set, the message is shown by new
/// clients upon logging in.
///
/// ***Required privileges:*** Sessions.GlobalMessage
///
/// ## Parameters:
///
/// ### message
/// The message to send. Newline characters may be included.
pub async fn update_service_message(&self, message: &str) -> Result<()> {
let input = UpdateServiceMessageRequestType {message, };
self.client.invoke_void("", "SessionManager", &self.mo_id, "UpdateServiceMessage", Some(&input)).await
}
/// This property contains information about the client's current session.
///
/// If the client is not logged on, the value is null.
///
/// ***Required privileges:*** System.Anonymous
pub async fn current_session(&self) -> Result<Option<crate::types::structs::UserSession>> {
let pv_opt = self.client.fetch_property_raw("", "SessionManager", &self.mo_id, "currentSession").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
/// This is the default server locale.
///
/// ***Required privileges:*** System.Anonymous
pub async fn default_locale(&self) -> Result<String> {
let pv_opt = self.client.fetch_property_raw("", "SessionManager", &self.mo_id, "defaultLocale").await?;
let pv = pv_opt.ok_or_else(|| crate::core::client::VimError::ParseError("property defaultLocale was empty".to_string()))?;
let result: String = crate::core::client::extract_property(pv)?;
Ok(result)
}
/// The system global message from the server.
///
/// ***Required privileges:*** System.View
pub async fn message(&self) -> Result<Option<String>> {
let pv_opt = self.client.fetch_property_raw("", "SessionManager", &self.mo_id, "message").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
/// Provides the list of locales for which the server has localized messages.
///
/// ***Required privileges:*** System.Anonymous
pub async fn message_locale_list(&self) -> Result<Option<Vec<String>>> {
let pv_opt = self.client.fetch_property_raw("", "SessionManager", &self.mo_id, "messageLocaleList").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
/// The list of currently active sessions.
///
/// ***Required privileges:*** Sessions.TerminateSession
pub async fn session_list(&self) -> Result<Option<Vec<crate::types::structs::UserSession>>> {
let pv_opt = self.client.fetch_property_raw("", "SessionManager", &self.mo_id, "sessionList").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
/// Provides the list of locales that the server supports.
///
/// Listing a locale ensures that some standardized information such as dates appear
/// in the appropriate format. Other localized information, such as error messages,
/// are displayed, if available. If localized information is not available, the
/// message is returned using the system locale.
///
/// ***Required privileges:*** System.Anonymous
pub async fn supported_locale_list(&self) -> Result<Option<Vec<String>>> {
let pv_opt = self.client.fetch_property_raw("", "SessionManager", &self.mo_id, "supportedLocaleList").await?;
match pv_opt {
Some(pv) => Ok(Some(crate::core::client::extract_property(pv)?)),
None => Ok(None),
}
}
}
struct AcquireGenericServiceTicketRequestType<'a> {
spec: &'a dyn crate::types::traits::SessionManagerServiceRequestSpecTrait,
}
impl<'a> miniserde::Serialize for AcquireGenericServiceTicketRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(AcquireGenericServiceTicketRequestTypeSer { data: self, seq: 0 }))
}
}
struct AcquireGenericServiceTicketRequestTypeSer<'b, 'a> {
data: &'b AcquireGenericServiceTicketRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for AcquireGenericServiceTicketRequestTypeSer<'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"), &"AcquireGenericServiceTicketRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("spec"), &self.data.spec as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct AcquireLocalTicketRequestType<'a> {
user_name: &'a str,
}
impl<'a> miniserde::Serialize for AcquireLocalTicketRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(AcquireLocalTicketRequestTypeSer { data: self, seq: 0 }))
}
}
struct AcquireLocalTicketRequestTypeSer<'b, 'a> {
data: &'b AcquireLocalTicketRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for AcquireLocalTicketRequestTypeSer<'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"), &"AcquireLocalTicketRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("userName"), &self.data.user_name as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct CloneSessionRequestType<'a> {
clone_ticket: &'a str,
}
impl<'a> miniserde::Serialize for CloneSessionRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(CloneSessionRequestTypeSer { data: self, seq: 0 }))
}
}
struct CloneSessionRequestTypeSer<'b, 'a> {
data: &'b CloneSessionRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for CloneSessionRequestTypeSer<'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"), &"CloneSessionRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("cloneTicket"), &self.data.clone_ticket as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct ImpersonateUserRequestType<'a> {
user_name: &'a str,
locale: Option<&'a str>,
}
impl<'a> miniserde::Serialize for ImpersonateUserRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(ImpersonateUserRequestTypeSer { data: self, seq: 0 }))
}
}
struct ImpersonateUserRequestTypeSer<'b, 'a> {
data: &'b ImpersonateUserRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for ImpersonateUserRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"ImpersonateUserRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("userName"), &self.data.user_name as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.locale else { continue; };
return Some((std::borrow::Cow::Borrowed("locale"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct LoginRequestType<'a> {
user_name: &'a str,
password: &'a str,
locale: Option<&'a str>,
}
impl<'a> miniserde::Serialize for LoginRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(LoginRequestTypeSer { data: self, seq: 0 }))
}
}
struct LoginRequestTypeSer<'b, 'a> {
data: &'b LoginRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for LoginRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"LoginRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("userName"), &self.data.user_name as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("password"), &self.data.password as &dyn miniserde::Serialize)),
3 => {
let Some(ref val) = self.data.locale else { continue; };
return Some((std::borrow::Cow::Borrowed("locale"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct LoginBySspiRequestType<'a> {
base_64_token: &'a str,
locale: Option<&'a str>,
}
impl<'a> miniserde::Serialize for LoginBySspiRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(LoginBySspiRequestTypeSer { data: self, seq: 0 }))
}
}
struct LoginBySspiRequestTypeSer<'b, 'a> {
data: &'b LoginBySspiRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for LoginBySspiRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"LoginBySSPIRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("base64Token"), &self.data.base_64_token as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.locale else { continue; };
return Some((std::borrow::Cow::Borrowed("locale"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct LoginByTokenRequestType<'a> {
locale: Option<&'a str>,
}
impl<'a> miniserde::Serialize for LoginByTokenRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(LoginByTokenRequestTypeSer { data: self, seq: 0 }))
}
}
struct LoginByTokenRequestTypeSer<'b, 'a> {
data: &'b LoginByTokenRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for LoginByTokenRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"LoginByTokenRequestType")),
1 => {
let Some(ref val) = self.data.locale else { continue; };
return Some((std::borrow::Cow::Borrowed("locale"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct LoginExtensionRequestType<'a> {
extension_key: &'a str,
base_64_signed_credentials: &'a str,
locale: Option<&'a str>,
}
impl<'a> miniserde::Serialize for LoginExtensionRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(LoginExtensionRequestTypeSer { data: self, seq: 0 }))
}
}
struct LoginExtensionRequestTypeSer<'b, 'a> {
data: &'b LoginExtensionRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for LoginExtensionRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"LoginExtensionRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("base64SignedCredentials"), &self.data.base_64_signed_credentials as &dyn miniserde::Serialize)),
3 => {
let Some(ref val) = self.data.locale else { continue; };
return Some((std::borrow::Cow::Borrowed("locale"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct LoginExtensionByCertificateRequestType<'a> {
extension_key: &'a str,
locale: Option<&'a str>,
}
impl<'a> miniserde::Serialize for LoginExtensionByCertificateRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(LoginExtensionByCertificateRequestTypeSer { data: self, seq: 0 }))
}
}
struct LoginExtensionByCertificateRequestTypeSer<'b, 'a> {
data: &'b LoginExtensionByCertificateRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for LoginExtensionByCertificateRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"LoginExtensionByCertificateRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.locale else { continue; };
return Some((std::borrow::Cow::Borrowed("locale"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct LoginExtensionBySubjectNameRequestType<'a> {
extension_key: &'a str,
locale: Option<&'a str>,
}
impl<'a> miniserde::Serialize for LoginExtensionBySubjectNameRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(LoginExtensionBySubjectNameRequestTypeSer { data: self, seq: 0 }))
}
}
struct LoginExtensionBySubjectNameRequestTypeSer<'b, 'a> {
data: &'b LoginExtensionBySubjectNameRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for LoginExtensionBySubjectNameRequestTypeSer<'b, 'a> {
fn next(&mut self) -> Option<(std::borrow::Cow<'_, str>, &dyn miniserde::Serialize)> {
loop {
let seq = self.seq;
self.seq += 1;
match seq {
0 => return Some((std::borrow::Cow::Borrowed("_typeName"), &"LoginExtensionBySubjectNameRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("extensionKey"), &self.data.extension_key as &dyn miniserde::Serialize)),
2 => {
let Some(ref val) = self.data.locale else { continue; };
return Some((std::borrow::Cow::Borrowed("locale"), val as &dyn miniserde::Serialize));
}
_ => return None,
}
}
}
}
struct SessionIsActiveRequestType<'a> {
session_id: &'a str,
user_name: &'a str,
}
impl<'a> miniserde::Serialize for SessionIsActiveRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(SessionIsActiveRequestTypeSer { data: self, seq: 0 }))
}
}
struct SessionIsActiveRequestTypeSer<'b, 'a> {
data: &'b SessionIsActiveRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for SessionIsActiveRequestTypeSer<'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"), &"SessionIsActiveRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("sessionID"), &self.data.session_id as &dyn miniserde::Serialize)),
2 => return Some((std::borrow::Cow::Borrowed("userName"), &self.data.user_name as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct SetLocaleRequestType<'a> {
locale: &'a str,
}
impl<'a> miniserde::Serialize for SetLocaleRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(SetLocaleRequestTypeSer { data: self, seq: 0 }))
}
}
struct SetLocaleRequestTypeSer<'b, 'a> {
data: &'b SetLocaleRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for SetLocaleRequestTypeSer<'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"), &"SetLocaleRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("locale"), &self.data.locale as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct TerminateSessionRequestType<'a> {
session_id: &'a [String],
}
impl<'a> miniserde::Serialize for TerminateSessionRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(TerminateSessionRequestTypeSer { data: self, seq: 0 }))
}
}
struct TerminateSessionRequestTypeSer<'b, 'a> {
data: &'b TerminateSessionRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for TerminateSessionRequestTypeSer<'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"), &"TerminateSessionRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("sessionId"), &self.data.session_id as &dyn miniserde::Serialize)),
_ => return None,
}
}
}
struct UpdateServiceMessageRequestType<'a> {
message: &'a str,
}
impl<'a> miniserde::Serialize for UpdateServiceMessageRequestType<'a> {
fn begin(&self) -> miniserde::ser::Fragment<'_> {
miniserde::ser::Fragment::Map(Box::new(UpdateServiceMessageRequestTypeSer { data: self, seq: 0 }))
}
}
struct UpdateServiceMessageRequestTypeSer<'b, 'a> {
data: &'b UpdateServiceMessageRequestType<'a>,
seq: usize,
}
impl<'b, 'a> miniserde::ser::Map for UpdateServiceMessageRequestTypeSer<'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"), &"UpdateServiceMessageRequestType")),
1 => return Some((std::borrow::Cow::Borrowed("message"), &self.data.message as &dyn miniserde::Serialize)),
_ => return None,
}
}
}