Search the web
Sign In
New User? Sign Up
jetty-discuss · Jetty Discussion
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Click here for the latest updates on Groups Message search

Messages

  Messages Help
Advanced
Jetty Context Authentication Without Config Files   Topic List   < Prev Topic  |  Next Topic >
Reply  |  Next Message > 
Re: [jetty-discuss] Jetty Context Authentication Without Config Files

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]




Fri Oct 27, 2006 3:38 am

jetty-discuss@...
Send Email Send Email

 |  Next Message > 
Expand Messages Author Sort by Date

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...
Elia Morling
jetty-discuss@...
Send Email
Oct 15, 2006
3:21 am

Elia, The approach is: add a SecurityHandler to the context add SecurityConstraints to the SecurityHandler add an Authenticator cheers ... -- Greg...
Greg Wilkins
jetty-discuss@...
Send Email
Oct 17, 2006
4:52 am

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:* ...
David Yu
jetty-discuss@...
Send Email
Oct 27, 2006
3:45 am
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help