You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by missingfaktor <ra...@gmail.com> on 2012/02/29 10:02:02 UTC

Basic authentication with Camel Jetty

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>.

Re: Basic authentication with Camel Jetty

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

Take a look at the Test testAuthMethodPriorityBasicDigest [1] to see how to
reference the org.mortbay.jetty.Handler instances using the handlers option
through the Registery.

[1]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java

Babak


--
View this message in context: http://camel.465427.n5.nabble.com/Basic-authentication-with-Camel-Jetty-tp5524429p5524577.html
Sent from the Camel - Users mailing list archive at Nabble.com.