Exclude external JavaScript libraries from beeing validated in Eclipse 4

Due to an Eclipse Bug, JavaScript errors of external JavaScript libraries are marked as erroronous showing the red failure marker even if JavaScript errors are excluded from the contents Markers view, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=349020

Workaround as spooted in the bug history:

I have found that I can leave the JavaScript Validator enable and ignore specific files by adding a suitable exclusion pattern e.g. */jquery.js to the JavaScript/Include Path/Source/Excluded group (Project->Properties->JavaScript->Include Path->Source).

Original post: http://peter-on-java.blogspot.com/2014/04/exclude-external-javascript-libraries.html

Tags ide

Importing SSL Certificates to a Keystore with Java Keytool

Java Keytool is a key and certificate tool for managing cryptographic keys, X.509 certificate chains, and trusted certificates.

Keytool Functions

  • Administration of public/private key pairs and associated certificates.
  • Administration of secret keys used in symmetric encryption/decryption (e.g. DES)
  • Storing keys and certificates in a keystore

In this post, I focus on the last aspect.

SSL Basics

File types We distinguish between certificates and keystores:

  • Certificate: A digitally signed statement from one entity (person, company, etc.), saying that the public key (and some other information) of some other entity has a particular value. When data is digitally signed, the signature can be verified to check the data integrity and authenticity. Integrity means that the data has not been modified or tampered with, and authenticity means the data indeed comes from whoever claims to have created and signed it.
  • Keystore: Archive file (database) for storing many cryptography objects such as certificates as a single file.

Certificate encodings and extensions

  • .DER: Binary DER encoded certificates. Not routinely used by anything in common usage.
  • .PEM: ASCII (Base64) encoded DER certificates used for different types of X.509v3 files which contain data surrounded with -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----. PEM stands for Privacy-enhanced Electronic Mail.
  • .CRT: Used for certificates in DER or PEM format. Most common in *nix systems.
  • .CER: Alternate extension of .CRT. Microsoft convention.

Keystore formats and extensions

  • .JKS: Keystore in Java format, e.g. $JAVA_HOME/jre/lib/security/cacerts
  • .P12, .PKCS12, .PFX: PKCS12 certificate keystore file format. It is commonly used to bundle a private key with its X.509 certificate or to bundle all the members of a chain of trust.

Keytool Commands for Storing Keys and Certificates in a Keystore

Listing all imported certificates:

keytool -list -keystore keystore.jks -storepass ***

Importing a single certificate to a keystore:

keytool -importcert \
    -file mycert.pem \
    -destkeystore keystore.jks \
    -deststoretype jks \
    -deststorepass ***
    -alias myalias

Importing a PKCS12 keystore to a JKS keystore

This time we import not only a simple certificate but a whole keystore:

keytool -importkeystore \
    -srckeystore cert-and-key.p12 \
    -srcstoretype pkcs12 \
    -srcstorepass *** \
    -destkeystore keystore.jks \
    -deststoretype jks \
    -deststorepass *** \

If the destination keystore does not already exists it will be built. So the importing process becomes a format change process. If you do not enter the source or destination store passwords, you will be prompted for it. You may skip the type information if you are lazy and trust the keytool that it will recognize the correct type for you.

Importing a JKS keystore to a PKCS12 keystore

The same command as above but vice versa:

keytool -importkeystore \
    -srckeystore keystore.jks \
    -srcstoretype jks \
    -srcstorepass *** \
    -destkeystore cert-and-key.p12 \
    -deststoretype pkcs12 \
    -deststorepass *** \

Further Sources

Original post: http://peter-on-java.blogspot.com/2013/12/importing-ssl-certificates-to-keystore.html

Tags security

JBoss FUSE ESB / Apache ServiceMix Basic Authentication

Find below a guide to setup up Basic Authentication for a Restful service running in a JBoss FUSE ESB 6.0 / Apache ServiceMix OSGI runtime. The service itself is not special. The notable configuration is found in blueprint.xml and in pom.xml.

Important note: this setup only works for JBoss FUSE ESB 6.0 or newer but not for FUSE ESB 7.1.0 or older!

The Restful service implementation CustomerService.java:

 
package ch.keller.restws.server;

import java.util.Date;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;

import org.apache.cxf.jaxrs.ext.MessageContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Path("/customers")
public class CustomerService {
 
 private static final Logger LOG = LoggerFactory.getLogger(CustomerService.class);

 @Resource
 private MessageContext jaxrsContext;
 
 @GET
 @Path("/")
 public String listAll() {
  isUserInRole();
  return new Date()+": Yess!! "+jaxrsContext.getSecurityContext().getUserPrincipal();
 }

 private void isUserInRole() throws WebApplicationException {
  LOG.info("user = " + jaxrsContext.getSecurityContext().getUserPrincipal());
 }

}

The associated blueprint.xml configuration:

 
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
 xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs" 
 xmlns:jaas="http://karaf.apache.org/xmlns/jaas/v1.0.0"
 xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
 xsi:schemaLocation="
  http://www.osgi.org/xmlns/blueprint/v1.0.0 
    http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
  http://cxf.apache.org/blueprint/jaxrs 
    http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
  http://karaf.apache.org/xmlns/jaas/v1.0.0 
    http://karaf.apache.org/xmlns/jaas/v1.0.0
  http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0 
    http://aries.apache.org/schemas/blueprint-ext/blueprint-ext.xsd">
      
  <!-- Bean to allow the $[karaf.base] property to be correctly resolved -->
  <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
   
  <jaxrs:server id="customerService" address="/crm" >
    <jaxrs:serviceBeans>
      <ref component-id="customerSvc"/>
    </jaxrs:serviceBeans>
    <jaxrs:providers>
      <ref component-id="authenticationFilter"/>
    </jaxrs:providers>
  </jaxrs:server>
    
  <bean id="customerSvc" class="ch.keller.restws.server.CustomerService"/>
  <bean id="authenticationFilter" 
    class="org.apache.cxf.jaxrs.security.JAASAuthenticationFilter" >            
      <property name="contextName" value="karaf"/>
  </bean>
    
  <jaas:config name="karaf">
    <jaas:module flags="required"
      className="org.apache.karaf.jaas.modules.properties.PropertiesLoginModule">
        users = $[karaf.base]/etc/users.properties
    </jaas:module>
  </jaas:config><br /> 
    
  <!-- Don't forget to expose the BackingEngine as an OSGi service. -->
  <service interface="org.apache.karaf.jaas.modules.BackingEngineFactory">
    <bean class="org.apache.karaf.jaas.modules.properties.PropertiesBackingEngineFactory"/>
  </service>
</blueprint>

The format of the properties in users.properties is as follows, with each line defining a user, its password and associated roles:

 
user=password[,role][,role]...

And finally, the Maven pom.xml build script:

 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="
   http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
  <modelVersion>4.0.0</modelVersion>
  <groupId>ch.keller</groupId>
  <artifactId>restws</artifactId><br /> 
  <version>0.0.1-SNAPSHOT</version>
  <packaging>bundle</packaging><br />
  <properties>
    <cxf-version>2.6.8</cxf-version>
    <felix-version>2.3.5</felix-version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-bundle</artifactId>
      <scope>provided</scope>
      <version>${cxf-version}</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <version>${felix-version}</version>
        <configuration>
          <instructions>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Bundle-Description>${project.description}</Bundle-Description>
            <Import-Package>
                org.apache.karaf.jaas.config,
                org.apache.karaf.jaas.boot.principal,
                org.eclipse.jetty.plus.jaas,
                org.apache.karaf.jaas.boot,
                *
            </Import-Package>
            <Export-Package>ch.keller.restws.server</Export-Package>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Especially important is the import-package section that guarantees that no java.lang.ClassNotFoundException is thrown during runtime:

 
<Import-Package>
  org.apache.karaf.jaas.config,
  org.apache.karaf.jaas.boot.principal,
  org.eclipse.jetty.plus.jaas,
  org.apache.karaf.jaas.boot,
</Import-Package>

Original post: http://peter-on-java.blogspot.com/2013/06/fuse-esb-apache-servicemix-basic.html

Tags esb

Eclipse with Eclemma: java.lang.NoClassDefFoundError: oracle/security/pki/OracleWallet

Trying to determine the code coverage of my JUnit 4 tests with EclEmma an java.lang.NoClassDefFoundError was thrown. As we all love Java stack traces, here a short excerpt:

 
java.lang.NoClassDefFoundError: oracle/security/pki/OracleWallet
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:169)
 at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:57)
 at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
 at
 ...

What does my JUnit Test wants from the OracleWallet? The application uses JDBC for the access of the Oracle DB, but OracleWallet is never directly used in my application. Without Eclemma the tests are running successfully. Not nice.

This seems to be a known problem which is fixed in EclEmma 2.1.3, see http://sourceforge.net/p/eclemma/bugs/108/.

If you don't want (or are not allowed...) to update, then the workaround is to exclude oracle.* from the coverage agent in the Code Coverage preferences, see http://www.eclemma.org/userdoc/preferences.html.

Original post: http://peter-on-java.blogspot.com/2013/06/eclipse-with-eclemma.html

Tags ide