Red Hat
Sep 16, 2013
by Ray Tsang

Social Portal

JBoss Portal Platform 6.1 was designed with social media integration in mind to tailor use cases that are relevant in today’s web-based applications.  For example, when configured, JBoss Portal Platform can let new users to sign up and register by using Facebook, Twitter, or Google+.

Register with Social Media Account

New JBoss Portal Platform 6.1 users can register a new account using Facebook, Twitter, or Google+.

Once signed up, JBoss Portal will automatically pre-populate user information that was retrieved from the corresponding Social Media account, as authorized by the user.

Subsequently, users can sign in directly using the Social Media Account.

Registration with Social Media account.

User can register and sign-in with social media account.

Once signed in, the user can also decide to link or unlink existing Social Media accounts with JBoss Portal Platform!  For example, if the a user is currently registered with a Facebook account, and later started using Twitter, the user can link Twitter to the existing Portal user.

Similarly, if a user no longer wishes to stay connected/linked with one of the Social Media providers, the user can disconnect/unlink the account.

Link and Unlink

Registered user can link and unlink their Social Media accounts.

Last, if not least, once a user is connected to a Social Media account, and provided proper authorizations, your JBoss Portal Platform can then provide additional personalized services and/or provide tighter integration with social media.

Some of the popular use cases can be:

  • Activity Stream / Status update from user actions in the Portal
  • Retrieve user profile to provide customized experiences
  • Invite user’s friends to join your Portal website

Enabling Social Media Integration

Enabling Social Media integration in JBoss Portal Platform 6.1 is easy.  But first, you’ll need to get additional information from the Social Media provider, such as a Client ID and a Client Secret.  These two values will identify your portal application with the corresponding Social Media provider.  For more information about obtaining Client ID and Client Secret, please refer to Facebook, Twitter, and/or Google+’s Developer oriented websites.

Once Client ID and Client Secrets are obtained, you can enable corresponding Social Media integration within Portal.

The configuration file is located in:


Towards the end of this file, you’ll find a number of sections in the form of:


The most important configurations are: enabled, clientId, clientSecret, and scope.

First of all, set enabled to true:


Secondly, configure the clientId, and clientSecret:


Last, if not least, configure scope.  Scope is especially important – this literally specifies how much authorization would you like to request with the Social Media provider.  The available scopes also differs per provider.  So for example, if you are configuring Facebook integration, and would like to access user’s email address, friend list, as well as posting status updates on the user’s behave, then you may want to configure the scope as following:


Under the Hood – OAuth and Token

Under the hood, JBoss Portal Platform uses standard OAuth mechanism to interact with Social Media providers to authenticate the user, and obtaining proper authorizations to retrieve user information or trigger an action on the user’s behave.

JBoss Portal Platform does not include client libraries to interact with the Social Media providers, as each provider has different APIs, and thus, different client libraries can be used in your Portal application.

The important thing, though, is to be able to retrieve the access token – and you can do this via JBoss Portal Platform’s OAuthProvider API.

First, use Portal’s Public API to get an instance of OAuthProvider:

OAuthProvider googleProvider = PortalRequest.getInstance().getPortal().getOAuthProvider(OAuthProvider.GOOGLE);
if (googleProvider == null) {
    // Google+ integration was not enabled in

From the OAuthProvider, you can then get the AccessToken:

AccessToken accessToken = googleProvider.loadAccessToken(renderReq.getRemoteUser());
if (accessToken == null) {
    // User has not linked with a Google+ account

From the AccessToken, you will be able to check whether certain authorzation/scope has already been obtained – if not, you can initiate process to do obtain the authorization.

String availableScopes = accessToken.getAvailableScopes();
if (!availableScopes.contains("someScope")) {
  // User has linked with Google+ account
  // but we don't have proper scope/authorization
  // we can kick start the scope authorization by calling startOAuthWorkFlow

If you know you have authorization to the scope,  you can then obtain a reference of a client API object – or use any client API that simply requires a Access Token string.

Plus service = googleProvider.getAuthorizedSocialApiObject(accessToken, Plus.class);

OAuthProvider API gives you full access to how JBoss Portal manages the Access Token as well as verifying token availability, authorized scopes, etc.  In most portlets, it may be sufficient to use a re-usable Portlet Filter to check for scopes needed by the portlet, as well as displaying appropriate error messages and to request necessary scopes.

Detailed example of the Portlet Filter can be found in GitHub.

MDBlog Example

MDBlog (MarkDown Blog) portlet was developed to demonstrate some of the latest features of JBoss Portal Platform 6.1.  At a high-level, MDBlog is a portlet that allows user to create and edit Blog articles by using MarkDown template language.

Once a Blog is saved, it will use Portal’s Public API to determine Blog article’s URL.  It will also generate a short preview snippet that can be posted onto a user’s activity stream.  Finally, it’ll post to a Facebook user’s stream.  The core piece of code is located in SocialService Java class.

MDBlog Status Update

When saving an article, the portlet can publish the latest update to Facebook.

Let’s take a look in more detail.  First, use the new Navigation API to generate a  URL (We’ll look at Navigation API in-depth in future article):

String link = config.getBaseUrl() + portalRequest.getURIResolver().resolveURI(portalRequest.getSiteId()) +

Then generate a snippet of the Blog article to a maximum 200 characters:

String description = Jsoup.parse(processor.markdown(blog.getContent())).text();
 description = ellipsis(description, 200);

Finally, use FBClient to post it!

FacebookClient facebookClient = new DefaultFacebookClient(

FacebookType publishMessageResponse = facebookClient.publish(
    "me/feed", FacebookType.class,
    params.toArray(new Parameter[] {}));

Try it out!

Original Post