@@ -64,6 +64,24 @@ public String getCallbackUrl() {
64
64
return spConfig .getCallbackUrl ();
65
65
}
66
66
67
+ static List <Object > ensureNestedList (Map <String , Object > outerMap , String id ) {
68
+ List <Object > list = (List <Object >) outerMap .get (id );
69
+ if (list == null ) {
70
+ list = new ArrayList <Object >();
71
+ outerMap .put (id , list );
72
+ }
73
+ return list ;
74
+ }
75
+
76
+ static Map <String , Object > ensureNestedMap (Map <String , Object > outerMap , String id ) {
77
+ Map <String , Object > map = (Map <String , Object >) outerMap .get (id );
78
+ if (map == null ) {
79
+ map = new HashMap <String , Object >();
80
+ outerMap .put (id , map );
81
+ }
82
+ return map ;
83
+ }
84
+
67
85
/**
68
86
* A specification class for creating a new SAML Auth provider.
69
87
*
@@ -90,7 +108,7 @@ public CreateRequest() { }
90
108
public CreateRequest setIdpEntityId (String idpEntityId ) {
91
109
checkArgument (!Strings .isNullOrEmpty (idpEntityId ),
92
110
"IDP entity ID must not be null or empty." );
93
- getNestedMap (properties , "idpConfig" ).put ("idpEntityId" , idpEntityId );
111
+ ensureNestedMap (properties , "idpConfig" ).put ("idpEntityId" , idpEntityId );
94
112
return this ;
95
113
}
96
114
@@ -104,19 +122,7 @@ public CreateRequest setIdpEntityId(String idpEntityId) {
104
122
public CreateRequest setSsoUrl (String ssoUrl ) {
105
123
checkArgument (!Strings .isNullOrEmpty (ssoUrl ), "SSO URL must not be null or empty." );
106
124
assertValidUrl (ssoUrl );
107
- getNestedMap (properties , "idpConfig" ).put ("ssoUrl" , ssoUrl );
108
- return this ;
109
- }
110
-
111
- /**
112
- * Sets the RP entity ID for the new provider.
113
- *
114
- * @param rpEntityId A non-null, non-empty RP entity ID string.
115
- * @throws IllegalArgumentException If the RP entity ID is null or empty.
116
- */
117
- public CreateRequest setRpEntityId (String rpEntityId ) {
118
- checkArgument (!Strings .isNullOrEmpty (rpEntityId ), "RP entity ID must not be null or empty." );
119
- getNestedMap (properties , "spConfig" ).put ("spEntityId" , rpEntityId );
125
+ ensureNestedMap (properties , "idpConfig" ).put ("ssoUrl" , ssoUrl );
120
126
return this ;
121
127
}
122
128
@@ -129,14 +135,26 @@ public CreateRequest setRpEntityId(String rpEntityId) {
129
135
public CreateRequest addX509Certificate (String x509Certificate ) {
130
136
checkArgument (!Strings .isNullOrEmpty (x509Certificate ),
131
137
"The x509 certificate must not be null or empty." );
132
- Map <String , Object > idpConfigProperties = getNestedMap (properties , "idpConfig" );
133
- List <Object > x509Certificates = getNestedList (idpConfigProperties , "idpCertificates" );
138
+ Map <String , Object > idpConfigProperties = ensureNestedMap (properties , "idpConfig" );
139
+ List <Object > x509Certificates = ensureNestedList (idpConfigProperties , "idpCertificates" );
134
140
x509Certificates .add (ImmutableMap .<String , Object >of ("x509Certificate" , x509Certificate ));
135
141
return this ;
136
142
}
137
143
138
144
// TODO(micahstairs): Add 'addAllX509Certificates' method.
139
145
146
+ /**
147
+ * Sets the RP entity ID for the new provider.
148
+ *
149
+ * @param rpEntityId A non-null, non-empty RP entity ID string.
150
+ * @throws IllegalArgumentException If the RP entity ID is null or empty.
151
+ */
152
+ public CreateRequest setRpEntityId (String rpEntityId ) {
153
+ checkArgument (!Strings .isNullOrEmpty (rpEntityId ), "RP entity ID must not be null or empty." );
154
+ ensureNestedMap (properties , "spConfig" ).put ("spEntityId" , rpEntityId );
155
+ return this ;
156
+ }
157
+
140
158
/**
141
159
* Sets the callback URL for the new provider.
142
160
*
@@ -147,7 +165,7 @@ public CreateRequest addX509Certificate(String x509Certificate) {
147
165
public CreateRequest setCallbackUrl (String callbackUrl ) {
148
166
checkArgument (!Strings .isNullOrEmpty (callbackUrl ), "Callback URL must not be null or empty." );
149
167
assertValidUrl (callbackUrl );
150
- getNestedMap (properties , "spConfig" ).put ("callbackUri" , callbackUrl );
168
+ ensureNestedMap (properties , "spConfig" ).put ("callbackUri" , callbackUrl );
151
169
return this ;
152
170
}
153
171
@@ -162,7 +180,7 @@ void assertValidProviderIdFormat(String providerId) {
162
180
}
163
181
}
164
182
165
- public static class IdpCertificate {
183
+ static class IdpCertificate {
166
184
@ Key ("x509Certificate" )
167
185
private String x509Certificate ;
168
186
@@ -171,7 +189,7 @@ public String getX509Certificate() {
171
189
}
172
190
}
173
191
174
- public static class IdpConfig {
192
+ static class IdpConfig {
175
193
@ Key ("idpEntityId" )
176
194
private String idpEntityId ;
177
195
@@ -194,7 +212,7 @@ public List<IdpCertificate> getIdpCertificates() {
194
212
}
195
213
}
196
214
197
- public static class SpConfig {
215
+ static class SpConfig {
198
216
@ Key ("spEntityId" )
199
217
private String rpEntityId ;
200
218
0 commit comments