### Route Policy

Camel supports the notion of http://camel.apache.org/routepolicy.html[RoutePolicies,window=_blank], which can be used to integrate with the {wildfly} security system. There are currently two supported scenarios for security integration.

#### Camel calls into JavaEE

When a camel route calls into a secured JavaEE component, it acts as a client and must provide appropriate credentials associated with the call.

You can decorate the route with a `ClientAuthorizationPolicy` as follows:

[source,java,options="nowrap"]
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
        from("direct:start")
        .policy(new ClientAuthorizationPolicy())
        .to("ejb:java:module/AnnotatedSLSB?method=doSelected");
    }
});

This does not do any authentication and authorization, as a part of the camel message processing. Instead, it associates the credentials that come with the Camel Exchange with the call into the EJB3 layer.

The client that calls the message consumer must provide appropriate credentials in the AUTHENTICATION header like this:

[source,java,options="nowrap"]
ProducerTemplate producer = camelctx.createProducerTemplate();
Subject subject = new Subject();
subject.getPrincipals().add(new DomainPrincipal(domain));
subject.getPrincipals().add(new EncodedUsernamePasswordPrincipal(username, password));
producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);

Authentication and authorization will happen in the JavaEE layer.

#### Securing a Camel Route

In order to secure a Camel Route, you can associate a `DomainAuthorizationPolicy` with the route. This policy requires a successful authentication against the given security domain and authorization for "Role2".


[source,java,options="nowrap"]
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
        from("direct:start")
        .policy(new DomainAuthorizationPolicy().roles("Role2"))
        .transform(body().prepend("Hello "));
    }
});
camelctx.start();

Again, the client that calls the message consumer must provide appropriate credentials in the AUTHENTICATION header like this:

[source,java,options="nowrap"]
ProducerTemplate producer = camelctx.createProducerTemplate();
Subject subject = new Subject();
subject.getPrincipals().add(new DomainPrincipal(domain));
subject.getPrincipals().add(new EncodedUsernamePasswordPrincipal(username, password));
producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
