restx/restx — pull request #112 by ggtools (2014-06-14 14:54:15+00:00)
Title: Improved JongoRepository to support either string of id as credential keys

## Hopefully something that will work in every cases.

There are currently 2 user reference strategies

1. `RefUserByNameStrategy` should use when the users' `_id` field is actually the user name. In this case the user credential `_id` must be a plain string to match the user reference which is the user name.
2. `RefUserByKeyStrategy` should be use when the users' `_id` field is an `ObjectId` which is distinct from the user name. In this case, the user credentials `_id` must be store in Mongo as an `ObjectId` even if user credential objet uses a `String`.

The first case is working fine while the second one is not working as creating new user credentials lead to a Mongo error: *The _id field cannot be changed from {_id: ObjectId('5167cec5856107c479739656')} to {_id: \"5167cec5856107c479739656\"}.*

This is caused by Mongo which consider the insertion to be an update. Adding a `@ObjectId` in `UserCredentials` solves the issue for case 2 but breaks case 1.

### My brand new solution

We have two cases requiring different Java objects so I created a credential class for each case: `UserCredentialsByName` and `UserCredentialsByKey`. In order for `JongoUserRepository` to cope with both classes I extended `UserReferenceStrategy` to supply the concrete class and to create the user credentials. I also changed UserCredentials to be an interface since I have the impression that this is an internish class but it could easily be refactor not to change `UserCredentials`.