{"record":{"id":"a991cdf8ff2d1481","repo":"pentaho/pentaho-kettle","slug":"unable-to-obtain-authentication-context-for-url","errorCode":null,"errorMessage":"Unable to obtain authentication context for URL: ","messagePattern":"Unable to obtain authentication context for URL: ","errorType":"exception","errorClass":"SessionAuthenticationException","httpStatus":null,"severity":"error","filePath":"plugins/pur/core/src/main/java/com/pentaho/di/purge/RepositoryCleanupUtil.java","lineNumber":373,"sourceCode":"  @VisibleForTesting\n  void authenticateLoginCredentials() throws Exception {\n    KettleClientEnvironment.init();\n\n    if ( client == null ) {\n      ClientConfig clientConfig = new ClientConfig();\n      clientConfig.property( ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE );\n      client = ClientBuilder.newClient( clientConfig );\n      \n      // Check if session-based authentication is enabled\n      final boolean useSessionAuth = AuthenticationContext.SESSION_AUTH_TOKEN.equals( password );\n\n      if ( useSessionAuth ) {\n        // Get authentication context using the factory pattern\n        AuthenticationContext authContext =\n          SpoonSessionManager.getInstance().getAuthenticationContext( url );\n\n        if ( authContext == null ) {\n          throw new SessionAuthenticationException(\n            \"Unable to obtain authentication context for URL: \" + url\n              + \". Verify the URL is valid and properly formatted.\" );\n        }\n\n        // Check if authenticated\n        if ( authContext.isAuthenticated() ) {\n          String jsessionId = authContext.getJSessionId();\n\n          // Register a ClientRequestFilter to add Cookie header to every request\n          final String finalJsessionId = jsessionId;\n          client.register( (jakarta.ws.rs.client.ClientRequestFilter) requestContext ->\n            requestContext.getHeaders().add( \"Cookie\", \"JSESSIONID=\" + finalJsessionId )\n          );\n        } else {\n          throw new SessionAuthenticationException( \"Session-based authentication is enabled but no valid session found. Please authenticate through browser first.\" );\n        }\n      } else {\n        // Use basic authentication with username/password","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/pur/core/src/main/java/com/pentaho/di/purge/RepositoryCleanupUtil.java#L355-L391","documentation":"RepositoryCleanupUtil.authenticateLoginCredentials(), when useSessionAuth is enabled, asks SpoonSessionManager.getInstance().getAuthenticationContext(url) for the current session's AuthenticationContext; if it returns null the method throws SessionAuthenticationException \"Unable to obtain authentication context for URL: ...\". It means the Spoon session holds no authentication context registered for that exact URL, so login credentials cannot be validated/used for the purge repository call.","triggerScenarios":"authenticateLoginCredentials() invoked with useSessionAuth=true and a URL for which getAuthenticationContext(url) returns null: never logged in from Spoon for that server, the URL string differs (scheme/host/port/trailing slash) from the one registered at login, or the session context expired/was cleared.","commonSituations":"Running a purge against a URL slightly different from the one used to log in (http vs https, hostname vs IP, port mismatch); attempting purge before logging into the repository through the Spoon UI; session invalidated after idle timeout; testing session auth in headless/scripted environments where no Spoon session exists.","solutions":["Log into the repository/server from the Spoon UI so an AuthenticationContext is registered, then retry the purge.","Make the URL string exactly match the one used at login (same scheme, host, port, path).","Switch to basic authentication (useSessionAuth=false) if a headless/scripted run has no Spoon session.","Re-authenticate if the session expired, and normalize/validate the URL before calling the method."],"exampleFix":"// before\nutil.authenticateLoginCredentials( \"http://localhost:8080/pentaho\" ); // registered as https://server:8443\n// after: reuse the exact registered URL\nString url = SpoonSessionManager.getInstance().getActiveRepositoryUrl();\nutil.authenticateLoginCredentials( url );","handlingStrategy":"validation","validationCode":"AuthenticationContext ctx = SpoonSessionManager.getInstance().getAuthenticationContext( url );\nif ( ctx == null || !ctx.isAuthenticated() ) { throw new IllegalStateException( \"Log into Spoon for URL before purging: \" + url ); }","typeGuard":null,"tryCatchPattern":"try { util.authenticateLoginCredentials( url ); } catch ( SessionAuthenticationException e ) { /* prompt re-login or fall back to basic auth */ }","preventionTips":["Use the exact URL string that was registered at login (scheme/host/port).","Log in via Spoon before scripted purge operations.","Fall back to basic auth for headless runs."],"tags":["authentication","session","http","purge"],"backgroundTag":"authentication-required","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}