Hi Elia,
Authentication on Embedded Jetty:
This example is setting up Basic Authentication on the context "/mywebapp"
*On your webapp's WEB-INF/web.xml:*
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>A Protected Page</web-resource-name>
<url-pattern>/*</url-pattern> <!-- u can include specific
files/urls individually.. eg. <url-pattern>/mywelcomepage.html</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>MyRealm</realm-name>
</login-config>
</web-app>
*Next on your webapp,*
WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/mywebapp");
webappcontext.setWar("./path/to/my/war/orExplodedwar");
HandlerCollection handlers= new HandlerCollection();
handlers.setHandlers(new Handler[]{webappcontext, new DefaultHandler()});
server.setHandler(handlers);
HashUserRealm myrealm = new
HashUserRealm("MyRealm","C:/jetty-6.0.1/etc/realm.properties"); //
org.mortbay.jetty.security.HashUserRealm
server.setUserRealms(new UserRealm[]{myrealm}); //
org.mortbay.jetty.security.UserRealm
server.start();
server.join();
*On JETTY_HOME/etc/realm.properties:*
You will see the format:
<username>:<password>,role ... notice the password has another ":" for
users "jetty", "admin" and "other". Its the hash of the actual password.
Since the roles we placed on <auth-constraint> are admin, user,
moderator,...
The user/pass with access are:
jetty/jetty
admin/admin
you can then append a new user/pass and role on realm.properties... for
example:
newUser: newPass,moderator
So when u test on http://localhost:4700/mywebapp
You will be prompted to supply the user/pass with a basic
authentication. Simply admin/admin, jetty/jetty or newUser/newPass will
get you authenticated.
Hope this helps,
David
Elia Morling wrote:
> I'm using Jetty and want to apply authentication to a context I've
> defined in Java.
> How do I add authentication without using congfig files? Documentation
> is very poor on this topic.
> Thx
> Elia
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> ------------------------------------------------------------------------
>
> _______________________________________________
> jetty-discuss mailing list
> jetty-discuss@...
> https://lists.sourceforge.net/lists/listinfo/jetty-discuss
>
----------
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
----------
_______________________________________________
jetty-discuss mailing list
jetty-discuss@...
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
[Non-text portions of this message have been removed]