Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] DefaultServlet with authentication

Greetings,

I believe the part that you added to webdefault.xml should instead be part of the WEB-INF/web.xml of your web application. If you are using Jetty embedded into your application, you should refer to the following code sample for information on how to programmatically configure authentication realm.

Thanks,
Michael

On Wed, Mar 23, 2011 at 5:57 AM, Axel Rose <axel.roeslein@xxxxxxxxxxxxxx> wrote:
Hello all,

could anybody help how to configure jetty 7.2 to use authentication when
serving some static content with the DefaultServlet?

The content is accessible but access restrictions don't seem to be used.


This is what I tried:

<Configure id="Server" class="org.eclipse.jetty.server.Server">

   <Set name="handler">
     <New id="Handlers"
class="org.eclipse.jetty.server.handler.HandlerCollection">
       <Set name="handlers">
         <Array type="org.eclipse.jetty.server.Handler">
           <Item>
             <New class="org.eclipse.jetty.servlet.ServletContextHandler">
               <Set name="contextPath">/content</Set>
               <Set name="resourceBase">/home/ar/content/</Set>
               <Call name="addServlet">
                 <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
                 <Arg>/</Arg>
               </Call>
             </New>
           </Item>
         </Array>
       </Set>
     </New>
 </Set>

 <Call name="addBean">
   <Arg>
     <New class="org.eclipse.jetty.security.HashLoginService">
       <Set name="name">UserDatabase</Set>
       <Set name="config"><Property name="jetty.home"
default="."/>/etc/realm.properties</Set>
       <Set name="refreshInterval">0</Set>
     </New>
   </Arg>
 </Call>

</Configure>

and within "etc/webdefault.xml" I added

<web-app>
 <servlet>
   <servlet-name>default</servlet-name>
   <servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
 </servlet>

 <servlet-mapping>
   <servlet-name>default</servlet-name>
   <url-pattern>/</url-pattern>
 </servlet-mapping>

 <security-constraint>
   <web-resource-collection>
     <url-pattern>/</url-pattern>
   </web-resource-collection>
   <auth-constraint>
     <role-name>admin</role-name>
     <role-name>user</role-name>
     <role-name>moderator</role-name>
   </auth-constraint>
 </security-constraint>

 <login-config>
   <auth-method>BASIC</auth-method>
   <realm-name>UserDatabase</realm-name>
 </login-config>


Thanks for any hints,
Axel.
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top