Skip to content

Commit e417321

Browse files
authored
Merge pull request #1528 from marklogic/feature/property-renaming
Renamed securityContextType property to authType
2 parents e5977c1 + 4546030 commit e417321

File tree

10 files changed

+66
-65
lines changed

10 files changed

+66
-65
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/ConnectedRESTQA.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public abstract class ConnectedRESTQA {
5050

5151
protected static Properties testProperties = null;
5252

53-
protected static String securityContextType;
53+
protected static String authType;
5454
protected static String restServerName = null;
5555
private static String restSslServerName = null;
5656
private static String ssl_enabled = null;
@@ -2101,7 +2101,7 @@ private static void overrideTestPropertiesWithSystemProperties(Properties testPr
21012101
testProperties.setProperty("httpPort", "8020");
21022102
testProperties.setProperty("marklogic.client.port", "8020");
21032103
testProperties.setProperty("marklogic.client.basePath", "testFunctional");
2104-
testProperties.setProperty("marklogic.client.securityContextType", "basic");
2104+
testProperties.setProperty("marklogic.client.authType", "basic");
21052105
}
21062106
}
21072107

@@ -2119,7 +2119,7 @@ public static void loadGradleProperties() {
21192119

21202120
overrideTestPropertiesWithSystemProperties(properties);
21212121

2122-
securityContextType = properties.getProperty("marklogic.client.securityContextType");
2122+
authType = properties.getProperty("marklogic.client.authType");
21232123
restServerName = properties.getProperty("mlAppServerName");
21242124
restSslServerName = properties.getProperty("mlAppServerSSLName");
21252125

@@ -2151,9 +2151,9 @@ public static void loadGradleProperties() {
21512151
testProperties = properties;
21522152

21532153
System.out.println("For 'slow' tests, will connect to: " + host_name + ":" + http_port + "; basePath: " + basePath +
2154-
"; auth: " + securityContextType);
2154+
"; auth: " + authType);
21552155
System.out.println("For 'fast' tests, will connect to: " + host_name + ":" + fast_http_port + "; basePath: " + basePath +
2156-
"; auth: " + securityContextType);
2156+
"; auth: " + authType);
21572157
}
21582158

21592159
public static boolean isLBHost() {
@@ -2598,7 +2598,7 @@ public static void associateRESTServerWithModuleDB(String restServerName, String
25982598
}
25992599

26002600
public static DatabaseClientFactory.SecurityContext newSecurityContext(String username, String password) {
2601-
if ("basic".equalsIgnoreCase(securityContextType)) {
2601+
if ("basic".equalsIgnoreCase(authType)) {
26022602
return new DatabaseClientFactory.BasicAuthContext(username, password);
26032603
}
26042604
return new DatabaseClientFactory.DigestAuthContext(username, password);

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestDatabaseClientConnection.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.marklogic.client.query.*;
3333
import org.custommonkey.xmlunit.exceptions.XpathException;
3434
import org.junit.jupiter.api.AfterAll;
35-
import org.junit.jupiter.api.AfterEach;
3635
import org.junit.jupiter.api.BeforeAll;
3736
import org.junit.jupiter.api.Test;
3837
import org.w3c.dom.Document;
@@ -1019,7 +1018,7 @@ public static void tearDown() throws Exception {
10191018
System.out.println("In tear down");
10201019

10211020
if (!IsSecurityEnabled()) {
1022-
setAuthenticationAndDefaultUser(restServerName, securityContextType, "nobody");
1021+
setAuthenticationAndDefaultUser(restServerName, authType, "nobody");
10231022
}
10241023
// Associate the Server with Documents. Due to test orders being
10251024
// undeterministic not sure which DB will be associated.

marklogic-client-api-functionaltests/src/test/resources/test.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Standard properties for constructing a DatabaseClient
22
marklogic.client.host=localhost
33
marklogic.client.port=8014
4-
marklogic.client.securityContextType=digest
4+
marklogic.client.authType=digest
55
marklogic.client.username=opticUser
66
marklogic.client.password=0pt1c
77
marklogic.client.basePath=

marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientBuilder.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
public class DatabaseClientBuilder {
3939

4040
public final static String PREFIX = "marklogic.client.";
41-
public final static String SECURITY_CONTEXT_TYPE_BASIC = "basic";
42-
public final static String SECURITY_CONTEXT_TYPE_DIGEST = "digest";
43-
public final static String SECURITY_CONTEXT_TYPE_MARKLOGIC_CLOUD = "cloud";
44-
public final static String SECURITY_CONTEXT_TYPE_KERBEROS = "kerberos";
45-
public final static String SECURITY_CONTEXT_TYPE_CERTIFICATE = "certificate";
46-
public final static String SECURITY_CONTEXT_TYPE_SAML = "saml";
41+
public final static String AUTH_TYPE_BASIC = "basic";
42+
public final static String AUTH_TYPE_DIGEST = "digest";
43+
public final static String AUTH_TYPE_MARKLOGIC_CLOUD = "cloud";
44+
public final static String AUTH_TYPE_KERBEROS = "kerberos";
45+
public final static String AUTH_TYPE_CERTIFICATE = "certificate";
46+
public final static String AUTH_TYPE_SAML = "saml";
4747

4848
private final Map<String, Object> props;
4949

@@ -124,42 +124,42 @@ public DatabaseClientBuilder withSecurityContext(DatabaseClientFactory.SecurityC
124124
* @param type must be one of "basic", "digest", "cloud", "kerberos", "certificate", or "saml"
125125
* @return
126126
*/
127-
public DatabaseClientBuilder withSecurityContextType(String type) {
128-
props.put(PREFIX + "securityContextType", type);
127+
public DatabaseClientBuilder withAuthType(String type) {
128+
props.put(PREFIX + "authType", type);
129129
return this;
130130
}
131131

132132
public DatabaseClientBuilder withBasicAuth(String username, String password) {
133-
return withSecurityContextType(SECURITY_CONTEXT_TYPE_BASIC)
133+
return withAuthType(AUTH_TYPE_BASIC)
134134
.withUsername(username)
135135
.withPassword(password);
136136
}
137137

138138
public DatabaseClientBuilder withDigestAuth(String username, String password) {
139-
return withSecurityContextType(SECURITY_CONTEXT_TYPE_DIGEST)
139+
return withAuthType(AUTH_TYPE_DIGEST)
140140
.withUsername(username)
141141
.withPassword(password);
142142
}
143143

144144
public DatabaseClientBuilder withMarkLogicCloudAuth(String apiKey, String basePath) {
145-
return withSecurityContextType(SECURITY_CONTEXT_TYPE_MARKLOGIC_CLOUD)
145+
return withAuthType(AUTH_TYPE_MARKLOGIC_CLOUD)
146146
.withCloudApiKey(apiKey)
147147
.withBasePath(basePath);
148148
}
149149

150150
public DatabaseClientBuilder withKerberosAuth(String principal) {
151-
return withSecurityContextType(SECURITY_CONTEXT_TYPE_KERBEROS)
151+
return withAuthType(AUTH_TYPE_KERBEROS)
152152
.withKerberosPrincipal(principal);
153153
}
154154

155155
public DatabaseClientBuilder withCertificateAuth(String file, String password) {
156-
return withSecurityContextType(SECURITY_CONTEXT_TYPE_CERTIFICATE)
156+
return withAuthType(AUTH_TYPE_CERTIFICATE)
157157
.withCertificateFile(file)
158158
.withCertificatePassword(password);
159159
}
160160

161161
public DatabaseClientBuilder withSAMLAuth(String token) {
162-
return withSecurityContextType(SECURITY_CONTEXT_TYPE_SAML)
162+
return withAuthType(AUTH_TYPE_SAML)
163163
.withSAMLToken(token);
164164
}
165165

marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientFactory.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ public SecurityContext withSSLContext(SSLContext context, X509TrustManager trust
452452
public static class MarkLogicCloudAuthContext extends AuthContext {
453453
private String tokenEndpoint;
454454
private String grantType;
455-
private String key;
455+
private String apiKey;
456456

457-
public MarkLogicCloudAuthContext(String key) {
458-
this(key, "/token", "apikey");
457+
public MarkLogicCloudAuthContext(String apiKey) {
458+
this(apiKey, "/token", "apikey");
459459
}
460460

461-
public MarkLogicCloudAuthContext(String key, String tokenEndpoint, String grantType) {
462-
this.key = key;
461+
public MarkLogicCloudAuthContext(String apiKey, String tokenEndpoint, String grantType) {
462+
this.apiKey = apiKey;
463463
this.tokenEndpoint = tokenEndpoint;
464464
this.grantType = grantType;
465465
}
@@ -472,8 +472,8 @@ public String getGrantType() {
472472
return grantType;
473473
}
474474

475-
public String getKey() {
476-
return key;
475+
public String getApiKey() {
476+
return apiKey;
477477
}
478478

479479
@Override
@@ -1230,16 +1230,18 @@ public String getCertificatePassword() {
12301230
* <li>marklogic.client.database = must be a String</li>
12311231
* <li>marklogic.client.connectionType = must be a String or instance of {@code ConnectionType}</li>
12321232
* <li>marklogic.client.securityContext = an instance of {@code SecurityContext}; if set, then all other
1233-
* properties pertaining to the construction of a {@code SecurityContext} will be ignored, including the
1234-
* properties pertaing to SSL</li>
1235-
* <li>marklogic.client.securityContextType = required if marklogic.client.securityContext is not set;
1236-
* must be a String and one of "basic", "digest", "cloud", "kerberos", "certificate", or "saml"</li>
1233+
* authentication properties pertaining to the construction of a {@code SecurityContext} will be ignored,
1234+
* including the properties pertaining to SSL; this is effectively an escape hatch for providing a
1235+
* {@code SecurityContext} in case an appropriate one cannot be created via the other supported properties</li>
1236+
* <li>marklogic.client.authType = determines the type of authentication to use; required if
1237+
* marklogic.client.securityContext is not set; must be a String and one of "basic", "digest", "cloud",
1238+
* "kerberos", "certificate", or "saml"</li>
12371239
* <li>marklogic.client.username = must be a String; required for basic and digest authentication</li>
12381240
* <li>marklogic.client.password = must be a String; required for basic and digest authentication</li>
1239-
* <li>marklogic.client.cloud.apiKey = must be a String; required for cloud authentication</li>
1240-
* <li>marklogic.client.kerberos.principal = must be a String</li>
12411241
* <li>marklogic.client.certificate.file = must be a String; required for certificate authentication</li>
12421242
* <li>marklogic.client.certificate.password = must be a String; required for certificate authentication</li>
1243+
* <li>marklogic.client.cloud.apiKey = must be a String; required for cloud authentication</li>
1244+
* <li>marklogic.client.kerberos.principal = must be a String; required for Kerberos authentication</li>
12431245
* <li>marklogic.client.saml.token = must be a String; required for SAML authentication</li>
12441246
* <li>marklogic.client.sslContext = must be an instance of {@code javax.net.ssl.SSLContext}</li>
12451247
* <li>marklogic.client.sslProtocol = must be a String; if "default', then uses the JVM default SSL

marklogic-client-api/src/main/java/com/marklogic/client/impl/DatabaseClientPropertySource.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ private DatabaseClientFactory.SecurityContext newSecurityContext() {
136136
throw new IllegalArgumentException("Security context must be of type " + DatabaseClientFactory.SecurityContext.class.getName());
137137
}
138138

139-
Object typeValue = propertySource.apply(PREFIX + "securityContextType");
139+
Object typeValue = propertySource.apply(PREFIX + "authType");
140140
if (typeValue == null || !(typeValue instanceof String)) {
141-
throw new IllegalArgumentException("Security context should be set, or security context type must be of type String");
141+
throw new IllegalArgumentException("Security context should be set, or auth type must be of type String");
142142
}
143-
final String securityContextType = (String)typeValue;
144-
final SSLInputs sslInputs = buildSSLInputs(securityContextType);
143+
final String authType = (String)typeValue;
144+
final SSLInputs sslInputs = buildSSLInputs(authType);
145145

146-
DatabaseClientFactory.SecurityContext securityContext = newSecurityContext(securityContextType, sslInputs);
146+
DatabaseClientFactory.SecurityContext securityContext = newSecurityContext(authType, sslInputs);
147147

148148
X509TrustManager trustManager = determineTrustManager(sslInputs);
149149
SSLContext sslContext = sslInputs.getSslContext() != null ?
@@ -160,20 +160,20 @@ private DatabaseClientFactory.SecurityContext newSecurityContext() {
160160

161161
private DatabaseClientFactory.SecurityContext newSecurityContext(String type, SSLInputs sslInputs) {
162162
switch (type.toLowerCase()) {
163-
case DatabaseClientBuilder.SECURITY_CONTEXT_TYPE_BASIC:
163+
case DatabaseClientBuilder.AUTH_TYPE_BASIC:
164164
return newBasicAuthContext();
165-
case DatabaseClientBuilder.SECURITY_CONTEXT_TYPE_DIGEST:
165+
case DatabaseClientBuilder.AUTH_TYPE_DIGEST:
166166
return newDigestAuthContext();
167-
case DatabaseClientBuilder.SECURITY_CONTEXT_TYPE_MARKLOGIC_CLOUD:
167+
case DatabaseClientBuilder.AUTH_TYPE_MARKLOGIC_CLOUD:
168168
return newCloudAuthContext();
169-
case DatabaseClientBuilder.SECURITY_CONTEXT_TYPE_KERBEROS:
169+
case DatabaseClientBuilder.AUTH_TYPE_KERBEROS:
170170
return newKerberosAuthContext();
171-
case DatabaseClientBuilder.SECURITY_CONTEXT_TYPE_CERTIFICATE:
171+
case DatabaseClientBuilder.AUTH_TYPE_CERTIFICATE:
172172
return newCertificateAuthContext(sslInputs);
173-
case DatabaseClientBuilder.SECURITY_CONTEXT_TYPE_SAML:
173+
case DatabaseClientBuilder.AUTH_TYPE_SAML:
174174
return newSAMLAuthContext();
175175
default:
176-
throw new IllegalArgumentException("Unrecognized security context type: " + type);
176+
throw new IllegalArgumentException("Unrecognized auth type: " + type);
177177
}
178178
}
179179

@@ -302,11 +302,11 @@ private DatabaseClientFactory.SSLHostnameVerifier determineHostnameVerifier() {
302302
* Uses the given propertySource to construct the inputs pertaining to constructing an SSLContext and an
303303
* X509TrustManager.
304304
*
305-
* @param securityContextType used for applying "default" as the SSL protocol for MarkLogic cloud authentication in
305+
* @param authType used for applying "default" as the SSL protocol for MarkLogic cloud authentication in
306306
* case the user does not define their own SSLContext or SSL protocol
307307
* @return
308308
*/
309-
private SSLInputs buildSSLInputs(String securityContextType) {
309+
private SSLInputs buildSSLInputs(String authType) {
310310
SSLContext sslContext = null;
311311
Object val = propertySource.apply(PREFIX + "sslContext");
312312
if (val != null) {
@@ -320,7 +320,7 @@ private SSLInputs buildSSLInputs(String securityContextType) {
320320
String sslProtocol = getNullableStringValue("sslProtocol");
321321
if (sslContext == null &&
322322
(sslProtocol == null || sslProtocol.trim().length() == 0) &&
323-
DatabaseClientBuilder.SECURITY_CONTEXT_TYPE_MARKLOGIC_CLOUD.equalsIgnoreCase(securityContextType)) {
323+
DatabaseClientBuilder.AUTH_TYPE_MARKLOGIC_CLOUD.equalsIgnoreCase(authType)) {
324324
sslProtocol = "default";
325325
}
326326

marklogic-client-api/src/main/java/com/marklogic/client/impl/okhttp/MarkLogicCloudAuthenticationConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public MarkLogicCloudAuthenticationConfigurer(String host) {
3636

3737
@Override
3838
public void configureAuthentication(OkHttpClient.Builder clientBuilder, MarkLogicCloudAuthContext securityContext) {
39-
final String apiKey = securityContext.getKey();
39+
final String apiKey = securityContext.getApiKey();
4040
if (apiKey == null || apiKey.trim().length() < 1) {
4141
throw new IllegalArgumentException("No API key provided");
4242
}
@@ -97,7 +97,7 @@ protected HttpUrl buildTokenUrl(MarkLogicCloudAuthContext securityContext) {
9797
protected FormBody newFormBody(MarkLogicCloudAuthContext securityContext) {
9898
return new FormBody.Builder()
9999
.add("grant_type", securityContext.getGrantType())
100-
.add("key", securityContext.getKey()).build();
100+
.add("key", securityContext.getApiKey()).build();
101101
}
102102

103103
private String getAccessTokenFromResponse(Response response) {

marklogic-client-api/src/test/java/com/marklogic/client/impl/DatabaseClientPropertySourceTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class DatabaseClientPropertySourceTest {
2727
@BeforeEach
2828
void beforeEach() {
2929
props = new HashMap() {{
30-
put(PREFIX + "securityContextType", "digest");
30+
put(PREFIX + "authType", "digest");
3131
put(PREFIX + "username", "someuser");
3232
put(PREFIX + "password", "someword");
3333
}};
@@ -74,7 +74,7 @@ void stringPort() {
7474

7575
@Test
7676
void cloudAuthWithNoSslInputs() {
77-
props.put(PREFIX + "securityContextType", "cloud");
77+
props.put(PREFIX + "authType", "cloud");
7878
props.put(PREFIX + "cloud.apiKey", "abc123");
7979
props.put(PREFIX + "basePath", "/my/path");
8080

@@ -84,7 +84,7 @@ void cloudAuthWithNoSslInputs() {
8484
assertTrue(bean.getSecurityContext() instanceof DatabaseClientFactory.MarkLogicCloudAuthContext);
8585

8686
DatabaseClientFactory.MarkLogicCloudAuthContext context = (DatabaseClientFactory.MarkLogicCloudAuthContext) bean.getSecurityContext();
87-
assertEquals("abc123", context.getKey());
87+
assertEquals("abc123", context.getApiKey());
8888

8989
assertNotNull(context.getSSLContext(), "If cloud is chosen with no SSL protocol or context, the default JVM " +
9090
"SSLContext should be used");

marklogic-client-api/src/test/java/com/marklogic/client/test/Common.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class Common {
5151

5252
final public static boolean USE_REVERSE_PROXY_SERVER = Boolean.parseBoolean(System.getProperty("TEST_USE_REVERSE_PROXY_SERVER", "false"));
5353
final public static int PORT = USE_REVERSE_PROXY_SERVER ? 8020 : Integer.parseInt(System.getProperty("TEST_PORT", "8012"));
54-
final public static String SECURITY_CONTEXT_TYPE = USE_REVERSE_PROXY_SERVER ? "basic" : System.getProperty("TEST_SECURITY_CONTEXT_TYPE", "digest");
54+
final public static String AUTH_TYPE = USE_REVERSE_PROXY_SERVER ? "basic" : System.getProperty("TEST_AUTH_TYPE", "digest");
5555
final public static String BASE_PATH = USE_REVERSE_PROXY_SERVER ? "test/marklogic/unit" : System.getProperty("TEST_BASE_PATH", null);
5656
final public static boolean WITH_WAIT = Boolean.parseBoolean(System.getProperty("TEST_WAIT", "false"));
5757
final public static int PROPERTY_WAIT = Integer.parseInt(System.getProperty("TEST_PROPERTY_WAIT", WITH_WAIT ? "8200" : "0"));
@@ -114,7 +114,7 @@ public static DatabaseClient newClient() {
114114
}
115115

116116
public static DatabaseClientFactory.SecurityContext newSecurityContext(String username, String password) {
117-
if ("basic".equalsIgnoreCase(SECURITY_CONTEXT_TYPE)) {
117+
if ("basic".equalsIgnoreCase(AUTH_TYPE)) {
118118
return new DatabaseClientFactory.BasicAuthContext(username, password);
119119
}
120120
return new DatabaseClientFactory.DigestAuthContext(username, password);
@@ -127,7 +127,7 @@ public static DatabaseClientBuilder newClientBuilder() {
127127
.withBasePath(BASE_PATH)
128128
.withUsername(USER)
129129
.withPassword(PASS) // Most of the test users all have the same password, so we can use a default one here
130-
.withSecurityContextType(SECURITY_CONTEXT_TYPE)
130+
.withAuthType(AUTH_TYPE)
131131
.withConnectionType(CONNECTION_TYPE);
132132
}
133133

marklogic-client-api/src/test/java/com/marklogic/client/test/DatabaseClientBuilderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ void noSecurityContextOrType() {
6262
.withHost("some-host")
6363
.withPort(10)
6464
.buildBean());
65-
assertEquals("Security context should be set, or security context type must be of type String", ex.getMessage());
65+
assertEquals("Security context should be set, or auth type must be of type String", ex.getMessage());
6666
}
6767

6868
@Test
69-
void invalidSecurityContextType() {
69+
void invalidAuthType() {
7070
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> new DatabaseClientBuilder()
7171
.withHost("another-host")
7272
.withPort(200)
73-
.withSecurityContextType("invalid-type")
73+
.withAuthType("invalid-type")
7474
.buildBean());
75-
assertEquals("Unrecognized security context type: invalid-type", ex.getMessage());
75+
assertEquals("Unrecognized auth type: invalid-type", ex.getMessage());
7676
}
7777

7878
@Test
@@ -105,7 +105,7 @@ void cloudWithBasePath() {
105105

106106
DatabaseClientFactory.MarkLogicCloudAuthContext context =
107107
(DatabaseClientFactory.MarkLogicCloudAuthContext) bean.getSecurityContext();
108-
assertEquals("my-key", context.getKey());
108+
assertEquals("my-key", context.getApiKey());
109109
assertEquals("/my/path", bean.getBasePath());
110110

111111
assertNotNull(context.getSSLContext(), "If no sslProtocol or sslContext is set, the JVM's default SSL " +
@@ -121,7 +121,7 @@ void cloudWithBasePath() {
121121
@Test
122122
void cloudNoApiKey() {
123123
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> Common.newClientBuilder()
124-
.withSecurityContextType("cloud")
124+
.withAuthType("cloud")
125125
.withBasePath("/my/path")
126126
.build());
127127
assertEquals("cloud.apiKey must be of type String", ex.getMessage());

0 commit comments

Comments
 (0)