Skip to content

Commit

Permalink
KNOX-1645 - Improve JSESSIONID handling
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Risden <[email protected]>
  • Loading branch information
risdenk committed Nov 30, 2018
1 parent 191b914 commit d49cb66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.servlet.SessionCookieConfig;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import java.io.File;
Expand Down Expand Up @@ -118,6 +119,8 @@ public class GatewayServer {
private static final Auditor auditor = AuditServiceFactory.getAuditService().getAuditor(AuditConstants.DEFAULT_AUDITOR_NAME,
AuditConstants.KNOX_SERVICE_NAME, AuditConstants.KNOX_COMPONENT_NAME);

static final String KNOXSESSIONCOOKIENAME = "KNOXSESSIONID";

private static GatewayServer server;
private static GatewayServices services;

Expand Down Expand Up @@ -678,6 +681,8 @@ private WebAppContext createWebAppContext( Topology topology, File warFile, Stri
String contextPath;
contextPath = "/" + Urls.trimLeadingAndTrailingSlashJoin( config.getGatewayPath(), topoName, warPath );
context.setContextPath( contextPath );
SessionCookieConfig sessionCookieConfig = context.getServletContext().getSessionCookieConfig();
sessionCookieConfig.setName(KNOXSESSIONCOOKIENAME);
context.setWar( warFile.getAbsolutePath() );
context.setAttribute( GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, topoName );
context.setAttribute( "org.apache.knox.gateway.frontend.uri", getFrontendUri( context, config ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ public void testBasicJsonUseCase() throws IOException {
.statusCode( HttpStatus.SC_OK )
.contentType( "application/json" )
.body( "boolean", is( true ) )
.when().put( driver.getUrl( "WEBHDFS" ) + "/v1" + root + "/dir" ).getDetailedCookie( "JSESSIONID" );
.when().put( driver.getUrl( "WEBHDFS" ) + "/v1" + root + "/dir" )
.getDetailedCookie( GatewayServer.KNOXSESSIONCOOKIENAME);
assertThat( cookie.isSecured(), is( true ) );
assertThat( cookie.isHttpOnly(), is( true ) );
assertThat( cookie.getPath(), is( "/gateway/cluster" ) );
Expand Down

0 comments on commit d49cb66

Please sign in to comment.