<< Previous | Home

Minimal web.xml for authenticated webapp on WAS 8.5.5.x

I was doing a simple servlet based web application that should on WebSphere Application Server the other day. The servlet should require authentication. I really wanted to avoid using web.xml and go annotation based but it turned out that it wasn't possible - at least for me. Servlets are secured using the @ServletSecurity and you specify required role(s) and HTTP constraints e.g. is HTTPS required etc.

I added the following annotations:

@WebServlet(urlPatterns={"/"}, initParams={@WebInitParam(name="foo", value="bar")})
The "users" role turned up just fine in WAS ISC but I couldn't make the authentication kick in when I accessed the resources. Changing settings and values for the @ServletSecurity annotation e.g. explicitly mentioning GET didn't do anything for me. For some reason the annotation wasn't enough. To make the authentication kick in I had to add the following web.xml which is pretty much a standard web.xml you would do without annotations. You might be able to get away with a little less but at least I got it working... Oh well...
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="xmlns.jcp.org/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" 
  xsi:schemaLocation="xmlns.jcp.org/xml/ns/javaee xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd 
    http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
  id="WebApp_ID" version="3.1">
      <web-resource-name>Protected Area</web-resource-name>

Self-paced Docker

Nice videos with Self-Paced Training on Docker right from the source...

Fun demo of Watson IoT

Pretty cool demo of Watson IoT using your phone or other device. Access the page, scroll down about a page and try it out.

Explore IBM Watson Internet of Things

Git reflog to the rescue

Earlier today while slaving away on my code I did some wizard-like changes and solved an issue I had been having with packaging Visual Studio Tools for Office (VSTO) add-ins for Microsoft Outlook. It was soooo cool that I just had to record a video on it as it involved a number of steps and it would be easier to record a video than describing it in text. So I commited my changes and reverted to an easier commit without thinking. And boom!! All my changes was gone - including some stuff I actually needed. I shouldn't have reset to a commit but instead I should have created a new branch from an earlier commit. Stupid is as stupid does!

After making a loud noise I remembered that all was still safe as I'm using Git...

All changes in Git are recorded in the reflog so my work wasn't lost - I just needed to revert back to them which is easy using the reflog. Now I will not go into details on the reflog here but do look it up. All I needed was two simple commands:

  • git reflog (display the reflog and note the commit hash I wanted to go back to)
  • git reset --hard <commit hash>
Below is a more detailed example. The git reflog command shows the log of what has happened. The top entry is me screwing things up. The commit just under it (41a2195) is the working copy as it was and where I wanted to return before branching correctly. Doing the reset command specifying the hash returns me to it.

$ git reflog
afc548e HEAD@{0}: reset: moving to afc548e1029839175a7620b5c15c6a122a4db47c
41a2195 HEAD@{1}: commit (amend): Update to v. across the board to allow update
71ab438 HEAD@{2}: commit: Update to v. across the board to allow update
afc548e HEAD@{3}: rebase -i (finish): returning to refs/heads/master
$ git reset --hard 41a2195
$ git reflog
41a2195 HEAD@{0}: reset: moving to 41a2195
afc548e HEAD@{1}: reset: moving to afc548e1029839175a7620b5c15c6a122a4db47c
41a2195 HEAD@{2}: commit (amend): Update to v. across the board to allow update
71ab438 HEAD@{3}: commit: Update to v. across the board to allow update
afc548e HEAD@{4}: rebase -i (finish): returning to refs/heads/master
Again - as so many times before - thank you Linus :) And now - please go read up on the git reflog if this is news to you...

Tags : ,

Date and time in Java 8

IBM Connections application development state of the union - part 6

Part 5 was about extensions/apps on-premises and this - probably final post - will be about extensions for IBM Connections Cloud. There are different ways to extend IBM Connections Cloud - one is to add links to the app menu and another is to add actual UI extensions to the applications within IBM Connections. This post is about the latter (although the observations about the administration UI applies to both). To get it out of the way from the beginning I might as well say it flat out. IBM has really missed the mark here. The extensibility mechanism for IBM Connections in Cloud is close to unusable from my point of view. Let me explain...

Basically the extension mechanism for cloud is an iframe and you may only extend Communities which is so wrong to begin with. As mentioned previously IBM Connections is a piece of social software that focus on people and not being able to extend Profiles is baffling to me. Using a clumsy UI in the administration portal you can upload a JSON file describing the extension which in turn will make the extension show up in the main UI. The smallest file I could make work is 34 lines of JSON but basically I could do away with 3 lines. Almost all of the JSON I upload is simply cruft that seems to carry over from the on-premises widget container and as I really cannot change it why should I specify it? In essence I can only change the following 3 parameters:

  • defId - seems to be an ID of the widget
  • url - the URL to set into the iframe
  • height - the height of the iframe
Part of the JSON I upload is the widget ID. I have to specify the ID of the widget (defId) but there is no check whether it's used. Using an already used ID is allowed but only one of the widgets with the same ID shows up which is an issue as this is an obvious copy/paste error on the users part. Also the widget is added to the community page using the defId as the title but shown in the administration UI using a "name" parameter from JSON which is pretty confusing. Part of the JSON I upload is also the actual iWidget that creates and builds the iframe. I can specify my own iWidget description and the only thing that makes it not work is the ajaxProxy rejecting it making the UI fail when users load the community page. There is no upload time check. Often times an invalid JSON file only makes the UI do nothing - there is no response as to what might be wrong.


Once the JSON is uploaded I get an iframe of a static height with a URL set into it. The height is one thing that makes this extension mechanism hard to work with for production apps. Often times the height of the content cannot be decided at deployment time but is only known at runtime and unfortunately there is no way to change the iframe height at runtime. At least nothing which is obvious and/or documented. But now we have an iframe set the URL specified in the application JSON. The iframe is sandboxed with the following policy: "allow-same-origin allow-scripts allow-popups allow-forms". This restricts the extension and basically it may only do the following:

  • Run JavaScript
  • Make xhr requests to the server it was loaded from (same origin)
  • Open a new window/tab in the browser
There is no way for the widget to even talk to IBM Connections itself - not even the IBM Connections API. The widget may basically show static / server side generated HTML and run JavaScript. The JavaScript may make xhr requests to the server it was loaded from. That's it.

When the widget loads it may ask the surrounding page for a widget context by registering a message listener and posting a message to the parent page (parent.postMessage). The context looks like this:

   "source": {
      "resourceId": "ff7dd8b4-95d6-4fb4-f094-edb52e5d8eee",
      "resourceName": "Some Community Title",
      "resourceType": "community",
      "orgId": "12345678"
   "user": {
      "userId": "87654321",
      "orgId": "12345678",
      "displayName": "John Doe",
      "email": "jdoe@example.com"
   "extraContent": {
      "canContribute": "true",
      "canPersonalize": "true"
From the context the widget can figure out who the user is and what community the user is in. The problem is however that the user information is unusable as there is no way my application server can trust this user information. As the context is not verifiable in any way there is no way for my server to trust the information it receives from the extension. The only way to convey user identity to my server is by using SAML and assume that a SAML assertion dance is performed when the iframe contents is loaded so the user has a session cookie relationship with my server. But this is doable - I now know the user identity based on the SAML dance.

Next thing is to make sure the user is actually a member of the community he/she is sending to my server - but oh - there is no way to decide this. My server side code cannot make requests on behalf of the user back to IBM Connections without the user having already performed an OAuth dance and authorized my application to IBM Connections. I could tell the user that we might not have tokens for him/her but it yields a crappy user experience. Plus any authorization granted expires from time to time (at least every 90 days). Also there is no organization wide OAuth authorization capabilities in IBM Connections Cloud like is the case for Google or Microsoft plus there is no super-user for IBM Connections so we're pretty stuck here.

Now this is pretty bad and combining these things basically makes it impossible to create any kind of customer or ISV solution with a decent user experience. At least if the context is important and the contents is not static.

So what do we do about it? Well IMHO the solution is pretty easy and simple which makes it even worse that IBM decided to ship this capability. Let me suggest the following points:

  • Administration UI
    Fix the administration UI including the widget JSON I have to upload. Only ask for the stuff that actually matter and induce the rest if not specified. If the uploaded file doesn't validate tell me - maybe even provide a clue as to what's missing...
  • Make the context verifiable
    When I register a widget add an option to indicate that my server needs to verify the information in the context (the JSON blob above). If I check the box generate a set of asymmetric keys and provide me one of the keys. Now the JSON context could be signed with the IBM Connections part of the key making my server capable of verifying that the information indeed came from IBM Connections. And since it's asymmetric there is no way for my server to impersonate IBM Connections. Oh and this would make the information in the context trustable even if the customer is not using SAML.
  • Making calls back to IBM Connections possible
    When I register a widget add an option for me to indicate that my server needs to make calls back to IBM Connections on behalf of the user. For additional credits allow me to specify which parts of the IBM Connections API my server may use. In combination with the asymmetric key pair above this option would include an encrypted opaque token in the JSON context blob. This token could be used by my server to authenticate my server and the request back to IBM Connections. It could be a set of automatically generated OAuth tokens but doesn't need to be. This is a secure solution as we already have a key pair in place so the token could be encrypted using the IBM Connections part of the key pair so that the widget code in the browser cannot use it. Only the server with the matching key may decrypt the token and use it for the IBM Connections API.
Now I'm no security expert but this should be secure and pretty easy to implement. With a single sweep it would make widgets in IBM Connections Cloud way more powerful than widgets on-premises and would make them much easier to develop. Only thing left then is making it possible to adjust the height at runtime but I'll let that slip for now as a basic oversight in the design of the extensibility mechanism and assume this capability will be available soon anyway.

</rant >

I have a small IBM Connections Cloud community apo on Github if you would like to see a minimal example: IBM Connections Cloud Community App Example

IBM Connections application development state of the union - part 5

Part 1 was about API's and SPI's, part 2 about Mobile, part 3 about security and "coherent-ness". This part will be about apps/extensions this time moving to on-premises.

For on-premises the extension model for IBM Connections is iWidgets and OpenSocial gadgets. You can extend Profiles, Communities and Homepage. OpenSocial is only supported in Homepage. IMO the former two (Profiles and Communities) are probably the ones mostly extended using widgets. Unfortunately these also use the oldest extension mechanism but also the most capable one. I have presented numerous times on iWidgets (e.g. see Easy as Pie - Creating Widgets for IBM Connections).

In essence an iWidget consists of:

  • A widget descriptor - an XML document describing the widget and which is pointed to in the IBM Connections on-prem setup (widgets-config.xml). The widget descriptor may also contain static HTML for the widget e.g. a "Loading..." text.
  • A JavaScript "class" having methods for various parts of the widget lifecycle such as onLoad, onView, onEdit etc.
  • Zero or more resources loaded by the widget descriptor before control is passed to the JavaScript. This can be JavaScript files, CSS files etc.
Besides being the worstly formatted document I've even seen the iWidget specification is pretty easy to follow. The specification allows for pretty powerful extensions to IBM Connections but has major drawbacks the worst being:
  • Creating a simple dynamic widget is pretty involved failing the "fast HelloWorld test". Also something simple as setting a nice widget title takes i18n files and editing LotusConnections-config.xml as well.
  • IBM proprietary - at some point IBM Mashup Server used iWidgets as well but I think the product has been discontinued with IBM Connections being the only container using iWidgets now
  • No development environment available. Only way to develop is to either use a full IBM Connections instance with the caching-hell that ensues or write an iWidget wrapper/emulator. I prefer the latter and it's not hard but really shouldn't be necessary.
  • The widgets all run as part of the page so there is no containment from a CSS perspective (a "rouge" CSS class will mess up the entire page), from a JavaScript perspective (a "rouge" piece of JavaScript both stop the entire page from loading and/or read data from the entire page).
These are pretty bad but as a developer you can learn to live with them and work around them. The worst is the last item where a failing widget makes the entire page fail to load something that seems to even affect the IBM supplied widgets.

This being said you can develop almost anything using iWidgets. You may talk to any HTTP based API using XHR whether the same source as where the widget code was loaded from or not. Worst case is that you use the built-in AJAX proxy to tunnel requests that work to work around same-origin-policy issues or if the API supports CORS you can go nuts and load data to your heart's content. The only real issue is that to convey user identity from the IBM Connections WebSphere Application Server (WAS) to a proprietary - or non IBM server (without support for LtpaToken cookies) - is tricky. Developing a simply app deployed on WAS or Domino to created an encrypted assertion of the user identity is not hard but could - and should - be part of the platform and not something I as a developer should have to worry about. It's a situation that is pretty easy to imagine would happen and IBM should have addressed it.

All things considered the iWidgets approach is proven works for most ISV/product situations or customer engagements I've been involved in. I'm just happy we and/or no customer has asked us to extend areas other than Profiles and Communities yet...

IBM Connections application development state of the union - part 4

While previous posts in this series has been about specific parts of the IBM Connections platform this is a bit more generic setting the stage for the next two ports. The next two posts are about extensions/apps for IBM Connections on-premises and in the cloud. Setting the stage for this is talking about the difference scenarios for extensions and what they would like to to and what capabilities they would need from the platform (IBM Connections).

In my mind when you provide a platform that allows for extensions - such as the extensions/apps in IBM Connections - you really need to think about not just what you want and need to provide but also what the consumer would want to do with it. What is the usage scenario of the customer / ISV? What would they want / need to do? Is the user identity important? If the context (e.g. current profile / current community ID) important? Providing an extension mechanism that doesn't allow a customer or ISV to do what they would like is almost even worse than providing nothing at all. If nothing else it leads to more frustration anyway.

Looking at the various things a customer / ISV would want to do you can list them like below. Of course there might be a different number of areas of interest but these are at the core. I note observations for both on-premises and cloud.

  • Extend required areas e.g. Homepage, Profiles, Communities, Files etc.
    • On-premises: No. Or to some extent. You can extend Homepage, Profiles and Communities. It's pretty hard to control from a policy perspecitive but it's doable. There is no support for extending other features (besides the rich text editor) which is pretty bad if you provide a service for Files or Wikis.
    • Cloud: No. Extension only available for Communities. This is really bad for a piece of social software that focus on people...
  • Access to widget context
    • On-premises: Yes. iContext provide the community / profile ID of the active community or profile.
    • Cloud: Yes. Extension can receive a context object describing the active community.
  • Ability of called REST API to obtain user identity
    • On-premises: Yes. If using IBM server using LtpaToken otherwise you need to develop custom code.
    • Cloud: No. Not without additional technology. Context provides access to the user identity but it cannot be trusted as it's not signed or authenticated in any way. Using SAML is an option but is an add-on and require interaction with IBM Support.
  • Ability to communicate with custom API (anything other than IBM Connections)
    • On-premises: Yes. You may do anything but may need to use provided AJAX proxy
    • Cloud: No. May only communicate with the same origin as the widget was loaded from. Cannot even communicate with the IBM Connections API.
  • Ability to communicate with the IBM Connections API
    • On-premises: Yes. Possible as user is most likely already logged into IBM Connections. Most likely as Profiles doesn't require authentication by default. It is however possible to configure the widget to require the user to be authentication and hence not show up for unauthenticated users.
    • Cloud: No. Widget may only communicate with the same origin as the code was loaded from.
  • Ability of an API to communicate with the IBM Connections API on behalf of the user
    • On-premises: Yes. Possible if the API runs on an IBM based server supporting LtpaToken and the API runs on the same domain as IBM Connections as the API may grab the cookie and use it when calling back to IBM Connections. Not pretty but it works.
    • Cloud: No. The API a widget would call never runs on the same domain nor is there any traditional cookie based SSO available.

As is pretty clear from the above I'm not a great fan of the extensibility model of IBM Connections Cloud and it fails in almost all areas. It's severely and utterly broken from an ISV standpoint and fails on all accounts making it unusable IMHO. I go more into details about why not in a post specific to extensions for IBM Connections Cloud. The on-premises model is okay but is cumbersome to develop for and is outdated. Also it doesn't work for cloud making us having to develop the same functionality twice. The on-premises capabilities work however and mostly allows ISV's and customers to develop the extensions they need. Again there will be a separate posts on extensions for on-premises.