Jen-Ming Chung

Using Amazon S3 as a Private Maven Repository

This article is a quick tutorial to setup a private maven repository using Amazon S3 instead of Nexus or Artifactory.

First we need to create a S3 bucket used to store two types of maven artifacts: stores two types of artifacts: releases and snapshots.

repository.example.com/[snapshots, releases]

Integrating Apache Shiro With CAS Authentication via LDAP

In this post I want to share how to setup SSO with CAS and LDAP authentication, and then demonstrate how to integrate Apache Shiro with CAS in the web application.

An Example of An Individual LDAP Entry

The following entry which represented in LDIF would be used to login the CAS. In this case, the username will be the full email address (case-insensitive) and the password is the value of userPassword attribute.

dn: cn=John Doe,dc=example,dc=com
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: John Doe
sn: Doe
mail: john@example.com
userPassword:: e21kNX1HaDNKSEpCekpjYVNjZDN3eVVTOGNnPT0=

How to Customise the Jackson JSON ObjectMapper in Java EE Enterprise Application

Assume we have a naive User POJO class with a BSON Type ObjectId field, i.e., id.

1
2
3
4
5
6
7
8
public class User {
    private ObjectId id;
    private String username;
    private String password;
    private Date createdAt;

    public getters/setters;
    ...

We can expect the following outputs from our REST services which is not a String with 24 hex characters.

1
2
3
4
5
6
7
8
9
10
11
12
{
  "_id": {
    "new": false,
    "machine": 805608948,
    "timeSecond": 1403022678,
    "inc": -871980150,
    "time": 1403022678000
  },
  "username": "John Smith",
  "password": "am9obiBzbWl0aCBwYXNzd29yZA",
  "createdAt": 1403022678341
}

Convert ObjectId to String in MongoDB Asynchronous Java Driver

Here’s quick share of converting the ObjectId to String in MongoDB Asynchronous Java Driver:

1
2
3
4
5
6
7
Aggregate.Builder builder = new Aggregate.Builder();
...
Iterable<Document> docs = collection.aggregate(builder.build());
for (Document d : docs) {
    String objectIdString = ((ObjectIdElement)d.get("_id")).getId().toHexString();
    System.out.println(objectIdString);
}

Allanbank’s driver is a good alternative when 10gen driver does not provide a better way for constructing arbitrary Aggregation pipelines. Now the official MongoDB Java driver also provides a new helper method, DBCollection.aggregate() which can be used to create aggregation tasks since version 2.9.0.