sobota, 4 września 2010

JOSSO – Java Open Source Single Sign On solution

Single login and session on multiple services is something very useful and straightforward for the end user, but hard to develop and maintain from technical point of view. Especially when SSO solution is going to be implemented on the existing services with custom authentication and user management methods. Of course there are many API's especially on enterprise level which allows developer to move authentication logic to separate layer. For example JAAS in case of Java applications.

But when we have to deal with multiple platform on multiple servers some solution build on top of environment frameworks is required. JOSSO is most known open source solution for
In my example I will present example solution composed of central JOSSO server and two partner services one written in PHP and second one java Java legacy servlet and JSP application with authentication logic build in deployed on tomcat, and one modern java enterprise application.

Setting up JOSSO server
Setting a JOSSO server and easy and well described in this document , so I'll skip it.

Modern Java Applications (JAAS)
This is also good described on JOSSO home page in this document.

PHP
There is available PHP example in JOSSO source tree, but it little outdated and just not working. It is using NuSOAP PHP classes which was replaced long time ago with better SOAP classes build in PHP. So I build my custom classes that access JOSSO web services and allows PHP app to authenticate. I used standard soap library to utilize JOSSO web services (so soap library have to be available on PHP installation). I haven't used autoprepend clause because in my opinion service user rarely has access to php.ini. To use JOSSO with php you have to call ssoGetUser function on very beginning of every page which should be aware login status.


Java legacy code
During deployment of JOSSO I had a challenge to integrate JOSSO with Java Legacy servlets and JSP with existing sophisticated authentication infrastructure. Adding JAAS was not option because of system architecture. I also had to avoid adding to much new JAR's to project because of possibility of conflict with version. Thats the reason why I taken similar approach as in PHP version – just tie my application with JOSSO server with plain Web Services.
I used JAX-WS wizard build in NetBeans 6.7 to generate bindings with web services. You can take multiple approaches to integrate JOSSO library with your legacy JSP/servlet. You can create filter or event add user check at beginning of every JSP file.

Sources:
You can download source code of examples mentioned above here. For PHP files you have just to copy files to your PHP server and check if SOAP is supported on it. With Java situation is little more difficault – you have to generate WebServices JAX-WS. You can do it using wizard in NetBeans 6.5+ or SOAPUI.




License:
New BSD, please consult license.txt file

sobota, 14 sierpnia 2010

Flash Build 4.0.1 - problem with debugger

After updating Flash Builder from 4.0 to 4.0.1 my debugger suddenly stopped working. There was errors both in debugging air apps and flash apps.

Changing Air version in descriptor to 1.5.3 does not make any difference. Also removing Flash Builder workspace was not a solution.

After two days I finally foud way to fix this problem.
  1. Ensure that you have newest Flash Player with debugger installed in your browser (I am using Firefox)
  2. Set new Flex SDK 4.0.1 to default
  3. Create new Flash (not Air) project, in main MXML add one button with some trace(event) on click event
  4. Run your application in debug mode, running slider in Flash Builder will probally stop at 57% and you will not see any trace on button click
  5. Click right mouse button and select Debugger from popup menu
  6. Select IP address radio and enter "127.0.0.1"
  7. You should now see your trace message on mouse click
  8. Also AIR apps should now work with debugging

czwartek, 3 czerwca 2010

GPCAS update

I recently made some updates in GPCAS project . New example Britain and Arrows was added. Here you can enjoy its live demo and here source code is available.

niedziela, 18 kwietnia 2010

WebOrb Flex and unicode encoding

During work on my WebOrb - Flex project I run into problem with character encoding. I had MySQL database configured with unicode, properly configured connection

mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");

My data from flex was correctly stored in database, but when I was trying to read it back i was receiving malformed unicode string with all unicode characters presented as two ASCII chars.

The solution of this problem is removing utf8_encode function from begining of FlashBinaryWriter.php in weborb directory OR inserting application in all places where there is a possibility to receive unicode data (ie. database queries) utf8_decode

niedziela, 14 lutego 2010

Porting Java code to ActionScript

ActionScript 3 unlike earlier versions of ActionScript (JavaScript) is very similar in syntax to Java. Both languages are strongly type and object oriented. Unlike strange prototype notation in earlier ActionScript AS 3 code have normal class declaration with fields and methods.

Porting code from java:
1) Use automatic converter to change syntax (mainly moving variable type definition to beginning)
2) Check types used. Numerical libraries probally will only use classes from Java Collection Framework other libraries may contains IO classes. Make your custom ActionScript version of these classes
3) Convert JUnit tests into FlexUnit
4)Run tests

And voila, your library is ported. In reality it is not so easy and you will need a lot of time to tweak your ported library.

GPCAS 3 - ActionScript 3 geometrical library

Few months ago I has to project in Flex in which I had to manipulate geometrical data. In short words it was about merging and splitting geometrical areas. Splitting polygon with section line is rather simply alghoritm, merging is little bit taughet but it is possible to write it in few hours. But problems appears when you have to split and merge polygon with "holes"

What is hole?
For example - take a look on map of South Africa. You see country of Lesotho which is bordered from every side by South Africa. So there is polygon "South Africa" and polygon "Lesotho" inside. Algorithm thats correctly merge and split polygons with holes is not easy to implement.



After some quick research I discovered that are no good library in ActionScript to handle this issue. I found some open source libraries in C++ and Java but I was not convinced to move this code to server side. After all I decided to port one of best geometrical libraries GPCAS to ActionScript. Because it was easier I ported already existing java version of library. Finally feature rich GPC library is available nativele in ActionScript 3 as SWC library. Anyone who wants may use it in his product.

http://code.google.com/p/gpcas/