5
5
import java .util .Optional ;
6
6
import java .util .WeakHashMap ;
7
7
8
+ import javax .ws .rs .core .MediaType ;
8
9
import javax .ws .rs .core .Response ;
9
10
10
11
import org .gitlab4j .api .Constants .TokenType ;
11
12
import org .gitlab4j .api .models .OauthTokenResponse ;
12
13
import org .gitlab4j .api .models .Session ;
13
14
import org .gitlab4j .api .models .User ;
14
15
import org .gitlab4j .api .models .Version ;
16
+ import org .gitlab4j .api .utils .Oauth2LoginStreamingOutput ;
17
+ import org .gitlab4j .api .utils .SecretString ;
15
18
16
19
/**
17
20
* This class is provides a simplified interface to a GitLab API server, and divides the API up into
@@ -95,11 +98,44 @@ public final GitLabApi duplicate() {
95
98
* @param password password for a given {@code username}
96
99
* @return new {@code GitLabApi} instance configured for a user-specific token
97
100
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
101
+ * @deprecated As of release 4.8.7, replaced by {@link #oauth2Login(String, String, CharSequence)}, will be removed in 4.9.0
98
102
*/
103
+ @ Deprecated
99
104
public static GitLabApi oauth2Login (String url , String username , String password ) throws GitLabApiException {
100
105
return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , password , null , null , false ));
101
106
}
102
107
108
+ /**
109
+ * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
110
+ * and creates a new {@code GitLabApi} instance using returned access token.</p>
111
+ *
112
+ * @param url GitLab URL
113
+ * @param username user name for which private token should be obtained
114
+ * @param password a CharSequence containing the password for a given {@code username}
115
+ * @return new {@code GitLabApi} instance configured for a user-specific token
116
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
117
+ */
118
+ public static GitLabApi oauth2Login (String url , String username , CharSequence password ) throws GitLabApiException {
119
+ return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , password , null , null , false ));
120
+ }
121
+
122
+ /**
123
+ * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
124
+ * and creates a new {@code GitLabApi} instance using returned access token.</p>
125
+ *
126
+ * @param url GitLab URL
127
+ * @param username user name for which private token should be obtained
128
+ * @param password a char array holding the password for a given {@code username}
129
+ * @return new {@code GitLabApi} instance configured for a user-specific token
130
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
131
+ */
132
+ public static GitLabApi oauth2Login (String url , String username , char [] password ) throws GitLabApiException {
133
+
134
+ try (SecretString secretPassword = new SecretString (password )) {
135
+ return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , secretPassword , null , null , false ));
136
+ }
137
+ }
138
+
103
139
/**
104
140
* <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
105
141
* and creates a new {@code GitLabApi} instance using returned access token.</p>
@@ -110,11 +146,46 @@ public static GitLabApi oauth2Login(String url, String username, String password
110
146
* @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
111
147
* @return new {@code GitLabApi} instance configured for a user-specific token
112
148
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
149
+ * @deprecated As of release 4.8.7, replaced by {@link #oauth2Login(String, String, CharSequence, boolean)}, will be removed in 4.9.0
113
150
*/
151
+ @ Deprecated
114
152
public static GitLabApi oauth2Login (String url , String username , String password , boolean ignoreCertificateErrors ) throws GitLabApiException {
115
153
return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , password , null , null , ignoreCertificateErrors ));
116
154
}
117
155
156
+ /**
157
+ * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
158
+ * and creates a new {@code GitLabApi} instance using returned access token.</p>
159
+ *
160
+ * @param url GitLab URL
161
+ * @param username user name for which private token should be obtained
162
+ * @param password a CharSequence containing the password for a given {@code username}
163
+ * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
164
+ * @return new {@code GitLabApi} instance configured for a user-specific token
165
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
166
+ */
167
+ public static GitLabApi oauth2Login (String url , String username , CharSequence password , boolean ignoreCertificateErrors ) throws GitLabApiException {
168
+ return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , password , null , null , ignoreCertificateErrors ));
169
+ }
170
+
171
+ /**
172
+ * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
173
+ * and creates a new {@code GitLabApi} instance using returned access token.</p>
174
+ *
175
+ * @param url GitLab URL
176
+ * @param username user name for which private token should be obtained
177
+ * @param password a char array holding the password for a given {@code username}
178
+ * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
179
+ * @return new {@code GitLabApi} instance configured for a user-specific token
180
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
181
+ */
182
+ public static GitLabApi oauth2Login (String url , String username , char [] password , boolean ignoreCertificateErrors ) throws GitLabApiException {
183
+
184
+ try (SecretString secretPassword = new SecretString (password )) {
185
+ return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , secretPassword , null , null , ignoreCertificateErrors ));
186
+ }
187
+ }
188
+
118
189
/**
119
190
* <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
120
191
* and creates a new {@code GitLabApi} instance using returned access token.</p>
@@ -127,13 +198,77 @@ public static GitLabApi oauth2Login(String url, String username, String password
127
198
* @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
128
199
* @return new {@code GitLabApi} instance configured for a user-specific token
129
200
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
201
+ * @deprecated As of release 4.8.7, will be removed in 4.9.0
130
202
*/
131
- public static GitLabApi oauth2Login (String url , String username , String password ,
132
- String secretToken , Map <String , Object > clientConfigProperties , boolean ignoreCertificateErrors )
133
- throws GitLabApiException {
203
+ @ Deprecated
204
+ public static GitLabApi oauth2Login (String url , String username , String password , String secretToken ,
205
+ Map <String , Object > clientConfigProperties , boolean ignoreCertificateErrors ) throws GitLabApiException {
206
+ return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , password , secretToken , clientConfigProperties , ignoreCertificateErrors ));
207
+ }
208
+
209
+ /**
210
+ * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
211
+ * and creates a new {@code GitLabApi} instance using returned access token.</p>
212
+ *
213
+ * @param url GitLab URL
214
+ * @param username user name for which private token should be obtained
215
+ * @param password a CharSequence containing the password for a given {@code username}
216
+ * @param secretToken use this token to validate received payloads
217
+ * @param clientConfigProperties Map instance with additional properties for the Jersey client connection
218
+ * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
219
+ * @return new {@code GitLabApi} instance configured for a user-specific token
220
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
221
+ */
222
+ public static GitLabApi oauth2Login (String url , String username , CharSequence password , String secretToken ,
223
+ Map <String , Object > clientConfigProperties , boolean ignoreCertificateErrors ) throws GitLabApiException {
134
224
return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , password , secretToken , clientConfigProperties , ignoreCertificateErrors ));
135
225
}
136
226
227
+ /**
228
+ * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
229
+ * and creates a new {@code GitLabApi} instance using returned access token.</p>
230
+ *
231
+ * @param url GitLab URL
232
+ * @param username user name for which private token should be obtained
233
+ * @param password a char array holding the password for a given {@code username}
234
+ * @param secretToken use this token to validate received payloads
235
+ * @param clientConfigProperties Map instance with additional properties for the Jersey client connection
236
+ * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
237
+ * @return new {@code GitLabApi} instance configured for a user-specific token
238
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
239
+ */
240
+ public static GitLabApi oauth2Login (String url , String username , char [] password , String secretToken ,
241
+ Map <String , Object > clientConfigProperties , boolean ignoreCertificateErrors ) throws GitLabApiException {
242
+
243
+ try (SecretString secretPassword = new SecretString (password )) {
244
+ return (GitLabApi .oauth2Login (ApiVersion .V4 , url , username , secretPassword ,
245
+ secretToken , clientConfigProperties , ignoreCertificateErrors ));
246
+ }
247
+ }
248
+
249
+ /**
250
+ * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
251
+ * and creates a new {@code GitLabApi} instance using returned access token.</p>
252
+ *
253
+ * @param url GitLab URL
254
+ * @param apiVersion the ApiVersion specifying which version of the API to use
255
+ * @param username user name for which private token should be obtained
256
+ * @param password a char array holding the password for a given {@code username}
257
+ * @param secretToken use this token to validate received payloads
258
+ * @param clientConfigProperties Map instance with additional properties for the Jersey client connection
259
+ * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
260
+ * @return new {@code GitLabApi} instance configured for a user-specific token
261
+ * @throws GitLabApiException GitLabApiException if any exception occurs during execution
262
+ */
263
+ public static GitLabApi oauth2Login (ApiVersion apiVersion , String url , String username , char [] password , String secretToken ,
264
+ Map <String , Object > clientConfigProperties , boolean ignoreCertificateErrors ) throws GitLabApiException {
265
+
266
+ try (SecretString secretPassword = new SecretString (password )) {
267
+ return (GitLabApi .oauth2Login (apiVersion , url , username , secretPassword ,
268
+ secretToken , clientConfigProperties , ignoreCertificateErrors ));
269
+ }
270
+ }
271
+
137
272
/**
138
273
* <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password},
139
274
* and creates a new {@code GitLabApi} instance using returned access token.</p>
@@ -148,7 +283,7 @@ public static GitLabApi oauth2Login(String url, String username, String password
148
283
* @return new {@code GitLabApi} instance configured for a user-specific token
149
284
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
150
285
*/
151
- public static GitLabApi oauth2Login (ApiVersion apiVersion , String url , String username , String password ,
286
+ public static GitLabApi oauth2Login (ApiVersion apiVersion , String url , String username , CharSequence password ,
152
287
String secretToken , Map <String , Object > clientConfigProperties , boolean ignoreCertificateErrors )
153
288
throws GitLabApiException {
154
289
@@ -167,19 +302,17 @@ class Oauth2Api extends AbstractApi {
167
302
}
168
303
}
169
304
170
- GitLabApiForm formData = new GitLabApiForm ()
171
- .withParam ("grant_type" , "password" , true )
172
- .withParam ("username" , username , true )
173
- .withParam ("password" , password , true );
305
+ try (Oauth2LoginStreamingOutput stream = new Oauth2LoginStreamingOutput (username , password )) {
174
306
175
- Response response = new Oauth2Api (gitLabApi ).post (Response .Status .OK , formData , "oauth" , "token" );
176
- OauthTokenResponse oauthToken = response .readEntity (OauthTokenResponse .class );
177
- gitLabApi = new GitLabApi (apiVersion , url , TokenType .ACCESS , oauthToken .getAccessToken (), secretToken , clientConfigProperties );
178
- if (ignoreCertificateErrors ) {
179
- gitLabApi .setIgnoreCertificateErrors (true );
180
- }
307
+ Response response = new Oauth2Api (gitLabApi ).post (Response .Status .OK , stream , MediaType . APPLICATION_JSON , "oauth" , "token" );
308
+ OauthTokenResponse oauthToken = response .readEntity (OauthTokenResponse .class );
309
+ gitLabApi = new GitLabApi (apiVersion , url , TokenType .ACCESS , oauthToken .getAccessToken (), secretToken , clientConfigProperties );
310
+ if (ignoreCertificateErrors ) {
311
+ gitLabApi .setIgnoreCertificateErrors (true );
312
+ }
181
313
182
- return (gitLabApi );
314
+ return (gitLabApi );
315
+ }
183
316
}
184
317
185
318
/**
@@ -195,7 +328,9 @@ class Oauth2Api extends AbstractApi {
195
328
* @param password password for a given {@code username}
196
329
* @return new {@code GitLabApi} instance configured for a user-specific token
197
330
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
331
+ * @deprecated As of release 4.8.7, will be removed in 4.9.0
198
332
*/
333
+ @ Deprecated
199
334
public static GitLabApi login (ApiVersion apiVersion , String url , String username , String password ) throws GitLabApiException {
200
335
return (GitLabApi .login (apiVersion , url , username , password , false ));
201
336
}
@@ -212,7 +347,9 @@ public static GitLabApi login(ApiVersion apiVersion, String url, String username
212
347
* @param password password for a given {@code username}
213
348
* @return new {@code GitLabApi} instance configured for a user-specific token
214
349
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
350
+ * @deprecated As of release 4.8.7, will be removed in 4.9.0
215
351
*/
352
+ @ Deprecated
216
353
public static GitLabApi login (String url , String username , String password ) throws GitLabApiException {
217
354
return (GitLabApi .login (ApiVersion .V4 , url , username , password , false ));
218
355
}
@@ -231,7 +368,9 @@ public static GitLabApi login(String url, String username, String password) thro
231
368
* @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
232
369
* @return new {@code GitLabApi} instance configured for a user-specific token
233
370
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
371
+ * @deprecated As of release 4.8.7, will be removed in 4.9.0
234
372
*/
373
+ @ Deprecated
235
374
public static GitLabApi login (ApiVersion apiVersion , String url , String username , String password , boolean ignoreCertificateErrors ) throws GitLabApiException {
236
375
237
376
GitLabApi gitLabApi = new GitLabApi (apiVersion , url , (String )null );
@@ -273,7 +412,9 @@ public static GitLabApi login(ApiVersion apiVersion, String url, String username
273
412
* @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors
274
413
* @return new {@code GitLabApi} instance configured for a user-specific token
275
414
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
415
+ * @deprecated As of release 4.8.7, will be removed in 4.9.0
276
416
*/
417
+ @ Deprecated
277
418
public static GitLabApi login (String url , String username , String password , boolean ignoreCertificateErrors ) throws GitLabApiException {
278
419
return (GitLabApi .login (ApiVersion .V4 , url , username , password , ignoreCertificateErrors ));
279
420
}
@@ -287,7 +428,7 @@ public static GitLabApi login(String url, String username, String password, bool
287
428
* @param password password for a given {@code username}
288
429
* @return new {@code GitLabApi} instance configured for a user-specific token
289
430
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
290
- * @deprecated As of release 4.2.0, replaced by {@link #login(String, String, String)}, will be removed in 5.0 .0
431
+ * @deprecated As of release 4.2.0, replaced by {@link #login(String, String, String)}, will be removed in 4.9 .0
291
432
*/
292
433
@ Deprecated
293
434
public static GitLabApi create (String url , String username , String password ) throws GitLabApiException {
@@ -301,8 +442,9 @@ public static GitLabApi create(String url, String username, String password) thr
301
442
* <strong>NOTE</strong>: For GitLab servers 10.2 and above this method will always return null.
302
443
*
303
444
* @return the Session instance
304
- * @deprecated This method will be removed in Release 5.0 .0
445
+ * @deprecated This method will be removed in Release 4.9 .0
305
446
*/
447
+ @ Deprecated
306
448
public Session getSession () {
307
449
return session ;
308
450
}
0 commit comments