Peter Martin: June 2006 Archives

« May 2006 | Main | August 2006 »

June 30, 2006

Cairngorm 2 + XDoclet2

With the release of Cairngorm on Adobe Labs the package name has changed from org.nevis.cairngorm to com.adobe.cairngorm. I have updated the AS3 plugin for XDoclet2 to reflect the new package name so all generated VOs will now implement com.adobe.cairngorm.vo.ValueObject. You can also download the source from here.

For more information on XDoclet2 please see my earlier blogs:

Posted by at 2:41 PM | Comments (6)

Cairngorm 2 Security

It's great to finally see Cairgorm 2 on Adobe Labs. To mark the occassion I thought I would post some code I developed a while back to allow Cairngorm to use secured server-side destinations.

On the server you can configure security contraints in services-config.xml as per the following example , alternatively you can configure security constraints in-line with your destinations.

<security-constraint id="trusted">
   <auth-method>Custom</auth-method>
   <roles>
      <role>guests</role>
      <role>accountants</role>
      <role>employees</role>
      <role>managers</role>
   </roles>
</security-constraint>

You can then reference your security contraint in your destinations (data-management-config.xml, messaging-config.xml, proxy-config.xml and remoting-config.xml) as per the following example:

<destination id="loginService">
   <properties>
      <source>com.adobe.LoginService</source>
   </properties>
   <security>
      <security-constraint ref="trusted" />
   </security>
</destination>

The ZIP contains the following files:

  • DestinationLocator - subclasses Cairngorm ServiceLocator to support Messaging, Data Management Services and Web Services.
  • SecureDestinationLocator - sublcasses DestinationLocator to support user authentication.

The SecureDestinationLocator class provides two public methods, setCredentials() and logout(). When you call setCredentials() the supplied username and password are set on all configured destinations. When you call logout() the user is logged out from all configured destinations. At present SecureDestinationLocator doesn't support remote credentials or setting credentials on individual destinations.

When you set the user's credentials on a service they are applied to the underlying channel not the individual services i.e. the set of services belonging to the channel share the same credentials.

The SecureDestinationLocator will allow you to create a custom login form in your application and use the underlying J2EE security model. The benefits to your application are that you can apply authentication to your server-side destinations and also use role-based authorization. If you are developing a more complex enterprise application, which may have mid-tier business logic that is held in EJBs the user principal, which is created on authentication will be propagated. This allows you to identify the user and to secure you EJBs. The motivation to secure your server-side services often comes from the need to protect your system from malicious hackers, which forces many enterprise applications to undergo penetration testing before they can enter production.

On a wider enterprise scale many of today's J2EE-application servers support Single Sign On (SSO) and integration with Identity Management Solutions.

Posted by at 10:06 AM | Comments (4)

June 28, 2006

New FlexUnit Ant Task

Many thanks to Tony Hillerson of EUI for his contribution following my last blog on FlexUnit + Ant. Tony has taken the FlexUnit task and added the following properties:

  • haltonfailure - stop the build process if a failure occurs in one of the tests..
  • failureproperty - the name of a property to set if there is a failure in one of the tests..
  • verbose - print information about the test run.

The following example shows how to use these properties:

<target name="test-flex">
   <flexunit 
      swf="bin/AntTestRunner.swf"
      toDir="${flex-reports}"
      haltonfailure="false"
      verbose="true"
      failureproperty="flexunit.failed"	/>
		
   <junitreport todir="${flex-reports}">
      <fileset dir="${flex-reports}">
         <include name="TEST-*.xml"/>
      </fileset>
			
      <report format="frames" todir="${reports}/flex"/>
			
   </junitreport>
		
   <fail 
      message="One or more flexunit tests failed. See test reports for details." 
      if="flexunit.failed" />
</target>

Resources

Posted by at 1:32 PM | Comments (4)

June 1, 2006

FlexUnit + Ant

I have been planning this blog for some time, but was spurred on by a recent blog on Continous Integration in Flex. This blog concentrates on integration between Ant and FlexUnit, I will post a follow-up entry with details on how to setup a CruiseControl server for Continuous Integration.

This blog entry was written against Flex 2.0 Beta 3.

I have seen various postings about integration between FlexUnit with Ant, however most solutions seem to require a Flex server. My motivation here was to create an Ant task that has no dependency on a server. That would allow unit tests to be run in autonomously.

Very early on I decided if I was running the tests from Ant I wanted to re-use the JUnit tasks that already ship with Ant. In particular I wanted to use the JUnitReport task, which merges the XML files generated by the JUnit task to produce an HTML report. Therefore I wanted FlexUnit to print the results in the same XML format as the XML formatter used by the JUnit task.

The question was then how to make the XML test results available to the Ant tasks, my answer was to use XML sockets.

Technical Design

My solution is comprised of a controlling Ant task, flexunit, and a FlexUnit test runner, JUnitTestRunner, which is shown in the diagram below. The flexunit task starts a socket server running inside of a thread and launches the Flash Player, which runs the tests using the JUnitTestRunner. When JUnitTestRunner has finished running the test it formats the results as per the JUnit XML format and sends them to the flexunit task over an XML Socket, the flexunit task then saves them to disk. We can then use the JUnitReport task to create a report or use CruiseControl to create a report.

Requirements

  • Download the Ant distribution.
  • Download the example project (FlexUnitExample).

Software Installation

  • Extract the Ant distribution.
  • Add <your_ant_directory>\bin to your path.
  • Extract the FlexUnitExample project to your Eclipse/FB workspace (you only need to extract it into your workspace if you want to load the project into Eclipse/FB - select File > Import and follow the Existing Projects into Workspace wizard).
  • Edit <your_FlexUnitExample_directory>\build.properties and change the value of the flex.sdk.home property to the location of your Flex2 SDK installation (remember to use forward slashes).
  • The SWF containing your tests must run in the local trusted sandbox, copy FlexUnitExample.cfg from <your_FlexUnitExample_directory> to C:\Documents and Settings\<your_username>\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust.
  • Edit FlexUnitExample.cfg so it has the path to <your_FlexUnitExample_directory>\bin.

Example

To run the build script open a command prompt and change directory to <your_FlexUnitExample_directory>. To run the build script execute the following command: ant.

This will execute the Ant build script, which will run the SWF containing the tests and generate a JUnitReport report. The reports directory under <your_FlexUnitExample_directory> will contain the XML files created by JUnitTestRunner, you can view the report by opening <your_FlexUnitExample_directory>\reports\html\index.html. You should see two tests, one that passed and the other that failed.

Resources

You can download the source code for flexunit and JUnitTestRunner below, they are provided as an Eclipse Java Project and an Eclipse Flex Library project respectively.

  • Download the source for the flexunit Ant task (FlexAntTasks).
  • Download the source for the JUnitTestRunner (FlexUnitOptional).

You can import these projects into your workspace – extract the files into your workspace and in Eclipse select File > Import and follow the Existing Projects into Workspace wizard.

Posted by at 2:57 PM | Comments (27)