Skip to content

Commit 86dc1c2

Browse files
committed
Address pull request feedback.
1 parent c1c697d commit 86dc1c2

File tree

5 files changed

+42
-44
lines changed

5 files changed

+42
-44
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
import com.google.common.collect.ImmutableMap;
2424
import java.net.MalformedURLException;
2525
import java.net.URL;
26-
import java.util.ArrayList;
2726
import java.util.HashMap;
28-
import java.util.List;
2927
import java.util.Map;
3028

3129
/**
@@ -62,24 +60,6 @@ static void assertValidUrl(String url) throws IllegalArgumentException {
6260
}
6361
}
6462

65-
static List<Object> getNestedList(Map<String, Object> outerMap, String id) {
66-
List<Object> list = (List<Object>) outerMap.get(id);
67-
if (list == null) {
68-
list = new ArrayList<Object>();
69-
outerMap.put(id, list);
70-
}
71-
return list;
72-
}
73-
74-
static Map<String, Object> getNestedMap(Map<String, Object> outerMap, String id) {
75-
Map<String, Object> map = (Map<String, Object>) outerMap.get(id);
76-
if (map == null) {
77-
map = new HashMap<String, Object>();
78-
outerMap.put(id, map);
79-
}
80-
return map;
81-
}
82-
8363
/**
8464
* A base specification class for creating a new provider.
8565
*

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

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ public String getCallbackUrl() {
6464
return spConfig.getCallbackUrl();
6565
}
6666

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+
6785
/**
6886
* A specification class for creating a new SAML Auth provider.
6987
*
@@ -90,7 +108,7 @@ public CreateRequest() { }
90108
public CreateRequest setIdpEntityId(String idpEntityId) {
91109
checkArgument(!Strings.isNullOrEmpty(idpEntityId),
92110
"IDP entity ID must not be null or empty.");
93-
getNestedMap(properties, "idpConfig").put("idpEntityId", idpEntityId);
111+
ensureNestedMap(properties, "idpConfig").put("idpEntityId", idpEntityId);
94112
return this;
95113
}
96114

@@ -104,19 +122,7 @@ public CreateRequest setIdpEntityId(String idpEntityId) {
104122
public CreateRequest setSsoUrl(String ssoUrl) {
105123
checkArgument(!Strings.isNullOrEmpty(ssoUrl), "SSO URL must not be null or empty.");
106124
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);
120126
return this;
121127
}
122128

@@ -129,14 +135,26 @@ public CreateRequest setRpEntityId(String rpEntityId) {
129135
public CreateRequest addX509Certificate(String x509Certificate) {
130136
checkArgument(!Strings.isNullOrEmpty(x509Certificate),
131137
"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");
134140
x509Certificates.add(ImmutableMap.<String, Object>of("x509Certificate", x509Certificate));
135141
return this;
136142
}
137143

138144
// TODO(micahstairs): Add 'addAllX509Certificates' method.
139145

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+
140158
/**
141159
* Sets the callback URL for the new provider.
142160
*
@@ -147,7 +165,7 @@ public CreateRequest addX509Certificate(String x509Certificate) {
147165
public CreateRequest setCallbackUrl(String callbackUrl) {
148166
checkArgument(!Strings.isNullOrEmpty(callbackUrl), "Callback URL must not be null or empty.");
149167
assertValidUrl(callbackUrl);
150-
getNestedMap(properties, "spConfig").put("callbackUri", callbackUrl);
168+
ensureNestedMap(properties, "spConfig").put("callbackUri", callbackUrl);
151169
return this;
152170
}
153171

@@ -162,7 +180,7 @@ void assertValidProviderIdFormat(String providerId) {
162180
}
163181
}
164182

165-
public static class IdpCertificate {
183+
static class IdpCertificate {
166184
@Key("x509Certificate")
167185
private String x509Certificate;
168186

@@ -171,7 +189,7 @@ public String getX509Certificate() {
171189
}
172190
}
173191

174-
public static class IdpConfig {
192+
static class IdpConfig {
175193
@Key("idpEntityId")
176194
private String idpEntityId;
177195

@@ -194,7 +212,7 @@ public List<IdpCertificate> getIdpCertificates() {
194212
}
195213
}
196214

197-
public static class SpConfig {
215+
static class SpConfig {
198216
@Key("spEntityId")
199217
private String rpEntityId;
200218

src/test/java/com/google/firebase/auth/OidcProviderConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class OidcProviderConfigTest {
4141
+ "}").replace("'", "\"");
4242

4343
@Test
44-
public void testJsonSerialization() throws IOException {
44+
public void testJsonDeserialization() throws IOException {
4545
OidcProviderConfig config = jsonFactory.fromString(OIDC_JSON_STRING, OidcProviderConfig.class);
4646

4747
assertEquals("oidc.provider-id", config.getProviderId());

src/test/java/com/google/firebase/auth/SamlProviderConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class SamlProviderConfigTest {
5555
+ "}").replace("'", "\"");
5656

5757
@Test
58-
public void testJsonSerialization() throws IOException {
58+
public void testJsonDeserialization() throws IOException {
5959
SamlProviderConfig config = jsonFactory.fromString(SAML_JSON_STRING, SamlProviderConfig.class);
6060

6161
assertEquals("saml.provider-id", config.getProviderId());

src/test/java/com/google/firebase/auth/TenantTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class TenantTest {
3232

3333
private static final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
3434

35-
private static final String TENANT_JSON_STRING =
35+
private static final String TENANT_JSON_STRING =
3636
"{"
3737
+ "\"name\":\"projects/project-id/resource/TENANT_ID\","
3838
+ "\"displayName\":\"DISPLAY_NAME\","
@@ -41,7 +41,7 @@ public class TenantTest {
4141
+ "}";
4242

4343
@Test
44-
public void testJsonSerialization() throws IOException {
44+
public void testJsonDeserialization() throws IOException {
4545
Tenant tenant = jsonFactory.fromString(TENANT_JSON_STRING, Tenant.class);
4646

4747
assertEquals(tenant.getTenantId(), "TENANT_ID");

0 commit comments

Comments
 (0)