camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From missingfaktor <rahul.phulore....@gmail.com>
Subject Basic authentication with Camel Jetty
Date Wed, 29 Feb 2012 09:02:02 GMT
I want to implement basic authentication for Jetty server programmatically,
as shown here<http://docs.codehaus.org/display/JETTY/How+to+Configure+Security+with+Embedded+Jetty>.
For the sake of convenience, I am ^C-^V'ing that snippet here.

import org.mortbay.jetty.security.*;

Server server = new Server();

Connector connector = new SelectChannelConnector();
connector.setPort(8080);
server.setConnectors(new Connector[]{connector});

Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);;
constraint.setRoles(new String[]{"user","admin","moderator"});
constraint.setAuthenticate(true);

ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");

SecurityHandler sh = new SecurityHandler();
sh.setUserRealm(new
HashUserRealm("MyRealm",System.getProperty("jetty.home")+"/etc/realm.properties"));
sh.setConstraintMappings(new ConstraintMapping[]{cm});

WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/mywebapp");
webappcontext.setWar("./path/to/my/war/orExplodedwar");
webappcontext.addHandler(sh);

HandlerCollection handlers= new HandlerCollection();
handlers.setHandlers(new Handler[]{webappcontext, new DefaultHandler()});

server.setHandler(handlers);
server.start();
server.join();

Now the problem is that the above approach requires you to have a handle to
the server. However in my case, since I am using Camel, I do not have a
direct access to the server. This is how my pipeline is defined:

from("jetty:http://localhost:8080/documents_in?matchOnUriPrefix=true").
  process(new MyProcessor());

How do I adapt the linked authentication solution to my case? Or do I have
to follow some completely different method? (This
page<http://camel.apache.org/jetty.html> shows
how to do it with Spring XML, however we are not using Spring, so that's of
no use to us.)

Please note that I am both a Camel and Jetty novice. Any help will be
greatly appreciated.
-- 
Cheers,
missingfaktor <http://twitter.com/#!/missingfaktor>.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message