Tuesday, November 24, 2015

OpenAM 12 - New Forget Password Self-Service

Most of my customers build their own User Self-Service module. That includes Change Password and Forget Password. And most of the times, they interact with the backend data source (e.g OpenDJ or Active Directory) directly.




I seldom have to worry about enabling the Forget Password feature in OpenAM. Well, good time is up for me. :) I have a customer that wants to utilize the Forget Password in OpenAM 12. 

Well, so based on my past exploration with OpenAM Password Reset feature, our discussion revolved around Challenge Questions & Answers and how the flow will be. Note that this customer only wanted the new XUI. No way to use legacy UI as discovery and customization times have been invested into rebranding the XUI.

Today, I had a shock when I started to read more about the Forget Password feature in OpenAM 12. The more I read, the more confused I become. The documentation keeps talking about Resetting Forgotten Passwords (legacy). 

OpenAM can provide self-service password reset for forgotten passwords when end user pages are served by the classic UI. To enable self-service password reset, you must configure the password reset service itself, which consists mainly of setting up secret questions, and configuring an SMTP mail server to send reset passwords to the users of the service.

But Mr Customer wants nothing, but the new XUI.

Now, during XUI rebranding, I did come across the following scripts in one of the template files.



There is definitely something to configure via the OpenAM Administration console to make the Forget Password hyperlink appears in XUI.

So I searched around and reached Configuration > Global > User Self Service. There you are! The Forgot Password for Users is disabled by default.



So I went ahead to enable the feature. Another great feature out there is the Forgot Password Token LifeTime (seconds). This expires the hyperlink which is sent to users. (Will talk about this in a while ...)


Nice, the Forgot password hyperlink finally appears!



The next screen is what you'll see when the Forgot password hyperlink is clicked.



When a correct username (default is to match with UID) is entered, an email will be sent.


The user will receive an email like the following:


This is where the Forgot Password Token LifeTime (seconds) kicks in. I suppose the hyperlink in the email will expires in the configured time. (I'll need to fully test this function. Still at high-level investigation now)

Once the hyperlink is clicked, the user will be redirected to the Change forgotten password page.



Pretty cool right? Initially I thought Mr Customer would reject it because the long-discussed Challenge Questions & Answers feature is no longer available in the new XUI. But, to my surprise, he prefers this new feature, especially the Forgot Password Token LifeTime.

And what surprised me more?

This new feature is not mentioned at all in OpenAM documentation, not in stable release. And I just searched the draft documentation for OpenAM 13, it's not mentioned as well. Maybe it's hidden somewhere, but it's really not obvious to customers and integrators like us.


The documentation is not catching up with development? Super strange! 


.

Monday, November 23, 2015

SLF4J: Class path contains multiple SLF4J bindings

Prior to OpenAM 12, we used to have our own logging framework using SLF4J and LogBack, instead of default logging framework that comes default with OpenAM. 



In OpenAM 12, multiple SLF4J bindings errors are thrown if both logging framework co-exist.

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/opt/apache-tomcat-8.0.26/webapps/auth/WEB-INF/lib/openam-slf4j-12.0.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/opt/apache-tomcat-8.0.26/webapps/auth/WEB-INF/lib/logback-classic-1.1.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.forgerock.openam.slf4j.AMLoggerFactory]


Need to handle carefully.

.

Friday, November 20, 2015

OpenAM - Mobile Access

The common topic from customers these days is how to integrate their mobile applications with OpenAM.

I will usually use the material from Shoot Me a Token: OpenAM as an OAuth2 Provider. Victor wrote this quite some time ago when I attended the 1st Open Identity Summit in the US. But it's still relevant.


So, there are a few ways to integrate mobile applications with OpenAM - OAuth2, OpenID Connect or REST. All methods are language independent, which is good.



The most common integration will be OAuth2. With OAuth2 in mind, one has to differentiate that there are in fact 2 types of tokens - Access Token & Refresh Token. The lifetime of a refresh token is long. So, a refresh token is used to exchange for a new access token (which is short-lived). This is important concept. Otherwise, users will need to keep logging in.





A real life example would be your Facebook application on your mobile phone. Are you prompted to log in every day? I don't even recall when did I last logged in. Technically, it's the "refresh token exchanging for an access token" in play.


In order for OpenAM to behave like Facebook (ok, this is very layman), the OAuth2 Provider feature in OpenAM has to be enabled. Once enabled, OpenAM can now provide the same functionalities as Facebook. It is now able to issue access and refresh token to mobile applications. It is now OAuth2-aware.


Some customers will then want to know more about what's going on behind the scene. Well, Victor's slides have it all. I just need to highlight a bit to make it complete.


The very 1st time a user access a mobile application (OAUTH2 Demo), he will be prompted with a consent page.



OpenAM will display the same to user. Depending on which OpenAM version you are using, you might get this:



Yes, so UI customization is required. :)  Or if you might get this:




I have not tested the latest UI yet. (Currently on a OpenAM 12 project, OAuth2 is in next phase)


So, after user has given his consent (highlighted in RED), an attribute in the user's LDAP entry is updated to "remember" user has in fact given his consent. This will prevent the Consent Page to be displayed again.

Once that's done, the mobile application will request for an Access Token and this will be stored in the Key Chain on the handphone (highlighted in BLUE). At the same time, the Refresh Token is stored.




The next time the user fires up the mobile application, it will retrieve the Access Token. If it has not expired, it will be used to request token information from OpenAM.



If the Access Token is expired, then the Refresh Token will be used to exchange for a new Access Token. The new Access Token will be stored in the Key Chain.



The extreme case will be the Refresh Token has also expired. Then users will be forced to re-login again.




That explains why some sites have their Refresh Token set to be months or even year. Just long enough for you to change handphone. :)



Futher readings:

[Concept] Working with Mobile Devices & Applications

[Sample] OpenAM OAuth 2.0 iOS Sample App

* I have not tested the sample codes yet. No comment there.


.


Tuesday, November 17, 2015

Monday, November 16, 2015

ssoadm CLI - Directory Configuration Part II

So there is, in fact, a way to script the Directory Configuration as mentioned by Peter.



The easiest way is to export the configuration in XML format, then import again via the ssoadm CLI.

$ ./ssoadm get-svrcfg-xml -u amadmin -f .pwd.txt -s http://am0-test.XXXX.net:8080/auth


$ ./ssoadm set-svrcfg-xml -u amadmin -f .pwd.txt -s http://am0-test.XXXX.net:8080/auth -X /data/bin//am-config/dir-conf.xml




Do take note to:

1. only update the SMS Server Group.

2. encrypt password via ampassword CLI


.

Friday, November 13, 2015

ssoadm CLI - Directory Configuration

Using ssoadm CLI to list a server configuration, I found out that the Directory Configuration information is not returned.





If you reference the OpenAM documentation, you would also realize there is no property listed in Servers > Directory Configuration section.




1) Now, for best practice, we would definitely not want to use cn=Directory Manager to bind to OpenDJ. A better approach is to create a service account.  

2) In production, especially when a pair of external OpenDJ is deployed, we would want to add Server2 to point to the 2nd external OpenDJ.




For (1), this can be easily solved by:
a. Create the service account prior to installation & configuration of OpenAM
b. In the OpenAM configuration file,

DATA_STORE=dirServer
DIRECTORY_SSL=SIMPLE
:
DS_DIRMGRDN=cn=Directory Manager
DS_DIRMGRPASSWD=password

Change DS_DIRMGRDN and  DS_DIRMGRPASSWD to the service account.

For (2), I have no idea how to script this. For now, I would have to manually add in via OpenAM Administration console.

Technically, I know this Directory Configuration is stored as XML in one of the LDAP attributes. Is this the challenge in not able to add/retrieve the information? I do not know.


Less than ideal.

.

Saturday, October 24, 2015

OpenAM : How to exchange for a long-lived access token from Facebook?

I have a customer who has a big data marketing engine running and they request for more information from Facebook to gather insights into their customers.




By default, when a user authenticates with Facebook via OpenAM Login Page, only a short-lived access token is captured.

There are 2 issues:

  1. The marketing engine will only run nightly/weekly. The short-lived access token would have expired then.
  2. The access token, even if it has not expired, is not persisted. Thus the marketing engine has no means to pick it up.


I did some research and this is what is required to exchange a short-lived access token with a long-lived access token.



You must exchange this short lived token with a long lived token by invoking a GET request to the following URL: 

https://graph.facebook.com/v2.0/oauth/access_token?grant_type=fb_exchange_token&client_id=[APP_ID]&client_secret=[APP_SECRET]&fb_exchange_token=[SHORT_LIVED_TOKEN] 

Where: 
APP_ID is your application id. 
APP_SECRET is your application secret. 
SHORT_LIVED_TOKEN is the short lived user access token received in the previous step. 

What comes back: 
The JSON response will contain the long lived access token.



To achieve customer's requirement, we can write some custom codes in Post-Authentication Processing module.

    @Override
    public void onLoginSuccess( Map requestParamsMap, HttpServletRequest request,
        HttpServletResponse response, SSOToken ssoToken )
            throws AuthenticationException {

         if (authentication module is Facebook) {

              // THIS IS KEY! Without it, there is no way to exchange for a long-lived
              // access token
              // this is short-lived access token returned from Facebook at OAuth 
              // authentication module
              String accessToken = ssoToken.getProperty
                             (OAuthParam.SESSION_OAUTH_TOKEN);

              // clientId, clientSecret, tokenServiceUrl 
              // quick and dirty is to hardcode; 
              // otherwise, read OAuth.java, OAuthParam.java and OAuthConf.java
              String clientId = ...;
              String clientSecret = ...;
              String tokenServiceUrl = ...;

              // follow the URL format above (highlighted in blue)
              String url = getFormattedTokenServiceUrlForFBLongLivedToken
                        (accessToken, clientId, clientSecret, tokenServiceUrl);

              // make a GET call to Facebook to exchange for a long-lived access token
              // methods getContent() and getContentStreamByGET() available 
              // in OAuth.java (no need to reinvent wheel; modify a bit will do)
               String longLivedToken  =  getContent(url);

              // Need to strip: 
              //    e.g. access_token=[LONG-LIVED-ACCESS-TOKEN]&expires=5148647
              longLivedToken = longLivedToken.substring(13,longLivedToken.indexOf("&"));

              // Persist FB long-lived access token to user's LDAP entry
              updateFBLongLivedAccessToken (longLivedToken, ssoToken);

          }

    }


Nice!

Tuesday, October 20, 2015

OpenAM 12 - Social Authentication

In OpenAM 12,  one of the new features released was Social Authentication made-easy.

Social Authentication  
Log in to an OpenAM protected resource by using your existing social website credentials. OpenAM supports Facebook, Google, Microsoft, or any other OpenID Connect 1.0 compliant identity provider.


OpenAM administrator can easily configure Social Authentication via the Common Tasks tab.



And the respectively Social Login logos will auto-magically appear on the default OpenAM Login Page, without any customization. Wow!




Yes, it did wow-ed one of my customers when some pre-sales presented this feature during selling/POC.


Side note: You'll be quite amazed the decision makers here are easily wow-ed by UI experience, rather than comparing products technically. (Few years ago, I did mentioned about the hard selling of OpenIDM without a proper UI. These days, it's much easier to sell with the launch of UI in OpenIDM 3.x.)


Back to our original topic, what's the catch? 


Read again:

Social Authentication  
Log in to an OpenAM protected resource by using your existing social website credentials. OpenAM supports Facebook, Google, Microsoft, or any other OpenID Connect 1.0 compliant identity provider.





So during project implementation,  this particular customer wants to have LinkedIn "auto-magically" appear on the Login Page as this was what he requested then.

Technically, to configure via the "short-cut" in Common Tasks tab is impossible. That's what I have to admit to Mr Customer. This is because LinkedIn does not currently supports OpenID Connect.


There is, however, workaround which I have researched for him and made it work for him.





OpenAM is very flexible to tweak around. But of course, some investment in time are required.

.


Thursday, October 15, 2015

OpenAM XUI Policy Editor ... on Safari

I was developing a custom policy condition for a customer. In the process, I was constantly clearing/disabling browser cache and was playing with XUI Policy Editor a lot. 

I'm seldom on Safari even though I'm using a Mac. But because of my laziness to keep clearing cache, I used Safari in one of my testings. That's when I found something weird in Safari. 


The last line "policy.subjectType.Policy.title" in Subject Conditions is always showing in Safari.



The last line "policy.conditionTypes.Policy.title" in Environment Conditions is always showing in Safari.



Note: I only added a MySQL Query Filter Condition which works perfectly fine.

So I went ahead to install a default OpenAM without any customisation.  The same behaviour exists in Safari.

Kind of strange... maybe I'll spend some time searching OpenAM bugster to see if this issue has been raised before.

.



Tuesday, October 13, 2015

OpenAM XUI Policy Editor ... Inconsistent UI

Having played with XUI for the OpenAM Policy Editor for a while (coming to 2 months), I must say I do not yet have a positive experience with it.


For example, there is this piece of inconsistency in the OpenAM Policy Editor implementation.

To add a resource, it's fairly simple.


Step 1: Roll over the mouse on "Available patterns". A green arrow appears. Click on the arrow.


Step 2: On the right-hand side, a "+" appears. Click on it and it will add the pattern to the resource. Simple!


If you want to remove the pattern, a "X" is available to carry out the function. Intuitive. 



Now, the UI experience for Define Subject Conditions and Define Environment Conditions is not consistent with the previous experience.


For example, to add a subject type, one has to drag the grey bar to the green area. (I missed this totally when I first used this XUI policy editor)



Where is the "+" to add?



Now, to remove a subject condition, one has to click on the "rubbish bin" icon, instead of "X" which was used in Resources.



Both "rubbish bin" and "X" serve the same function perfectly. However, in a product (especially within the same Policy Editor), one would expect the UI experience to be consistent throughout.

Kind of weird to me.

If I were to implement such a UI, I would have failed my Human-Computer Interaction course badly many years back in the University. I had a strict lecturer then. :)


.

Tuesday, September 29, 2015

Configuration store servers are not listed in Directory Configuration

I was working on an Open Identity Stack (OpenAM, OpenDJ, OpenIDM) project and OpenAM 12.0.1 was installed.


When verifying my configuration, I hit into OPENAM-6499 - Configuration store servers are not listed in Directory Configuration.


So, this was caused by a recently introduced new feature - Object Deserialisation Class Whitelist. The workaround was mentioned in the bugster.

Workaround is to add the following to the openam.deserialisation.classes.whitelist
Configuration -> Servers and Sites -> Default Server Settings -> Security -> Object Deserialisation Class Whitelist
com.sun.identity.common.configuration.ServerConfigXML
com.sun.identity.common.configuration.ServerConfigXML$DirUserObject
com.sun.identity.common.configuration.ServerConfigXML$ServerGroup
com.sun.identity.common.configuration.ServerConfigXML$ServerObject

Now, customer wanted scripted installation and configuration, so I was using SSO Administration Tool as much as I could. So, I went ahead to add the 4 classes into the whitelist ... 1 at a time.




But as soon as I keyed in the 1st class and tried to navigate around OpenAM Console, I hit into Invalid URL error.




I fired up OpenDJ and realised the default list of classes that shipped with OpenAM 12.0.1 was gone. The ssoadm command override the old values! (Need to be careful next time)


Luckily I always have backups! So, the 4 classes had to be appended to the existing list of classes like the following.






But .... it became worse ... the whitelist is now empty!


 So I realized $ sign had to be "escaped" ... aka prefixed with a backward slash.




After this, the configuration store servers finally shown up!