Skip to content

Commit 2cd553f

Browse files
authored
Add operation to list SAML provider configs. (#426)
Adds a list operation for SAML provider configs. I also set 'suppressLoadErrors' to true to avoid class information error. See https://stackoverflow.com/questions/27938039/unable-to-get-class-information-for-checkstyle for more context.
1 parent c3a08b4 commit 2cd553f

11 files changed

+421
-28
lines changed

checkstyle.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
<module name="FileTabCharacter">
4343
<property name="eachLine" value="true"/>
4444
</module>
45-
45+
4646
<module name="SuppressionCommentFilter">
4747
<property name="offCommentFormat" value="CSOFF\: ([\w\|]+)"/>
4848
<property name="onCommentFormat" value="CSON\: ([\w\|]+)"/>
4949
<property name="checkFormat" value="$1"/>
5050
</module>
5151

52-
<module name="TreeWalker">
53-
<module name="FileContentsHolder"/>
52+
<module name="TreeWalker">
53+
<module name="FileContentsHolder"/>
5454
<module name="OuterTypeFilename"/>
5555
<module name="IllegalTokenText">
5656
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
@@ -229,6 +229,7 @@
229229
<property name="allowedAnnotations" value="Override, Test"/>
230230
<property name="allowThrowsTagsForSubclasses" value="true"/>
231231
<property name="allowMissingJavadoc" value="true"/>
232+
<property name="suppressLoadErrors" value="true"/>
232233
</module>
233234
<module name="MethodName">
234235
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>

src/main/java/com/google/firebase/auth/AbstractFirebaseAuth.java

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.firebase.auth.FirebaseUserManager.UserImportRequest;
3232
import com.google.firebase.auth.ListProviderConfigsPage;
3333
import com.google.firebase.auth.ListProviderConfigsPage.DefaultOidcProviderConfigSource;
34+
import com.google.firebase.auth.ListProviderConfigsPage.DefaultSamlProviderConfigSource;
3435
import com.google.firebase.auth.ListUsersPage;
3536
import com.google.firebase.auth.ListUsersPage.DefaultUserSource;
3637
import com.google.firebase.auth.UserRecord;
@@ -1107,8 +1108,8 @@ public ListProviderConfigsPage<OidcProviderConfig> listOidcProviderConfigs(
11071108
}
11081109

11091110
/**
1110-
* Similar to {@link #listlistOidcProviderConfigs(String)} but performs the operation
1111-
* asynchronously. Page size will be limited to 100 provider configs.
1111+
* Similar to {@link #listOidcProviderConfigs(String)} but performs the operation asynchronously.
1112+
* Page size will be limited to 100 provider configs.
11121113
*
11131114
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
11141115
* configs.
@@ -1249,7 +1250,7 @@ protected SamlProviderConfig execute() throws FirebaseAuthException {
12491250

12501251
/**
12511252
* Updates an existing SAML Auth provider config with the attributes contained in the specified
1252-
* {@link OidcProviderConfig.UpdateRequest}.
1253+
* {@link SamlProviderConfig.UpdateRequest}.
12531254
*
12541255
* @param request A non-null {@link SamlProviderConfig.UpdateRequest} instance.
12551256
* @return A {@link SamlProviderConfig} instance corresponding to the updated provider config.
@@ -1296,7 +1297,7 @@ protected SamlProviderConfig execute() throws FirebaseAuthException {
12961297
* Gets the SAML provider Auth config corresponding to the specified provider ID.
12971298
*
12981299
* @param providerId A provider ID string.
1299-
* @return An {@link OidcProviderConfig} instance.
1300+
* @return An {@link SamlProviderConfig} instance.
13001301
* @throws IllegalArgumentException If the provider ID string is null or empty, or is not prefixed
13011302
* with 'saml'.
13021303
* @throws FirebaseAuthException If an error occurs while retrieving the provider config.
@@ -1335,6 +1336,94 @@ protected SamlProviderConfig execute() throws FirebaseAuthException {
13351336
};
13361337
}
13371338

1339+
/**
1340+
* Gets a page of SAML Auth provider configs starting from the specified {@code pageToken}. Page
1341+
* size will be limited to 100 provider configs.
1342+
*
1343+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1344+
* configs.
1345+
* @return A {@link ListProviderConfigsPage} instance.
1346+
* @throws IllegalArgumentException If the specified page token is empty.
1347+
* @throws FirebaseAuthException If an error occurs while retrieving provider config data.
1348+
*/
1349+
public ListProviderConfigsPage<SamlProviderConfig> listSamlProviderConfigs(
1350+
@Nullable String pageToken) throws FirebaseAuthException {
1351+
return listSamlProviderConfigs(
1352+
pageToken,
1353+
FirebaseUserManager.MAX_LIST_PROVIDER_CONFIGS_RESULTS);
1354+
}
1355+
1356+
/**
1357+
* Gets a page of SAML Auth provider configs starting from the specified {@code pageToken}.
1358+
*
1359+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1360+
* configs.
1361+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1362+
* not exceed 100.
1363+
* @return A {@link ListProviderConfigsPage} instance.
1364+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1365+
* invalid.
1366+
* @throws FirebaseAuthException If an error occurs while retrieving provider config data.
1367+
*/
1368+
public ListProviderConfigsPage<SamlProviderConfig> listSamlProviderConfigs(
1369+
@Nullable String pageToken, int maxResults) throws FirebaseAuthException {
1370+
return listSamlProviderConfigsOp(pageToken, maxResults).call();
1371+
}
1372+
1373+
/**
1374+
* Similar to {@link #listSamlProviderConfigs(String)} but performs the operation asynchronously.
1375+
* Page size will be limited to 100 provider configs.
1376+
*
1377+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1378+
* configs.
1379+
* @return An {@code ApiFuture} which will complete successfully with a
1380+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1381+
* config data, the future throws an exception.
1382+
* @throws IllegalArgumentException If the specified page token is empty.
1383+
*/
1384+
public ApiFuture<ListProviderConfigsPage<SamlProviderConfig>> listSamlProviderConfigsAsync(
1385+
@Nullable String pageToken) {
1386+
int maxResults = FirebaseUserManager.MAX_LIST_PROVIDER_CONFIGS_RESULTS;
1387+
return listSamlProviderConfigsAsync(pageToken, maxResults);
1388+
}
1389+
1390+
/**
1391+
* Similar to {@link #listSamlProviderConfigs(String, int)} but performs the operation
1392+
* asynchronously.
1393+
*
1394+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1395+
* configs.
1396+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1397+
* not exceed 100.
1398+
* @return An {@code ApiFuture} which will complete successfully with a
1399+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1400+
* config data, the future throws an exception.
1401+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1402+
* invalid.
1403+
*/
1404+
public ApiFuture<ListProviderConfigsPage<SamlProviderConfig>> listSamlProviderConfigsAsync(
1405+
@Nullable String pageToken,
1406+
int maxResults) {
1407+
return listSamlProviderConfigsOp(pageToken, maxResults).callAsync(firebaseApp);
1408+
}
1409+
1410+
private CallableOperation<ListProviderConfigsPage<SamlProviderConfig>, FirebaseAuthException>
1411+
listSamlProviderConfigsOp(@Nullable final String pageToken, final int maxResults) {
1412+
checkNotDestroyed();
1413+
final FirebaseUserManager userManager = getUserManager();
1414+
final DefaultSamlProviderConfigSource source = new DefaultSamlProviderConfigSource(userManager);
1415+
final ListProviderConfigsPage.Factory<SamlProviderConfig> factory =
1416+
new ListProviderConfigsPage.Factory<SamlProviderConfig>(source, maxResults, pageToken);
1417+
return
1418+
new CallableOperation<ListProviderConfigsPage<SamlProviderConfig>, FirebaseAuthException>() {
1419+
@Override
1420+
protected ListProviderConfigsPage<SamlProviderConfig> execute()
1421+
throws FirebaseAuthException {
1422+
return factory.create();
1423+
}
1424+
};
1425+
}
1426+
13381427
/**
13391428
* Deletes the SAML Auth provider config identified by the specified provider ID.
13401429
*

src/main/java/com/google/firebase/auth/FirebaseUserManager.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.google.firebase.auth.internal.GetAccountInfoResponse;
4545
import com.google.firebase.auth.internal.HttpErrorResponse;
4646
import com.google.firebase.auth.internal.ListOidcProviderConfigsResponse;
47+
import com.google.firebase.auth.internal.ListSamlProviderConfigsResponse;
4748
import com.google.firebase.auth.internal.ListTenantsResponse;
4849
import com.google.firebase.auth.internal.UploadAccountResponse;
4950
import com.google.firebase.internal.ApiClientUtils;
@@ -366,7 +367,7 @@ ListOidcProviderConfigsResponse listOidcProviderConfigs(int maxResults, String p
366367
ImmutableMap.<String, Object>builder().put("pageSize", maxResults);
367368
if (pageToken != null) {
368369
checkArgument(!pageToken.equals(
369-
ListTenantsPage.END_OF_LIST), "Invalid end of list page token.");
370+
ListProviderConfigsPage.END_OF_LIST), "Invalid end of list page token.");
370371
builder.put("nextPageToken", pageToken);
371372
}
372373

@@ -380,6 +381,26 @@ ListOidcProviderConfigsResponse listOidcProviderConfigs(int maxResults, String p
380381
return response;
381382
}
382383

384+
ListSamlProviderConfigsResponse listSamlProviderConfigs(int maxResults, String pageToken)
385+
throws FirebaseAuthException {
386+
ImmutableMap.Builder<String, Object> builder =
387+
ImmutableMap.<String, Object>builder().put("pageSize", maxResults);
388+
if (pageToken != null) {
389+
checkArgument(!pageToken.equals(
390+
ListProviderConfigsPage.END_OF_LIST), "Invalid end of list page token.");
391+
builder.put("nextPageToken", pageToken);
392+
}
393+
394+
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + "/inboundSamlConfigs");
395+
url.putAll(builder.build());
396+
ListSamlProviderConfigsResponse response =
397+
sendRequest("GET", url, null, ListSamlProviderConfigsResponse.class);
398+
if (response == null) {
399+
throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to retrieve provider configs.");
400+
}
401+
return response;
402+
}
403+
383404
void deleteOidcProviderConfig(String providerId) throws FirebaseAuthException {
384405
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + getOidcUrlSuffix(providerId));
385406
sendRequest("DELETE", url, null, GenericJson.class);

src/main/java/com/google/firebase/auth/ListProviderConfigsPage.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.firebase.auth.internal.DownloadAccountResponse;
2626
import com.google.firebase.auth.internal.ListOidcProviderConfigsResponse;
2727
import com.google.firebase.auth.internal.ListProviderConfigsResponse;
28+
import com.google.firebase.auth.internal.ListSamlProviderConfigsResponse;
2829
import com.google.firebase.internal.NonNull;
2930
import com.google.firebase.internal.Nullable;
3031
import java.util.Iterator;
@@ -205,7 +206,7 @@ static class DefaultOidcProviderConfigSource implements ProviderConfigSource<Oid
205206
private final FirebaseUserManager userManager;
206207

207208
DefaultOidcProviderConfigSource(FirebaseUserManager userManager) {
208-
this.userManager = checkNotNull(userManager, "user manager must not be null");
209+
this.userManager = checkNotNull(userManager, "User manager must not be null.");
209210
}
210211

211212
@Override
@@ -215,7 +216,20 @@ public ListOidcProviderConfigsResponse fetch(int maxResults, String pageToken)
215216
}
216217
}
217218

218-
// TODO(micahstairs): Add DefaultSamlProviderConfigSource class.
219+
static class DefaultSamlProviderConfigSource implements ProviderConfigSource<SamlProviderConfig> {
220+
221+
private final FirebaseUserManager userManager;
222+
223+
DefaultSamlProviderConfigSource(FirebaseUserManager userManager) {
224+
this.userManager = checkNotNull(userManager, "User manager must not be null.");
225+
}
226+
227+
@Override
228+
public ListSamlProviderConfigsResponse fetch(int maxResults, String pageToken)
229+
throws FirebaseAuthException {
230+
return userManager.listSamlProviderConfigs(maxResults, pageToken);
231+
}
232+
}
219233

220234
/**
221235
* A simple factory class for {@link ProviderConfigsPage} instances.

src/main/java/com/google/firebase/auth/OidcProviderConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public static final class UpdateRequest extends AbstractUpdateRequest<UpdateRequ
138138
* {@link AbstractFirebaseAuth#updateOidcProviderConfig(CreateRequest)} to update the provider
139139
* information persistently.
140140
*
141-
* @param tenantId A non-null, non-empty provider ID string.
141+
* @param providerId A non-null, non-empty provider ID string.
142142
* @throws IllegalArgumentException If the provider ID is null or empty, or is not prefixed with
143143
* "oidc.".
144144
*/

src/main/java/com/google/firebase/auth/internal/ListOidcProviderConfigsResponse.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
package com.google.firebase.auth.internal;
1818

1919
import com.google.api.client.util.Key;
20-
import com.google.common.annotations.VisibleForTesting;
20+
import com.google.common.base.Strings;
2121
import com.google.common.collect.ImmutableList;
2222
import com.google.firebase.auth.OidcProviderConfig;
23-
import com.google.firebase.auth.Tenant;
2423
import java.util.List;
2524

2625
/**
@@ -36,16 +35,6 @@ public final class ListOidcProviderConfigsResponse
3635
@Key("nextPageToken")
3736
private String pageToken;
3837

39-
@VisibleForTesting
40-
public ListOidcProviderConfigsResponse(
41-
List<OidcProviderConfig> providerConfigs,
42-
String pageToken) {
43-
this.providerConfigs = providerConfigs;
44-
this.pageToken = pageToken;
45-
}
46-
47-
public ListOidcProviderConfigsResponse() { }
48-
4938
@Override
5039
public List<OidcProviderConfig> getProviderConfigs() {
5140
return providerConfigs == null ? ImmutableList.<OidcProviderConfig>of() : providerConfigs;
@@ -58,6 +47,6 @@ public boolean hasProviderConfigs() {
5847

5948
@Override
6049
public String getPageToken() {
61-
return pageToken == null ? "" : pageToken;
50+
return Strings.nullToEmpty(pageToken);
6251
}
6352
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.auth.internal;
18+
19+
import com.google.api.client.util.Key;
20+
import com.google.common.base.Strings;
21+
import com.google.common.collect.ImmutableList;
22+
import com.google.firebase.auth.SamlProviderConfig;
23+
import java.util.List;
24+
25+
/**
26+
* JSON data binding for ListInboundSamlConfigsResponse messages sent by Google identity toolkit
27+
* service.
28+
*/
29+
public final class ListSamlProviderConfigsResponse
30+
implements ListProviderConfigsResponse<SamlProviderConfig> {
31+
32+
@Key("inboundSamlConfigs")
33+
private List<SamlProviderConfig> providerConfigs;
34+
35+
@Key("nextPageToken")
36+
private String pageToken;
37+
38+
@Override
39+
public List<SamlProviderConfig> getProviderConfigs() {
40+
return providerConfigs == null ? ImmutableList.<SamlProviderConfig>of() : providerConfigs;
41+
}
42+
43+
@Override
44+
public boolean hasProviderConfigs() {
45+
return providerConfigs != null && !providerConfigs.isEmpty();
46+
}
47+
48+
@Override
49+
public String getPageToken() {
50+
return Strings.nullToEmpty(pageToken);
51+
}
52+
}

0 commit comments

Comments
 (0)