How do I access username and password in a Camel processor when using Spring Security with Camel on EAP?

Solution Unverified - Updated -

Issue

  • I used a reference example camel-example-spring-security listed in: http://camel.apache.org/spring-security-example.html
  • Now I am wondering how I pass username and password in my client code so that my Camel processor can access it:
  • In code below, however, username, password are coming as null:
String username = exchange.getIn().getHeader("username", String.class);
String password = exchange.getIn().getHeader("password", String.class);

Authentication authToken = new UsernamePasswordAuthenticationToken(username, password);
SecurityContextHolder.getContext().setAuthentication(authToken);
  • When I call setAuthentication() method everything seems to be working except I just need a way to collect username and password from Exchanges's header.
  • If I do not call setAuthentication(), I get an error org.apache.camel.Camel.AuthorizationException: Cannot find the Authentication instance. I believe the cause is, it cannot find Exchange.AUTHENTICATION in the message header.
  • How can I access username and password from the message header?

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
  • Red Hat JBoss Fuse Service Works (FSW)
    • 6.x
  • Red Hat JBoss Fuse (Fuse)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content