@@ -227,92 +227,114 @@ public static void reopenSession() throws SDException, IOException
227227 // Do not use this method without getting a sessionLock write lock first.
228228 private static SDSession openNewSession () throws IOException , SDException
229229 {
230- SDSession returnValue ;
230+ SDSession returnValue = null ;
231231 BufferedReader reader = null ;
232232
233233 //2025-02-28 jusjoken: switch to using sage properties for user/pass so it can be shared with clients that need it
234- String username = null ;
235- String password = null ;
234+ String propUsername = null ;
235+ String propPassword = null ;
236+ String fileUsername = null ;
237+ String filePassword = null ;
236238
239+ //get the property based user/pass if any
237240 if (Sage .client ){ //get the server property
238241 try
239242 {
240243 Object serverProp = SageTV .api ("GetServerProperty" , new Object [] { PROP_USERNAME , null });
241- username = serverProp .toString ();
244+ propUsername = serverProp .toString ();
242245 serverProp = SageTV .api ("GetServerProperty" , new Object [] { PROP_PASSWORD , null });
243- password = serverProp .toString ();
246+ propPassword = serverProp .toString ();
244247 //if (Sage.DBG) System.out.println("***EPG*** getting from CLIENT user/pass: username:" + username + " password:" + password);
245248 }
246249 catch (Throwable t )
247250 {
248251 if (Sage .DBG ) System .out .println ("ERROR executing server API call of:" + t );
249252 t .printStackTrace ();
250- username = null ;
251- password = null ;
253+ propUsername = null ;
254+ propPassword = null ;
252255 }
253256 }else {
254- username = Sage .get (PROP_USERNAME , null );
255- password = Sage .get (PROP_PASSWORD , null );
257+ propUsername = Sage .get (PROP_USERNAME , null );
258+ propPassword = Sage .get (PROP_PASSWORD , null );
256259 }
257260
258261 //if (Sage.DBG) System.out.println("***EPG*** checking for user/pass: username:" + username + " password:" + password);
259262
260- if ( username == null || password == null ){ //get from old sdauth file then store in properties for future use
261- //if (Sage.DBG) System.out.println("***EPG*** reading user/pass from old file");
262- File authFile = new File (AUTH_FILE );
263- if (!authFile .exists () || authFile .length () == 0 )
264- throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
263+ //get user/pass from old sdauth file
264+ //if (Sage.DBG) System.out.println("***EPG*** reading user/pass from old file");
265+ File authFile = new File (AUTH_FILE );
266+ if (!authFile .exists () || authFile .length () == 0 )
267+ throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
265268
266- try
267- {
268- reader = new BufferedReader (new FileReader (authFile ));
269- String auth = reader .readLine ();
270- if (auth == null )
271- {
272- if (Sage .DBG ) System .out .println ("SDEPG Error: sdauth file is empty." );
273- throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
274- }
275- int split = auth .indexOf (' ' );
276- // If the file is not formatted correctly, it's as good as not existing.
277- if (split == -1 )
278- {
279- if (Sage .DBG ) System .out .println ("SDEPG Error: sdauth file is missing a space between the username and password." );
280- throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
281- }
269+ try
270+ {
271+ reader = new BufferedReader (new FileReader (authFile ));
272+ String auth = reader .readLine ();
273+ if (auth == null )
274+ {
275+ if (Sage .DBG ) System .out .println ("SDEPG Error: sdauth file is empty." );
276+ throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
277+ }
278+ int split = auth .indexOf (' ' );
279+ // If the file is not formatted correctly, it's as good as not existing.
280+ if (split == -1 )
281+ {
282+ if (Sage .DBG ) System .out .println ("SDEPG Error: sdauth file is missing a space between the username and password." );
283+ throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
284+ }
282285
283- username = auth .substring (0 , split );
284- password = auth .substring (split + 1 );
285-
286- //store these values in properties to use next time
287- //if (Sage.DBG) System.out.println("***EPG*** saving to properties user/pass: username:" + username + " password:" + password);
288- Sage .put (PROP_USERNAME , username );
289- Sage .put (PROP_PASSWORD , password );
286+ fileUsername = auth .substring (0 , split );
287+ filePassword = auth .substring (split + 1 );
290288
291- }
292- catch (FileNotFoundException e )
289+ }
290+ catch (FileNotFoundException e )
291+ {
292+ throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
293+ }
294+ finally
295+ {
296+ if (reader != null )
297+ {
298+ try
293299 {
294- throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
300+ reader .close ();
301+ } catch (Exception e ) {}
302+ }
303+ }
304+
305+ boolean authenticated = false ;
306+ if (propUsername !=null && propPassword !=null ){
307+ //try the prop based user/pass
308+ try {
309+ // This will throw an exception if there are any issues connecting.
310+ returnValue = new SDSageSession (propUsername , propPassword );
311+ authenticated = true ;
312+ if (Sage .DBG ) System .out .println ("***EPG*** checking for prop based user/pass PASSED: username:" + propUsername + " password:" + propPassword );
313+ } catch (Exception e ) {
314+ if (Sage .DBG ) System .out .println ("***EPG*** checking for prop based user/pass FAILED: username:" + propUsername + " password:" + propPassword );
295315 }
296- finally
297- {
298- if (reader != null )
299- {
300- try
301- {
302- reader .close ();
303- } catch (Exception e ) {}
304- }
316+ }
317+
318+ if (!authenticated && fileUsername !=null && filePassword !=null ){
319+ //try the file based user/pass
320+ try {
321+ // This will throw an exception if there are any issues connecting.
322+ returnValue = new SDSageSession (fileUsername , filePassword );
323+ authenticated = true ;
324+ Sage .put (PROP_USERNAME , fileUsername );
325+ Sage .put (PROP_PASSWORD , filePassword );
326+ if (Sage .DBG ) System .out .println ("***EPG*** checking for file based user/pass PASSED: username:" + fileUsername + " password:" + filePassword );
327+ } catch (Exception e ) {
328+ if (Sage .DBG ) System .out .println ("***EPG*** checking for file based user/pass FAILED: username:" + fileUsername + " password:" + filePassword );
305329 }
306330 }
307331
308- try {
309- // This will throw an exception if there are any issues connecting.
310- returnValue = new SDSageSession (username , password );
311- } catch (Exception e ) {
332+ //we have now have tried both prop and file based user/pass
333+ if (!authenticated ){
334+ if (Sage .DBG ) System .out .println ("***EPG*** checking for BOTH user/pass FAILED: throwing SAGETV_NO_PASSWORD" );
312335 throw new SDException (SDErrors .SAGETV_NO_PASSWORD );
313336 }
314337
315-
316338 // We have just successfully authenticated, so this needs to be cleared so that updates can
317339 // start immediately.
318340 SDRipper .retryWait = 0 ;
0 commit comments