19
19
20
20
/*
21
21
* Copyright (c) 2020, Chris Fraire <[email protected] >.
22
- * Copyright (c) 2020, 2021 , Oracle and/or its affiliates. All rights reserved.
22
+ * Copyright (c) 2020, 2025 , Oracle and/or its affiliates. All rights reserved.
23
23
*/
24
24
package opengrok .auth .plugin ;
25
25
@@ -141,7 +141,7 @@ void shouldThrowOnLoadIfUnreadableFileSpecified(String param) {
141
141
init (param );
142
142
HashMap <String , Object > unreadablePluginParameters = new HashMap <>();
143
143
unreadablePluginParameters .put (UserWhiteListPlugin .FILE_PARAM ,
144
- RandomStringUtils .randomAlphanumeric (24 ));
144
+ RandomStringUtils .secure (). nextAlphanumeric (24 ));
145
145
146
146
IllegalArgumentException caughtException = null ;
147
147
try {
@@ -188,8 +188,9 @@ void shouldStripWhitespaceFromWhitelists(String param) throws IOException {
188
188
}
189
189
190
190
// Make sure there as some entries with trailing spaces in the file.
191
- Stream <String > stream = Files .lines (tmpFile .toPath ());
192
- assertTrue (stream .anyMatch (s -> s .startsWith (" " ) || s .endsWith (" " )));
191
+ try (Stream <String > stream = Files .lines (tmpFile .toPath ())) {
192
+ assertTrue (stream .anyMatch (s -> s .startsWith (" " ) || s .endsWith (" " )));
193
+ }
193
194
194
195
pluginParameters .put (UserWhiteListPlugin .FILE_PARAM , tmpFile .toString ());
195
196
plugin .load (pluginParameters );
@@ -221,11 +222,11 @@ void shouldAllowWhitelistedUserForAnyProject(String param) {
221
222
}
222
223
req .setAttribute (UserPlugin .REQUEST_ATTR , user );
223
224
224
- Project randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
225
+ Project randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
225
226
boolean projectAllowed = plugin .isAllowed (req , randomProject );
226
227
assertTrue (projectAllowed , "should allow OK entity for random project 1" );
227
228
228
- randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
229
+ randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
229
230
projectAllowed = plugin .isAllowed (req , randomProject );
230
231
assertTrue (projectAllowed , "should allow OK entity for random project 2" );
231
232
}
@@ -237,13 +238,13 @@ void shouldNotAllowRandomUserForAnyProject(String param) {
237
238
plugin .load (validPluginParameters );
238
239
239
240
DummyHttpServletRequest req = new DummyHttpServletRequest ();
240
- req .setAttribute (UserPlugin .REQUEST_ATTR , new User (RandomStringUtils .randomAlphanumeric (8 )));
241
+ req .setAttribute (UserPlugin .REQUEST_ATTR , new User (RandomStringUtils .secure (). nextAlphanumeric (8 )));
241
242
242
- Project randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
243
+ Project randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
243
244
boolean projectAllowed = plugin .isAllowed (req , randomProject );
244
245
assertFalse (projectAllowed , "should not allow random user for random project 1" );
245
246
246
- randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
247
+ randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
247
248
projectAllowed = plugin .isAllowed (req , randomProject );
248
249
assertFalse (projectAllowed , "should not allow random user for random project 2" );
249
250
}
@@ -263,11 +264,11 @@ void shouldAllowWhitelistedUserForAnyGroup(String param) {
263
264
}
264
265
req .setAttribute (UserPlugin .REQUEST_ATTR , user );
265
266
266
- Group randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
267
+ Group randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
267
268
boolean groupAllowed = plugin .isAllowed (req , randomGroup );
268
269
assertTrue (groupAllowed , "should allow OK entity for random group 1" );
269
270
270
- randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
271
+ randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
271
272
groupAllowed = plugin .isAllowed (req , randomGroup );
272
273
assertTrue (groupAllowed , "should allow OK entity for random group 2" );
273
274
}
@@ -279,13 +280,13 @@ void shouldNotAllowRandomUserForAnyGroup(String param) {
279
280
plugin .load (validPluginParameters );
280
281
281
282
DummyHttpServletRequest req = new DummyHttpServletRequest ();
282
- req .setAttribute (UserPlugin .REQUEST_ATTR , new User (RandomStringUtils .randomAlphanumeric (8 )));
283
+ req .setAttribute (UserPlugin .REQUEST_ATTR , new User (RandomStringUtils .secure (). nextAlphanumeric (8 )));
283
284
284
- Group randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
285
+ Group randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
285
286
boolean projectAllowed = plugin .isAllowed (req , randomGroup );
286
287
assertFalse (projectAllowed , "should not allow random group 1" );
287
288
288
- randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
289
+ randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
289
290
projectAllowed = plugin .isAllowed (req , randomGroup );
290
291
assertFalse (projectAllowed , "should not allow random group 2" );
291
292
}
0 commit comments