1
+ /*
2
+ * Copyright (c) Citrix Systems, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions
7
+ * are met:
8
+ *
9
+ * 1) Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ *
12
+ * 2) Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following
14
+ * disclaimer in the documentation and/or other materials
15
+ * provided with the distribution.
16
+ *
17
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
29
+ */
30
+
31
+
32
+ package com .xensource .xenapi ;
33
+
34
+ import com .xensource .xenapi .Types .BadServerResponse ;
35
+ import com .xensource .xenapi .Types .VersionException ;
36
+ import com .xensource .xenapi .Types .XenAPIException ;
37
+
38
+ import java .io .PrintWriter ;
39
+ import java .io .StringWriter ;
40
+ import java .util .Date ;
41
+ import java .util .HashMap ;
42
+ import java .util .LinkedHashSet ;
43
+ import java .util .Map ;
44
+ import java .util .Set ;
45
+
46
+ import org .apache .xmlrpc .XmlRpcException ;
47
+
48
+ /**
49
+ * Management of remote authentication services
50
+ *
51
+ * @author Citrix Systems, Inc.
52
+ */
53
+ public class Auth extends XenAPIObject {
54
+
55
+
56
+ public String toWireString () {
57
+ return null ;
58
+ }
59
+
60
+ /**
61
+ * This call queries the external directory service to obtain the subject_identifier as a string from the human-readable subject_name
62
+ *
63
+ * @param subjectName The human-readable subject_name, such as a username or a groupname
64
+ * @return the subject_identifier obtained from the external directory service
65
+ */
66
+ public static String getSubjectIdentifier (Connection c , String subjectName ) throws
67
+ BadServerResponse ,
68
+ XenAPIException ,
69
+ XmlRpcException {
70
+ String method_call = "auth.get_subject_identifier" ;
71
+ String session = c .getSessionReference ();
72
+ Object [] method_params = {Marshalling .toXMLRPC (session ), Marshalling .toXMLRPC (subjectName )};
73
+ Map response = c .dispatch (method_call , method_params );
74
+ Object result = response .get ("Value" );
75
+ return Types .toString (result );
76
+ }
77
+
78
+ /**
79
+ * This call queries the external directory service to obtain the user information (e.g. username, organization etc) from the specified subject_identifier
80
+ *
81
+ * @param subjectIdentifier A string containing the subject_identifier, unique in the external directory service
82
+ * @return key-value pairs containing at least a key called subject_name
83
+ */
84
+ public static Map <String , String > getSubjectInformationFromIdentifier (Connection c , String subjectIdentifier ) throws
85
+ BadServerResponse ,
86
+ XenAPIException ,
87
+ XmlRpcException {
88
+ String method_call = "auth.get_subject_information_from_identifier" ;
89
+ String session = c .getSessionReference ();
90
+ Object [] method_params = {Marshalling .toXMLRPC (session ), Marshalling .toXMLRPC (subjectIdentifier )};
91
+ Map response = c .dispatch (method_call , method_params );
92
+ Object result = response .get ("Value" );
93
+ return Types .toMapOfStringString (result );
94
+ }
95
+
96
+ /**
97
+ * This calls queries the external directory service to obtain the transitively-closed set of groups that the the subject_identifier is member of.
98
+ *
99
+ * @param subjectIdentifier A string containing the subject_identifier, unique in the external directory service
100
+ * @return set of subject_identifiers that provides the group membership of subject_identifier passed as argument, it contains, recursively, all groups a subject_identifier is member of.
101
+ */
102
+ public static Set <String > getGroupMembership (Connection c , String subjectIdentifier ) throws
103
+ BadServerResponse ,
104
+ XenAPIException ,
105
+ XmlRpcException {
106
+ String method_call = "auth.get_group_membership" ;
107
+ String session = c .getSessionReference ();
108
+ Object [] method_params = {Marshalling .toXMLRPC (session ), Marshalling .toXMLRPC (subjectIdentifier )};
109
+ Map response = c .dispatch (method_call , method_params );
110
+ Object result = response .get ("Value" );
111
+ return Types .toSetOfString (result );
112
+ }
113
+
114
+ }
0 commit comments