9090import java .util .Map ;
9191import java .util .Set ;
9292import java .util .regex .Matcher ;
93+ import java .util .regex .Pattern ;
9394
9495public class JBrowseController extends SpringActionController
9596{
@@ -335,15 +336,29 @@ public void setDatabaseIds(String[] databaseIds)
335336 }
336337 }
337338
339+ // Based on: https://www.code4copy.com/java/validate-uuid-string-java/
340+ private final static Pattern UUID_REGEX_PATTERN = Pattern .compile ("^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$" );
341+
342+ private static boolean isValidUUID (String str )
343+ {
344+ if (str == null )
345+ {
346+ return false ;
347+ }
348+
349+ return UUID_REGEX_PATTERN .matcher (str ).matches ();
350+ }
351+
338352 @ RequiresPermission (ReadPermission .class )
339- public class BrowserAction extends SimpleViewAction <BrowserForm >
353+ public class JBrowseAction extends SimpleViewAction <BrowserForm >
340354 {
341355 private String _title ;
342356
343357 @ Override
344358 public ModelAndView getView (BrowserForm form , BindException errors ) throws Exception
345359 {
346- JBrowseSession db = new TableSelector (JBrowseSchema .getInstance ().getTable (JBrowseSchema .TABLE_DATABASES ), new SimpleFilter (FieldKey .fromString ("objectid" ), form .getDatabase ()), null ).getObject (JBrowseSession .class );
360+ String guid = form .getEffectiveSessionId ();
361+ JBrowseSession db = isValidUUID (guid ) ? new TableSelector (JBrowseSchema .getInstance ().getTable (JBrowseSchema .TABLE_DATABASES ), new SimpleFilter (FieldKey .fromString ("objectid" ), form .getEffectiveSessionId ()), null ).getObject (JBrowseSession .class ) : null ;
347362 _title = db == null ? "JBrowse" : db .getName ();
348363 form .setPageTitle (_title );
349364
@@ -361,9 +376,16 @@ public void addNavTrail(NavTree root)
361376 }
362377 }
363378
379+ @ RequiresPermission (ReadPermission .class )
380+ public class BrowserAction extends JBrowseAction
381+ {
382+
383+ }
384+
364385 public static class BrowserForm
365386 {
366387 private String _database ;
388+ private String _session ;
367389 private String _pageTitle ;
368390
369391 public String getDatabase ()
@@ -376,6 +398,21 @@ public void setDatabase(String database)
376398 _database = database ;
377399 }
378400
401+ public String getSession ()
402+ {
403+ return _session ;
404+ }
405+
406+ public String getEffectiveSessionId ()
407+ {
408+ return _session == null ? _database : _session ;
409+ }
410+
411+ public void setSession (String session )
412+ {
413+ _session = session ;
414+ }
415+
379416 public String getPageTitle ()
380417 {
381418 return _pageTitle ;
0 commit comments