<p>I try to use the Forms-Based authentication within an embedded Jetty 6.1.7 project.</p>

<p>That's why I need to serve servlets and html (login.html) under the same context
to make authentication work. I don't want to secure the hole application since
different context should need different roles. The jetty javadoc states that a 
ContextHandlerCollection can handle different handlers for one context but I don't
get it to work. My sample ignoring the authentication stuff will not work, why?</p>

<pre><code>ContextHandlerCollection contexts = new ContextHandlerCollection();

// serve html       
Context ctxADocs= new Context(contexts,"/ctxA",Context.SESSIONS);
ctxADocs.setResourceBase("d:\\tmp\\ctxA");
ServletHolder ctxADocHolder= new ServletHolder();
ctxADocHolder.setInitParameter("dirAllowed", "false");    
ctxADocHolder.setServlet(new DefaultServlet());
ctxADocs.addServlet(ctxADocHolder, "/");   

// serve a sample servlet
Context ctxA = new Context(contexts,"/ctxA",Context.SESSIONS);  

ctxA.addServlet(new ServletHolder(new SessionDump()), "/sda");
ctxA.addServlet(new ServletHolder(new DefaultServlet()), "/");

contexts.setHandlers(new Handler[]{ctxA, ctxADocs});

// end of snippet
</code></pre>

<p>Any helpful thought is welcome!</p>

<p>Thanks.</p>

<p>Okami</p>

[{'answer_id': 91072, 'author': 'Eduard Wirch', 'author_id': 17428, 'author_profile': 'https://Stackoverflow.com/users/17428', 'pm_score': 1, 'selected': False, 'text': '<p>Use the web application descriptor:</p>\n\n<p>Paste this in to your web.xml:</p>\n\n<pre><code>&lt;login-config&gt;\n    &lt;auth-method&gt;BASIC&lt;/auth-method&gt;\n&lt;/login-config&gt;\n&lt;security-role&gt;\n    &lt;role-name&gt;MySiteRole&lt;/role-name&gt;\n&lt;/security-role&gt;\n\n&lt;security-constraint&gt;\n    &lt;display-name&gt;ProtectEverything&lt;/display-name&gt;\n    &lt;web-resource-collection&gt;\n        &lt;web-resource-name&gt;ProtectEverything&lt;/web-resource-name&gt;\n        &lt;url-pattern&gt;*.*&lt;/url-pattern&gt;\n        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;\n    &lt;/web-resource-collection&gt;\n    &lt;auth-constraint&gt;\n        &lt;role-name&gt;MySiteRole&lt;/role-name&gt;\n    &lt;/auth-constraint&gt;\n&lt;/security-constraint&gt;\n\n&lt;security-constraint&gt;\n    &lt;web-resource-collection&gt;\n        &lt;web-resource-name&gt;ExcludeLoginPage&lt;/web-resource-name&gt;\n        &lt;url-pattern&gt;/login.html&lt;/url-pattern&gt;\n    &lt;/web-resource-collection&gt;\n    &lt;user-data-constraint&gt;\n        &lt;transport-guarantee&gt;NONE&lt;/transport-guarantee&gt;\n    &lt;/user-data-constraint&gt;\n&lt;/security-constraint&gt;\n</code></pre>\n\n<p>Without authentication this will hide everything but the login.html.</p>\n'}, {'answer_id': 114336, 'author': 'Okami', 'author_id': 11450, 'author_profile': 'https://Stackoverflow.com/users/11450', 'pm_score': 2, 'selected': False, 'text': "<p>Finally I got it right, solution is to use latest jetty 6.1.12 rc2.\nI didn't check out what they changed - I'm just happy that it works now.</p>\n"}]
['https://Stackoverflow.com/questions/73029', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11450/']