Showing posts with label jboss fuse. Show all posts
Showing posts with label jboss fuse. Show all posts

Monday, January 18, 2016

Jboss Fuse / Apache Camel - How to enable ws-security? (3/250 - 2016)


Dependencies to be added in pom.xml
<dependency>
   <groupId>org.apache.wss4j</groupId>
   <artifactId>wss4j-bindings</artifactId>
   <version>2.0.3</version>
  </dependency>
  <dependency>
   <groupId>org.apache.wss4j</groupId>
   <artifactId>wss4j-policy</artifactId>
   <version>2.0.3</version>
  </dependency>
  <dependency>
   <groupId>org.apache.wss4j</groupId>
   <artifactId>wss4j-ws-security-common</artifactId>
   <version>2.0.3</version>
  </dependency>
  <dependency>
   <groupId>org.apache.wss4j</groupId>
   <artifactId>wss4j-ws-security-dom</artifactId>
   <version>2.0.3</version>
  </dependency>
  <dependency>
   <groupId>org.apache.wss4j</groupId>
   <artifactId>wss4j-ws-security-policy-stax</artifactId>
   <version>2.0.3</version>
  </dependency>
  <dependency>
   <groupId>org.apache.wss4j</groupId>
   <artifactId>wss4j-ws-security-stax</artifactId>
   <version>2.0.3</version>
  </dependency>


Features to be installed in Fuse:

features:install wss4j
features:install cxf-wssecurity


Update Bluerpint with the code place- 
  <http:conduit name="https://.*/.*">
  <http:tlsClientParameters disableCNCheck="true">
   <sec:trustManagers>
    <sec:keyStore type="JKS" file="etc/uatesb.jks" password="password" />
   </sec:trustManagers>
   <sec:keyManagers keyPassword="password">
    <sec:keyStore type="JKS" file="etc/uatesb.jks" password="password" />
   </sec:keyManagers>

   <sec:cipherSuitesFilter>
    <sec:include>.*_EXPORT_.*</sec:include>
    <sec:include>.*_EXPORT1024_.*</sec:include>
    <sec:include>.*_WITH_DES_.*</sec:include>
    <sec:include>.*_WITH_AES_.*</sec:include>
    <sec:include>.*_WITH_NULL_.*</sec:include>
    <sec:exclude>.*_DH_anon_.*</sec:exclude>
   </sec:cipherSuitesFilter>
  </http:tlsClientParameters>
  <http:client AutoRedirect="true" Connection="Keep-Alive" />
 </http:conduit>


Based on the requirement add Inbound / Outbound Interceptors within the consumer / producer endpoints.

<cxf:inInterceptors>
 <bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor">
  <property name="properties">
   <map>
    <entry key="passwordType" value="PasswordText" />
    <entry key="action" value="UsernameToken" />
    <entry key="passwordCallbackRef">
     <bean class="com.dummy.handler.PasswordCallback">
      <property name="passwordMap">
       <map>
        <entry key="${datapower.user.id}" value="${datapower.user.password}" />
        <entry key="${esb.user.id}" value="${esb.user.password}" />
       </map>
      </property>
     </bean>
    </entry>
   </map>
  </property>
 </bean>
</cxf:inInterceptors>



<cxf:outInterceptors>
 <bean class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
  <property name="properties">
   <map>
    <entry key="user" value="wesb" />
    <entry key="passwordCallbackRef">
    <bean id="passwordCallback" class="com.dummy.handler.PasswordCallback">
     <property name="passwordMap">
      <map>
       <entry key="${datapower.user.id}" value="${datapower.user.password}" />
       <entry key="${esb.user.id}" value="${esb.user.password}" />
      </map>
     </property>
    </bean>
    </entry>
    <entry key="action" value="UsernameToken Timestamp" />
    <entry key="passwordType" value="PasswordDigest" />
    <entry key="mustUnderstand" value="${secureEnable}" />
   </map>
  </property>
 </bean>
</cxf:outInterceptors>



The PasswordCallback Impl

public class PasswordCallback implements CallbackHandler {

 private static Logger logger = Logger.getLogger(PasswordCallback.class);
 private Map<String, String> passwordMap;

 public Map<String, String> getPasswordMap() {
  return passwordMap;
 }

 public void setPasswordMap(Map<String, String> passwordMap) {
  this.passwordMap = passwordMap;
 }

 public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
  WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
  if (pc.getIdentifier() != null && passwordMap != null) {
   if ("wesb".equals(pc.getIdentifier())) {
    try {
     pc.setPassword((DummyEncryptDecrypter.decrypt(passwordMap.get(pc.getIdentifier()))));
    } catch (DummyCipherException e) {

     e.printStackTrace();
     logger.error("Error in decrypt password for id " + pc.getIdentifier());
     throw new UnsupportedCallbackException(null, "Error in decrypt password for id " + pc.getIdentifier());
    }
   } else {
    pc.setPassword(passwordMap.get(pc.getIdentifier()));
   }
  }
 }
}



DummyEncryptDecrypter

public class DummyEncryptDecrypter {

 Cipher cipher;

 private final static String IV = "password12345678";
 private final static String AES_CBC = "AES/CBC/PKCS5Padding";
 
 private static Logger logger = Logger.getLogger(DummyEncryptDecrypter.class);
 
 static SecretKeySpec key = new SecretKeySpec(IV.getBytes(), "AES");

 /**
  * Decrypt
  * 
  * @param cipherText
  * @return
  * @throws DummyCipherException
  */
 public static  String decrypt(String cipherText) throws DummyCipherException  {
  if(cipherText==null){
   return "";
  }
  AlgorithmParameterSpec paramSpec = new IvParameterSpec(
    IV.getBytes());

  Cipher cipher = null;
  byte[] output = null;
  byte[] decrypted = null;
  try {
   cipher = Cipher.getInstance(AES_CBC);
   cipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
   output = new BASE64Decoder().decodeBuffer(cipherText);
   decrypted = cipher.doFinal(output);
  } catch (Exception e) {
   logger.error("Exception while decrypt ");

   throw new DummyCipherException(e.getMessage(), e);
  }
  String palintText = new String(decrypted);
  return palintText;
 }

 /**
  * Encrypt
  * 
  * @param painText
  * @return
  * @throws DummyCipherException
  */
 public static String encrypt(String painText) throws DummyCipherException {

  if(painText==null){
   return "";
  }
  AlgorithmParameterSpec paramSpec = new IvParameterSpec(
    IV.getBytes());

  Cipher cipher = null;
  byte[] ecrypted = null;
  String output = null;

  try {
   cipher = Cipher.getInstance(AES_CBC);
   cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
   ecrypted = cipher.doFinal(painText.getBytes());
   output = new BASE64Encoder().encode(ecrypted);
  } catch (Exception e) {
   logger.error("Exception while encrypting the string "+e.getMessage());
   throw new DummyCipherException(e.getMessage(), e);
  } 
  return output;

 }
 
 public static void main(String arg[]) throws DummyCipherException{
  String s = "xxxxxxxxxx";
  System.out.println(new DummyEncryptDecrypter().decrypt(s));
  System.out.println(new DummyEncryptDecrypter().encrypt("password"));
 }
}


DummyCipherException 
public class DummyCipherException extends Exception {

 private static final long serialVersionUID = 1L;
 public DummyCipherException(String message) {
  super(message);
 }
 public DummyCipherException(String message, Exception e) {
  super(message, e);
 }
}

Configuration File
datapower.user.password=xxxx
datapower.user.id=xxxx
keystore.password=xxxx
secureEnable=false
esb.user.id=xxxx
esb.user.password=xxxx


Tuesday, July 7, 2015

JBoss Fuse vs IBM ESB? (94/285 technotes for 2015)

Price:
  • IBM products has a license cost and a support cost.
  • JBoss does not have a License cost - but has a subscription cost. Red Hat JBoss Fuse subscription is over $823K less than IBM WebSphere Enterprise Service bus at list price—or just 7.3% of the IBM cost.
Interest Over Time: 
Click on the link to see how Google Trends shows the interest over the time between the two products and the latest Integration technology - Apache Camel (which is used in JBoss Fuse)

Websphere ESB vs (Jboss Fuse & Apache Camel) (live link)

Sample below - the blue line shows decrease in interest IBM WebSphere technologies



Support:
  • RedHat JBoss Fuse can be used in any customer locations. 
  • The same is applicable for IBM ESB (except IBM WESB - Registry Edition or Retail Edition)
Developer Tooling:
  • RedHat JBoss Developer Studio is used for all Middleware development. 
  • Similarly IBM Websphere Integration Developer used for all development purpose. IBM tooling is more matured - but Red Hat is catching up.
Development:
  • JBoss Fuse development is extremely flexible - developers can swtich between graphical and xml views. Developers can can write a Apache Camel entirely in Java. 
  • IBM does not encourage switching between gui mode and xml mode. 
Other Tools:
  • With Red Hat Subscription, developers can choose to explore all the RedHat JBoss Middleware platforms like RedHat JBoss Data Grid and BRMS etc. 
  • This is not possible with IBM.
Building Integration using patterns:
  • RedHat JBoss uses Apache Camel -  open source, out of the box, standards based integration patterns based out of the book -  Enterprise Integration Patterns by Gregor Hohpe and Bobby Woolf.
  • IBM WESB does not allow pattern based development
Server deployment footprint:
  • RedHat JBoss Fuse requires 100mb free disk space and 2GB RAM. This can be even tuned and optimize. 
  • IBM in geneal required 6GB RAM to run IBM WESB (including IBM Application Server).
Embedded Java Development:
  • Use the Camel core component of Red Hat JBoss Fuse to embed routes in Java applications. This kind of feature is not available in IBM ESB.
Reliable Messaging:
  • RedHat JBoss Fuse uses ActiveMQ - an open source software with a very small footprint. ActiveMQ. 
  • It has several other benefits over IBM Websphere JMS. Please see link below for more info.
Transport Bindings
  • RedHat JBoss Fuse supports all the different types of transport binding including HTTP, JMS, HTTPS, FTP. 
  • On top of that Camel provides 125 connectors to varied systems.
References:

What are the components of JBoss Fuse? (93/285 technotes for 2015)


JBoss Fuse architecture and components - 




















Apache Camel - is a
  • 1. Simple
  • 2. Modular
  • 3. Open Source
  • 4. Java Library
  1. Connecting various components together, provide transformation, implement routing and also include Business Logic. 
  2. This is a rule based routing and mediation engine using EIPs (Enterprise Integration Patterns).
  3. Embed in any JVM and use any dependency injection framework
  4. Embed your integration solution directly where you need to.
  5. It has 100's of components already
  6. Huge community
  7. Also provide Domain Specific Language - you can use Java / Scala / ... or XML to decribe your flows
  8. For XML there is support for visual tooling
Apache CXF -
Apache ActiveMQ is an
  • open source message broker written in Java together with a full
  • Java Message Service (JMS) client.
Apache Karaf is a
  • modern and 
  • polymorphic container. It’s a 
  • lightweight, 
  • powerful, and 
  • enterprise ready container powered by OSGi. 
  • You can deploy different kind of applications in Karaf, OSGi or non-OSGi.
Fuse Fabric is a
  • technology layer that allows a 
  • group of containers to form a cluster that 
  • shares a common set of configuration information and a 
  • common set of repositories from which to access run-time artifacts.









What is JBoss Fabric? (92/285 technotes for 2015)



Fuse Fabric is a runtime environment that leverages capabilities of Apache Karaf, the container underlying JBoss Fuse, to provide centralized configuration and provisioning capabilities. In brief, Fuse Fabric provides the ability to create container instances running locally or remotely, including on cloud environments like Amazon EC2 and Rackspace. You can then create and apply Profiles that define what OSGi bundles and associated configurations (name / value pairs) to apply to each managed container.


References:

https://github.com/FuseByExample/docs/blob/master/deploy-using-fabric/README.md