Eugene responded to my earlier post “An even more capable SafeHashMap”:http://blog.dhananjaynene.com/archives/20 with “It is safer not to invent safe hash map / Java”:http://www.jroller.com/eu/entry/not_invent_safe_hash_map. While he does make some valid points I did have issues with some others, the issues being Signature Instability, Compilation Troubles, Principle of Least Surprise and Style.
February, 2008
15
Feb 08
An even more capable SafeHashMap
Eric Redmond in his post “A Safe HashMap for Java”:http://www.coderoshi.com/2008/02/safe-hashmap-for-java.html describes a SafeHashMap
Here’s a suggestion to extend the capabilities of the same. Lets look at the code.
h3. Define an interface to create an instance.
First, I create a new interface (We’ll get to know why very soon).
public interface InstanceProvider{ public V createNew(K k); }
h3. The SafeMap class itself
Here’s the proposed class. The main distinction is that instead of caching an instance and using the clone method to clone, this implementation stores away a reference to the instance provider and triggers it when required.
public class SafeMapextends HashMap { // Here's where we cache away the provider private InstanceProvider provider; // Note that the provider is now // passed to all the constructors public SafeMap( int initialCapacity, float loadFactor, InstanceProvider provider) { super(initialCapacity,loadFactor); this.provider = provider; } public SafeMap( int initialCapacity, InstanceProvider provider) { this.provider = provider; } public SafeMap( InstanceProvider provider) { this.provider = provider; } public SafeMap( Map extends K, ? extends V> m, InstanceProvider provider) { super(m); this.provider = provider; } @Override @SuppressWarnings("unchecked") public V get(Object key) { V value = super.get(key); if (value == null) { // use the provider here value = provider.createNew( (K) key); } return value; } }
h3. Test Case demonstrating usage.
public class TestSafeMap
{
@Test
public void testGetObject()
{
// Am using an anonymous class here.
// If additional parameters are required
// to be passed to constructor, one could
// create an abstract class with the constructor
// and pass the necessary arguments
Map> myMap =
new SafeMap>(
new InstanceProvider>()
{
public List createNew(String string)
{
List list = new ArrayList();
list.add(string);
return list;
}
}
);
String key = "hello world";
assertEquals(
"List size should've been one",
1,
myMap.get(key).size());
assertEquals(
"The only element in the list should've been : " + key,
key,
myMap.get(key).get(0));
}
@Test
public void testArrayInstantiation()
{
Map myMap =
new SafeMap(
new InstanceProvider()
{
public String[] createNew(
String string)
{
return new String[] {string};
}
}
);
String key = "hello world";
assertEquals(
"List size should've been one",
1,
myMap.get(key).length);
assertEquals(
"The only element in the list should've been : " + key,
key,
myMap.get(key)[0]);
}
}
This way I get a finer level of control on the instantiation of the default instance. There are multiple reasons why one might want that such as :
* The default instance needs to be configured in some way depending upon the key value (shown in the example above)
* The default instance needs to be configured based on some constructor parameters passed to it. In this case create an abstract class which implements the interface, declare a constructor with the necessary arguments, use the abstract class during instantiation, and allow the createNew method to behave appropriately based on the values of the arguments.
* There are some situations such as where the type above is a String[] where the clone method does not work (as in the second test case above). Perhaps the code to conduct the cloning could be modified above to create an array, but I am not too sure (since I’ve often faced difficulties working with instantiation of array types when using generics).
5
Feb 08
OpenID for Intranets and Extranets
This post continues from “OpenID or OpenAvataar ? UserID or AvataarID ?”:http://blog.dhananjaynene.com/archives/14, and “Implications of OpenID on software design”:http://blog.dhananjaynene.com/archives/18 and specifically looks at how the OpenID specification could be used within corporate intranets and extranets.
h3. Why would a corporate even want to implement OpenID
The problem OpenID is attempting to solve is widely prevalent within corporates as well. There are multiple applications, databases, web sites etc. which seem to want to create their own userid / password combinations. There is an enormous amount of activity and effort that a corporate has to invest in identity management. Additionally there is today a compelling need to for a user to transparently navigate across a wide variety of corporate applications especially in situation where each application performs its identity management tasks independently. This is precisely one reason why identity management, and Single Sign On are terms which are in many cases far more important to a software designer within a corporate context than on the public internet.
h3. What is different about corporate environments
For starters, there is a much stronger need within corporate environments to be able to associate a person’s identity with the authentication mechanism (eg. OpenID). I argued earlier that OpenID should reflect avataars and not necessarily a specific person’s identity especially within the public internet’s context. However many social interactions on the internet are relatively casual in nature and in most cases are likely to be sufficiently non-risky at least when looked at strictly from a commercial transaction perspective. The internet is a very democratic environment where most people are treated as fairly equal to each other. Within a corporate environment however each person has varying roles and along with that comes a varying set of responsibilities. It is fairly unlikely that corporate environments would easily allow any arbitrary OpenIDs (such as one created by a employee from one of a plethora of Internet based OpenID providers or even by creating a self hosted provider on his desktop himself). Corporates will be compelled to define ACLs around various corporate resources and these will need to be based on user identities and *not* their avataars.
h3. How could a corporate implement OpenID ?
First there would need to be sufficient conviction that this indeed helps solve the problem more effectively than many other Identity Management solutions out there (Some of the competing strategies are based on LDAP and SAML). Assuming that one reaches that conclusion, the way forward would be to either identify specific public OpenID providers or more likely create an internal OpenID provider (which may in turn be a layer on top of the Directory Services). The URLs as registered / provided from this internal providers would serve as a mechanism for the user identity presentment and verification.
Would there be a conviction that OpenID would be able to provide better identity verification solutions than the other solutions out there ? I suspect not always. However it is more likely in scenarios such as follows :
(a) Its a highly decentralised and large corporate with independent identity management functions being carried out by a variety of sub units.
(b) There is a necessity to establish broader extranets and expose the corporate application to other partners or consume applications and services provided by various partners.
Even in both the above situation there are other identity management solutions that do exist. However I do believe that OpenID is better placed at being able to find its place in these situations given the _relative_ simplicity of implementing it and more importantly the notion of standardisation that it brings with it. Moreover in a heterogenous world especially with all the various partner organisations and the identities that these spawn (which could be maintained in fairly diverse ways using different technology platforms) also starting to play a role, there will be a necessity for identity management, presentment and verification solutions to start talking one lingua franca and OpenID just might be it. There are other claims to be already having the common language (eg. SAML, LDAP), but I suspect the advantage OpenID brings in terms of a standard, widely used specification and especially in terms of it riding primarily on HTTP(s) will help it hold its own in many situations. It is imjportant to note here that SAML perhaps provides a much more structured mechanism of data exchange and providing more sophisticated assertions about the user identity and it may be so that it is more appropriate in a given context. However I believe OpenID is likely to be used more often than SAML in most less intensive cases primarily because of its simplicity and given the presumption that OpenID is far far more likely to be successful in the internet than SAML.
However OpenID only solves a part of the problem – ie. identity of the users. Within extranets, sometimes its important to establish the identity of the partner organisations as well. OpenID is unlike to be able to solve the same by itself. However there are other initiatives such as “inames”:http://www.inames.net which are at least attempting to solve that piece of the puzzle though it would be important in such cases that the individual inames and OpenIDs be seamlessly integrated.
5
Feb 08
Implications of OpenID on software design
In my earlier post “OpenID or OpenAvataar ? UserID or AvataarID ?”:http://blog.dhananjaynene.com/archives/14 , I referred to the fact that a user may have multiple OpenIDs (my hypothesis being that these will reflect his various avataars). The question I attempt to answer here is how will usage of OpenID impact the design of the software itself.
h3. Case of a site with OpenID integration
Here’s where things get interesting. One of the sites I went to “dzone”:http://www.dzone.com which is supposed to be for developers. It supports OpenIDs, but when I try to go to the registration page, here’s what I get.

Notice that the site seems to be supporting an OpenID login (bottom right) but yet goes on to add the following : *”You will need to set your password using the one-time link you received in your email before you can login.”*. I could not find any way of using my openID without the site creating a new user id and a password for me that it would send me to my email address. (And this is a rather geeky set of sites which seems to implement a single user id across JavaLobby, EclipseZone, dzone and JavaBlackBelt.). Clearly this was not how I believe OpenIDs were intended to be used (remember they are supposed to reduce userids and passwords) since the site expects me to create one more userid and one more password.
I shall assume that these sites are in the middle of a incremental transformation towards an OpenID oriented site and hopefully at a future date, I can simply register myself using my OpenID without creating any new userid or password.
h3. Design considerations when using OpenID
I submit the following as requirements for any OpenID based account registration
* My OpenID should be my userID / accountID (i.e. I am my OpenID)
* I should not be required to provide any new userid / password
* I may be required to provide additional information required by the site which is not published within my OpenID
But wait a minute we just went past the hypothesis that multiple OpenIDs could map to one Identity (UserID?). If that has to hold true, I need a new user id to be created so that I could map multiple OpenIDs onto it. But that seems to only exacerbate the problem that OpenID originally tried to solve. ie. the runaway number of userids that I seem to be having. Clearly something does not line up well here.
The one reasonable way I can imagine this working out fine is if the site itself focuses on the Avataar / Persona / OpenID and not necessarily the user’s unique Identity. ie. The site just keeps track of Avataars and does not attempt to link it into one single user id, and does not create a password for the same. Now me as an independent professional in my individual capacity and myself as the agent of an organisation could log in into the site independently as different avataars, and the site could treat each of my avataars as simply equivalent to what would’ve otherwise been two different userids. Thus the site no longer needs to keep track of my userid or my unique identity. It simply keeps track of Avataars or Personas, and in general does not focus on specific person’s identity.
However there are some sites which require user identity specific information (e.g. Online Drivers License Renewal assuming thats allowed in your region). Clearly in such situations, additional attributes would need to get attached to the avataar which reflect the specific user identity (actually more likely – the OpenID would need to get attached to the specific user identity). Whether one should require a unique constraint around such additional attributes (eg. two avataars cannot have the same drivers license number) is probably an site / application specific decision.
It is also quite likely that I might want to change the OpenID I use for a particular avataar. So there probably needs to be an internal unique identifier for the avataar, with an ability to change the OpenID that is used to login as that avataar (similar to the ability to change the primary email address). This actually is something which the OpenID spec does not address, thus transferring the onus of maintenance of such a mapping between an OpenID and an application / site specific avataar id (which probably just would end up being an internally generated number). As an aside this is something “inames”:http://www.inames.net/business.html does tackle explicitly
bq. This means all global i-names have a corresponding global i-number that represents a permanent identity that will never be reassigned even if a global i-name expires or is sold.
h3. Do I need a password field / column ?
If you are supporting OpenID users only then you no longer need it. But if you are supporting both site specific userIDs and OpenIDs you will still need to conduct authentication for the site specific userIDs. If you are building in support for OpenID in an existing application, you will probably keep the encrypted password or the password hash in the password column for the site specific user ids.
If you are building a new application however, and you still want to support users who do not have an OpenID, consider building your own OpenID provider. Thus generate an OpenID for such users only when required. Have the User Account Maintenance capabilities simply depend upon an OpenID provider (one of which could be your own). Should you want to get started on using some open source OpenID providers here’s a list of “OpenID Open Source Libraries”:http://wiki.openid.net/Libraries .
h3. Summary
# Design for new user registrations using only their OpenIDs ie. no new externally known userid or password
# If migrating towards a OpenID based infrastructure, you will need both non OpenID and OpenID users to coexist.
# Map the OpenID onto an internally generated and externally invisible id.
# If you want to allow users to link up their multiple OpenIDs, build for associating each such OpenID with the same internal Id. In this case users can freely add / remove other OpenIDs, subject to the constraint that at least one OpenID always remains associated with the account.
# If you would like to deal only with the user avataars and offer separate view of your site to each of his avataars, the ability to link multiple OpenIDs together may not be required. However do allow the user to change his OpenID (since he may find a good reason to want to change his OpenID provider in the future).
# If you are interested in supporting only one id per person consider using a different externally known identifier that uniquely identifies the person (could be the social security number or driving license number or something else). That should be the internal handle to the user which is enforced as a unique identifier (you can still choose to have another internally generated id). You can now associate one or more OpenIDs with that user and allow any one of them to be used as the authentication mechanism.
# If you are building a new application ground up, consider designing your application to work with OpenIDs alone. To cater to users not having OpenIDs, build a separate small application to allow them to create and maintain their OpenIDs
5
Feb 08
OpenID or OpenAvataar ? UserID or AvataarID ?
h3. Introduction to OpenID
Lately with the prolific activity around “OpenID”:http://openid.net and especially with a biggies like “Yahoo”:http://openid.yahoo.com and “AOL”:http://dev.aol.com/topic/openid , I was getting curious about how this will influence identity management both on the public internet and corporate intranets. One of the nice starting points to understand OpenID is “OpenID » What is OpenID”:http://openid.net/what/ , and for developers is “OpenID » developers”:http://openid.net/developers/
h3. How many OpenIDs per person ?
The “OpenID » What is OpenID”:http://openid.net/what/ page says
bq. OpenID eliminates the need for multiple usernames across different websites, simplifying your online experience.
This is a wonderful thing to happen, since we have been sufficiently bothered with trying to keep track of a whole bunch of userids and the passwords. It further goes on to add
bq. For businesses, this means a lower cost of password and account management, while drawing new web traffic. OpenID lowers user frustration by letting users have control of their login.
There is some correlation that is now being drawn between an OpenID id and an “account”. However it is still not yet clear what the OpenID reflects. Further it goes on to add
bq. For geeks, OpenID is an open, decentralized, free framework for user-centric digital identity
Now I start wondering does my OpenID reflect my user-centric digital identity ? Turns out I can have as many OpenIDs as I want. So there seems to be a *many to one relationship* between *my OpenIDs* and *me*.
This then is further reinforced in one of the articles that are referred to from the developer page “A Recipe for OpenID-Enabling Your Site”:http://www.plaxo.com/api/openid_recipe . This page contains the following text :
bq. Here’s an overview of what you’re going to add to your site:
1. A new database table to map OpenIDs to your internal user IDs
* It’s a many-to-one relationship (each user can have multiple OpenIDs attached to their account, but a given OpenID can only be claimed by a single user)
The “OpenID specification”:http://openid.net/specs/openid-authentication-2_0.html of course provides the most appropriate and insightful definition of OpenID even though it kind of has us wondering – what is the ID in OpenID (and leaves us with the loosely comfortable with the thought that the ID is simply an ID in the web space and has nothing to do with User Identity).
bq. OpenID Authentication provides a way to prove that an end user controls an Identifier.
So it seems sufficiently clear that an OpenID is not meant to reflect my identity the way my Tax Identification Number or Social Security Number or Drivers License Number works (ie. exactly one valid identifier per person at any point in time).
It is now clear OpenID reflects what I own (to the exclusion of others) rather than who I am. My OpenID does is not a unique or exclusive reference to me or any of my identifying characteristics as much as it asserts the fact that I control the ID and therefore others don’t. But that still leaves me thinking even harder – how many OpenIDs do I really need ?
h3. Why would I want to have multiple OpenIDs.
Sure having multiple ids is nice since I now have multiple providers, I am not tied to any particular one, I can have redundant ids. etc. etc. The reasons are quite similar to why I might have different email ids. Turns out at least in my case the most dominant reason why I would want to have different open ids is the same why I would want to have different email ids : *I have different facets to my identity and I would like each to be reflected differently*. Thus I might want to have _one_ OpenID to reflect my persona as a professional consultant, _another_ to reflect me in my personal and individual capacity, and _yet_ another to reflect my persona within the context of a particular of a client / project / organisation. This way I could use my personal openID across all my social networking sites, my professional one across a smaller number of professionally focused sites, and probably my organisation specific ID being used for sites hosted by a particular organisation which really isn’t focused on my global identity but wants to create and independently manage a single ID within that organisation. The number of OpenIDs I would want to reasonably maintain is the number of personas or avataars I want to project on the web. Thus I probably need 3 *avataars* instead of 1 identity or the hundreds of site specific userid/password combinations I today have. Probably I can better understand the word OpenID if in my mind I was to call it *OpenAvataar*. _My Submission here is that each person may have multiple openIDs and we shall probably be using each one to reflect one avataar. This is likely to be the primary reason why each person may have multiple OpenIDs”._
h3. Summary
* An OpenID does *not* exclusively identify a particular user. It simply asserts that users control over the OpenID.
* A user may have multiple OpenIDs. My hypothesis is that each of these is likely to reflect one of his avataars

