1919
2020/*
2121 * 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.
2323 */
2424package opengrok .auth .plugin ;
2525
@@ -141,7 +141,7 @@ void shouldThrowOnLoadIfUnreadableFileSpecified(String param) {
141141 init (param );
142142 HashMap <String , Object > unreadablePluginParameters = new HashMap <>();
143143 unreadablePluginParameters .put (UserWhiteListPlugin .FILE_PARAM ,
144- RandomStringUtils .randomAlphanumeric (24 ));
144+ RandomStringUtils .secure (). nextAlphanumeric (24 ));
145145
146146 IllegalArgumentException caughtException = null ;
147147 try {
@@ -188,8 +188,9 @@ void shouldStripWhitespaceFromWhitelists(String param) throws IOException {
188188 }
189189
190190 // 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+ }
193194
194195 pluginParameters .put (UserWhiteListPlugin .FILE_PARAM , tmpFile .toString ());
195196 plugin .load (pluginParameters );
@@ -221,11 +222,11 @@ void shouldAllowWhitelistedUserForAnyProject(String param) {
221222 }
222223 req .setAttribute (UserPlugin .REQUEST_ATTR , user );
223224
224- Project randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
225+ Project randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
225226 boolean projectAllowed = plugin .isAllowed (req , randomProject );
226227 assertTrue (projectAllowed , "should allow OK entity for random project 1" );
227228
228- randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
229+ randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
229230 projectAllowed = plugin .isAllowed (req , randomProject );
230231 assertTrue (projectAllowed , "should allow OK entity for random project 2" );
231232 }
@@ -237,13 +238,13 @@ void shouldNotAllowRandomUserForAnyProject(String param) {
237238 plugin .load (validPluginParameters );
238239
239240 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 )));
241242
242- Project randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
243+ Project randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
243244 boolean projectAllowed = plugin .isAllowed (req , randomProject );
244245 assertFalse (projectAllowed , "should not allow random user for random project 1" );
245246
246- randomProject = new Project (RandomStringUtils .randomAlphanumeric (10 ));
247+ randomProject = new Project (RandomStringUtils .secure (). nextAlphanumeric (10 ));
247248 projectAllowed = plugin .isAllowed (req , randomProject );
248249 assertFalse (projectAllowed , "should not allow random user for random project 2" );
249250 }
@@ -263,11 +264,11 @@ void shouldAllowWhitelistedUserForAnyGroup(String param) {
263264 }
264265 req .setAttribute (UserPlugin .REQUEST_ATTR , user );
265266
266- Group randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
267+ Group randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
267268 boolean groupAllowed = plugin .isAllowed (req , randomGroup );
268269 assertTrue (groupAllowed , "should allow OK entity for random group 1" );
269270
270- randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
271+ randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
271272 groupAllowed = plugin .isAllowed (req , randomGroup );
272273 assertTrue (groupAllowed , "should allow OK entity for random group 2" );
273274 }
@@ -279,13 +280,13 @@ void shouldNotAllowRandomUserForAnyGroup(String param) {
279280 plugin .load (validPluginParameters );
280281
281282 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 )));
283284
284- Group randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
285+ Group randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
285286 boolean projectAllowed = plugin .isAllowed (req , randomGroup );
286287 assertFalse (projectAllowed , "should not allow random group 1" );
287288
288- randomGroup = new Group (RandomStringUtils .randomAlphanumeric (10 ));
289+ randomGroup = new Group (RandomStringUtils .secure (). nextAlphanumeric (10 ));
289290 projectAllowed = plugin .isAllowed (req , randomGroup );
290291 assertFalse (projectAllowed , "should not allow random group 2" );
291292 }
0 commit comments