Skip to content

Commit 638240f

Browse files
committed
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 de24a2b commit 638240f

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;
@@ -1244,8 +1245,8 @@ public ListProviderConfigsPage<OidcProviderConfig> listOidcProviderConfigs(
12441245
}
12451246

12461247
/**
1247-
* Similar to {@link #listlistOidcProviderConfigs(String)} but performs the operation
1248-
* asynchronously. Page size will be limited to 100 provider configs.
1248+
* Similar to {@link #listOidcProviderConfigs(String)} but performs the operation asynchronously.
1249+
* Page size will be limited to 100 provider configs.
12491250
*
12501251
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
12511252
* configs.
@@ -1386,7 +1387,7 @@ protected SamlProviderConfig execute() throws FirebaseAuthException {
13861387

13871388
/**
13881389
* Updates an existing SAML Auth provider config with the attributes contained in the specified
1389-
* {@link OidcProviderConfig.UpdateRequest}.
1390+
* {@link SamlProviderConfig.UpdateRequest}.
13901391
*
13911392
* @param request A non-null {@link SamlProviderConfig.UpdateRequest} instance.
13921393
* @return A {@link SamlProviderConfig} instance corresponding to the updated provider config.
@@ -1433,7 +1434,7 @@ protected SamlProviderConfig execute() throws FirebaseAuthException {
14331434
* Gets the SAML provider Auth config corresponding to the specified provider ID.
14341435
*
14351436
* @param providerId A provider ID string.
1436-
* @return An {@link OidcProviderConfig} instance.
1437+
* @return An {@link SamlProviderConfig} instance.
14371438
* @throws IllegalArgumentException If the provider ID string is null or empty, or is not prefixed
14381439
* with 'saml'.
14391440
* @throws FirebaseAuthException If an error occurs while retrieving the provider config.
@@ -1472,6 +1473,94 @@ protected SamlProviderConfig execute() throws FirebaseAuthException {
14721473
};
14731474
}
14741475

1476+
/**
1477+
* Gets a page of SAML Auth provider configs starting from the specified {@code pageToken}. Page
1478+
* size will be limited to 100 provider configs.
1479+
*
1480+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1481+
* configs.
1482+
* @return A {@link ListProviderConfigsPage} instance.
1483+
* @throws IllegalArgumentException If the specified page token is empty.
1484+
* @throws FirebaseAuthException If an error occurs while retrieving provider config data.
1485+
*/
1486+
public ListProviderConfigsPage<SamlProviderConfig> listSamlProviderConfigs(
1487+
@Nullable String pageToken) throws FirebaseAuthException {
1488+
return listSamlProviderConfigs(
1489+
pageToken,
1490+
FirebaseUserManager.MAX_LIST_PROVIDER_CONFIGS_RESULTS);
1491+
}
1492+
1493+
/**
1494+
* Gets a page of SAML Auth provider configs starting from the specified {@code pageToken}.
1495+
*
1496+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1497+
* configs.
1498+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1499+
* not exceed 100.
1500+
* @return A {@link ListProviderConfigsPage} instance.
1501+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1502+
* invalid.
1503+
* @throws FirebaseAuthException If an error occurs while retrieving provider config data.
1504+
*/
1505+
public ListProviderConfigsPage<SamlProviderConfig> listSamlProviderConfigs(
1506+
@Nullable String pageToken, int maxResults) throws FirebaseAuthException {
1507+
return listSamlProviderConfigsOp(pageToken, maxResults).call();
1508+
}
1509+
1510+
/**
1511+
* Similar to {@link #listSamlProviderConfigs(String)} but performs the operation asynchronously.
1512+
* Page size will be limited to 100 provider configs.
1513+
*
1514+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1515+
* configs.
1516+
* @return An {@code ApiFuture} which will complete successfully with a
1517+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1518+
* config data, the future throws an exception.
1519+
* @throws IllegalArgumentException If the specified page token is empty.
1520+
*/
1521+
public ApiFuture<ListProviderConfigsPage<SamlProviderConfig>> listSamlProviderConfigsAsync(
1522+
@Nullable String pageToken) {
1523+
int maxResults = FirebaseUserManager.MAX_LIST_PROVIDER_CONFIGS_RESULTS;
1524+
return listSamlProviderConfigsAsync(pageToken, maxResults);
1525+
}
1526+
1527+
/**
1528+
* Similar to {@link #listSamlProviderConfigs(String, int)} but performs the operation
1529+
* asynchronously.
1530+
*
1531+
* @param pageToken A non-empty page token string, or null to retrieve the first page of provider
1532+
* configs.
1533+
* @param maxResults Maximum number of provider configs to include in the returned page. This may
1534+
* not exceed 100.
1535+
* @return An {@code ApiFuture} which will complete successfully with a
1536+
* {@link ListProviderConfigsPage} instance. If an error occurs while retrieving provider
1537+
* config data, the future throws an exception.
1538+
* @throws IllegalArgumentException If the specified page token is empty, or max results value is
1539+
* invalid.
1540+
*/
1541+
public ApiFuture<ListProviderConfigsPage<SamlProviderConfig>> listSamlProviderConfigsAsync(
1542+
@Nullable String pageToken,
1543+
int maxResults) {
1544+
return listSamlProviderConfigsOp(pageToken, maxResults).callAsync(firebaseApp);
1545+
}
1546+
1547+
private CallableOperation<ListProviderConfigsPage<SamlProviderConfig>, FirebaseAuthException>
1548+
listSamlProviderConfigsOp(@Nullable final String pageToken, final int maxResults) {
1549+
checkNotDestroyed();
1550+
final FirebaseUserManager userManager = getUserManager();
1551+
final DefaultSamlProviderConfigSource source = new DefaultSamlProviderConfigSource(userManager);
1552+
final ListProviderConfigsPage.Factory<SamlProviderConfig> factory =
1553+
new ListProviderConfigsPage.Factory<SamlProviderConfig>(source, maxResults, pageToken);
1554+
return
1555+
new CallableOperation<ListProviderConfigsPage<SamlProviderConfig>, FirebaseAuthException>() {
1556+
@Override
1557+
protected ListProviderConfigsPage<SamlProviderConfig> execute()
1558+
throws FirebaseAuthException {
1559+
return factory.create();
1560+
}
1561+
};
1562+
}
1563+
14751564
/**
14761565
* Deletes the SAML Auth provider config identified by the specified provider ID.
14771566
*

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.google.firebase.auth.internal.GetAccountInfoResponse;
4646
import com.google.firebase.auth.internal.HttpErrorResponse;
4747
import com.google.firebase.auth.internal.ListOidcProviderConfigsResponse;
48+
import com.google.firebase.auth.internal.ListSamlProviderConfigsResponse;
4849
import com.google.firebase.auth.internal.ListTenantsResponse;
4950
import com.google.firebase.auth.internal.UploadAccountResponse;
5051
import com.google.firebase.internal.ApiClientUtils;
@@ -415,7 +416,7 @@ ListOidcProviderConfigsResponse listOidcProviderConfigs(int maxResults, String p
415416
ImmutableMap.<String, Object>builder().put("pageSize", maxResults);
416417
if (pageToken != null) {
417418
checkArgument(!pageToken.equals(
418-
ListTenantsPage.END_OF_LIST), "Invalid end of list page token.");
419+
ListProviderConfigsPage.END_OF_LIST), "Invalid end of list page token.");
419420
builder.put("nextPageToken", pageToken);
420421
}
421422

@@ -429,6 +430,26 @@ ListOidcProviderConfigsResponse listOidcProviderConfigs(int maxResults, String p
429430
return response;
430431
}
431432

433+
ListSamlProviderConfigsResponse listSamlProviderConfigs(int maxResults, String pageToken)
434+
throws FirebaseAuthException {
435+
ImmutableMap.Builder<String, Object> builder =
436+
ImmutableMap.<String, Object>builder().put("pageSize", maxResults);
437+
if (pageToken != null) {
438+
checkArgument(!pageToken.equals(
439+
ListProviderConfigsPage.END_OF_LIST), "Invalid end of list page token.");
440+
builder.put("nextPageToken", pageToken);
441+
}
442+
443+
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + "/inboundSamlConfigs");
444+
url.putAll(builder.build());
445+
ListSamlProviderConfigsResponse response =
446+
sendRequest("GET", url, null, ListSamlProviderConfigsResponse.class);
447+
if (response == null) {
448+
throw new FirebaseAuthException(INTERNAL_ERROR, "Failed to retrieve provider configs.");
449+
}
450+
return response;
451+
}
452+
432453
void deleteOidcProviderConfig(String providerId) throws FirebaseAuthException {
433454
GenericUrl url = new GenericUrl(idpConfigMgtBaseUrl + getOidcUrlSuffix(providerId));
434455
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)