Open Portal Adapter Reference Guide 1.0 Copyright kingmedia websolutions 2005-2008 Preface ................................................................................................................................... iii 1. Setting up an open portal adapter project ............................................................................... 1 1.1. Requirements ............................................................................................................ 1 1.2. Maven Archetype ...................................................................................................... 1 2. Open Portal Adapter Architecture ......................................................................................... 3 2.1. Notice ....................................................................................................................... 3 2.2. Architecture Overwiew .............................................................................................. 3 3. Modules of the Open Portal Adapter ..................................................................................... 5 3.1. Core ......................................................................................................................... 5 3.1.1. GenericController ........................................................................................... 5 3.1.2. Annotations .................................................................................................... 5 3.1.3. Extending the GenericController ...................................................................... 5 3.2. User Profile Module .................................................................................................. 6 3.2.1. User Service ................................................................................................... 6 4. Vendor modules ................................................................................................................... 7 4.1. Liferay Module ......................................................................................................... 7 4.1.1. Description ..................................................................................................... 7 4.1.2. Integration with Open Portal Adapter ............................................................... 7 4.2. JBoss Portal Module .................................................................................................. 7 4.2.1. Decription ...................................................................................................... 7 4.2.2. Integration with Open Portal Adapter ............................................................... 7 A. Appendix - Some Further Readings ...................................................................................... 8 A.1. Using Spring Security with OPA ............................................................................... 8 Open Portal Adapter (1.0) ii Preface The Problem: The Portlet API 1.0 and 2.0 aka JSR 168/JSR 286 have a Gap in gathering Informations about the User. Our vision: The Open Portal Adapter provides the ability to develop portlets without container barriers. Use a consistent user authentication and authorization over various portletcontainer with Spring Security and access user profile information always over the same interface. Do not think about different implementations about of undefined functions in the JSR168 and 286 standard. The Open Portal Adapter will close this gaps and unify the needed Informations. For a quick start the included maven archetype provides a project structure and container depended and preconfigured configuration files out of the box. Open Portal Adapter (1.0) iii Chapter 1. Setting up an open portal adapter project 1.1. Requirements • This release requires Maven 2.0.9. • The Open Portal Adapter libraries (opa-core.jar, opa-profile.jar, opa-jboss.jar, opa-liferay.jar) for detailed information on the jars see the Modules section of this document. These libraries can be obtained via the described Maven archetype or as download the source from svn. • An IDE of your choice with Maven support is recommended, but you can also use an simple editor and run Maven in a shell, if you prefer it more cowboy style. • Make sure you have JDK 5.0 installed or above. Note that the open portal adapter uses JDK 5.0 annotations. So any Java version below Java 5 isn't supported 1.2. Maven Archetype Please use our archtype in order to set up a Project Skeleton. That fulfills the required dependencies. You might use the following Maven Command for creating a new Maven project with the Open Portal Adapter Archetype. mvn archetype:generate -B -DartifactId=[yourartifactId] -DarchetypeGroupId=org.cilander.opa -DarchetypeArtifactId=opa-archetype -DarchetypeVersion=1.0.5 -DarchetypeRepository=https://archiva.cilander.org/archiva/repository/internal/ The Projectskeleton after creating a project with the Archetype will look like : Project |main | java | resources | webapp |--- META-INF | |MANIFEST.MF | |--- WEB-INF |lib |portlet-context | |portletContext.xml |portlet.xml |web.xml Open Portal Adapter (1.0) 1 Setting up an open portal adapter project After you have create the Project you will be able to benefit from our predefined profiles. Use jboss or liferay as profile if you either plan to deploy on JBoss or on Liferay. Open Portal Adapter (1.0) 2 Chapter 2. Open Portal Adapter Architecture 2.1. Notice Since Open Portal Adapter uses the Springframework. We make usage of the followed Classes of Spring Dispatcherportlet Default Portlet Implementation of the Springframework. Controller Spring Controller Class it will delegate the RenderRequest. 2.2. Architecture Overwiew The Open Portal Adapter is build upon the Springframework actually we use version 2.5.6.A. We support the Portlet API 1.0 and 2.0 . The Core Module contains the basic functionality of the Framework. The Profile Module is build upon the Core and contains the main UserProfile features. The Profile Service make usage of the Vendor Modules in order to gather the informations about the User and return unified user information. Open Portal Adapter (1.0) 3 Open Portal Adapter Architecture Open Portal Adapter (1.0) 4 Chapter 3. Modules of the Open Portal Adapter The Open Portal Adapter consists of the following main Modules. Open Portal Adapter Core, Open Portal Adapter User, Open Portal Adapter Security 3.1. Core The Core Module of the Open Portal Adapter. This module will provide you with the basic classes of the framework. 3.1.1. GenericController This Controller class should be extended when using the Open Portal Adapter. It contains the initService Method that has to be called when extending this Controller. 3.1.2. Annotations @UsingOpenPortalAdapterService(serviceNames= [OpaConstants.USER_SERVICE, OpaConstants.SECURITY_SERVICE ]) The example above shows the usage of the UsingOpenPortalAdapterService Annotation. This annotation will indicate that the Declaring class is going to use one of our Services. It should even be possible to make usage of your own Services, as long as it's registered as spring bean. 3.1.3. Extending the GenericController Within the created project. You can create a new class that will extend the GenericController class of the Open Portal Framework. See code snippet below. //declare the services being used via annotations. Here we are going to use the //USER_SERVICE @UsingOpenPortalAdapterService(serviceNames=OpaConstants.USER_SERVICE) public class TestController extends GenericController { @Override protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception { //init the declared services for this class initService(this.getClass()); Map m = new HashMap(); //obtain the service the user service will return a GenericUserProfile //with the request you can make a call on the user attributes m.put("user", ((GenericUserProfile)getService(OpaConstants.USER_SERVICE)) .getLoginName(request)); return new ModelAndView("hello",m); } } Afterwards this class must be added to the portletContext.xml, so it will be used as Controller for the View. Now you have written the first Portlet with the Open Portal Adapter. Open Portal Adapter (1.0) 5 Modules of the Open Portal Adapter 3.2. User Profile Module 3.2.1. User Service This section will cover the User Profile module being covered by the Open Portal Adapter to close the gap of the Information about the User in the Portlet API 1.0 and 2.0. Therefore the Profile Module has a User Interface that will wrap the Vendor specific Implementations and you can use the declared methods like getFirstname and so on for convenience. Open Portal Adapter (1.0) 6 Chapter 4. Vendor modules Open Portal Adapter mainly focus on vendor independent implementation for getting user information. The project also have a nice integration with two Vendor modules. 4.1. Liferay Module 4.1.1. Description The Liferay Module should get the required information of the Liferay specific implementation. Supported Version: 5.1.2 4.1.2. Integration with Open Portal Adapter If Liferay Module (opa-liferay.jar) is available in the classpath, Open Portal Adaptor will integrates in the followed way: • Our factory will use the LifeUserUtil class for getting the required information of the user profile and wrapper it in our User Interface so you won't have to take care the about the Liferay secific UserProfile class. We use the UserLocalServiceUtil implementation of Liferay to wrapper the information. 4.2. JBoss Portal Module 4.2.1. Decription The JBoss Portal Module should get the required information of the JBoss Portal specific implementation. Supported Version: 2.7.0 4.2.2. Integration with Open Portal Adapter If JBoss Module (opa-jboss.jar) is available in the classpath, Open Portal Adaptor will integrates in the followed way: • Our factory will make usage of the JBossUserUtil class. We use the UserModule Service of JBoss Portal to get the required information and wrap the gathered information again in our User Interface Open Portal Adapter (1.0) 7 Appendix A. Appendix - Some Further Readings Portlet Books: • Portlets. Portalkomponenten in Java (german) JSF Books: • Core JavaServer Faces • JavaServer Faces. Ein Arbeitsbuch für die Praxis (german) • JavaServer Faces. The Complete Reference • JSF in Action JSF Online Resources: • JSF Programming Resources Spring Documentation: • Reference Documentation Portlet Online Resources: • Portlet API Introduction to Portlet Programming with JSR-168: • Introduction to the Portlet API A.1. Using Spring Security with OPA To integrate Spring Security with OPA, download the Spring Security API 2.0.4 . and the additional steps required to use spring security are : - Define the security interceptor in portletContext.xml as the example below: <bean class="org.springframework.web.portlet.handler.PortletModeHandlerMapping"> <property name="interceptors"> <list> <ref bean="portletContextIntegrationInterceptor"/> <ref bean="portletAuthenticationInterceptor"/> <ref bean="securityModeInterceptor"/> </list> </property> <property name="portletModeMap"> <map> <entry key="view" value-ref="simpleController" /> <entry key="edit" value-ref="simpleController" /> <entry key="help" value-ref="simpleController" /> </map> Open Portal Adapter (1.0) 8 Appendix - Some Further Readings </property> </bean> - Create the following XML Security Config under WEB-INF folder. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:sec="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd"> <bean id="securityModeInterceptor" class="de.kingmedia.portlet.security.ui.SecurityModeInterceptor"></bean> <!-- This interceptor populates the SecurityContextHolder with information obtained from the PortletSession. It is applied to both ActionRequests and RenderRequests --> <bean id="portletContextIntegrationInterceptor" class="org.springframework.security.context.PortletSessionContextIntegrationInterceptor"/> <!-Interceptor that processes portlet requests for authentication by invoking the configured AuthenticationManager. Creates the initial AuthenticationToken from the PortletRequest security methods. --> <bean id="portletAuthenticationInterceptor" class="org.springframework.security.ui.portlet.PortletProcessingInterceptor"> <property name="authenticationDetailsSource"> <bean class="org.springframework.security.ui.portlet.PortletPreAuthenticatedAuthenticationDetailsSource"> <property name="mappableRolesRetriever"> <bean class="org.springframework.security.authoritymapping.SimpleMappableAttributesRetriever"> <property name="mappableAttributes"> <list> <!-- The roles and/or groups that should have access to your portlet in the resource --> <value>tomcat</value> <value>admin</value> <value>manager</value> <!-- Some standard liferay roles --> <value>Administrator</value> <value>Guest</value> <value>User</value> <value>Power User</value> </list> </property> </bean> </property> </bean> </property> <property name="authenticationManager" ref="authenticationManager"/> <!-- Liferay doesn't seem to set the authType --> <property name="useAuthTypeAsCredentials" value="false"/> </bean> <sec:authentication-manager alias="authenticationManager"/> <!-PreAuthenticatedAuthenticationProvider processes pre-authenticated authentication request (from PortletProcessingInterceptor).A valid PreAuthenticatedAuthenticationToken with non-null principal & credentials will succeed. --> <bean id="portletAuthProvider" class="org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationProvider"> <sec:custom-authentication-provider/> Open Portal Adapter (1.0) 9 Appendix - Some Further Readings <property name="preAuthenticatedUserDetailsService"> <!-Bean that knows how to populate user details(including GrantedAuthorities) for the authenticated user. PreAuthenticatedGrantedAuthoritiesUserDetailsService will use purely data contained in the PreAuthenticatedAuthenticationToken --> <bean class="org.springframework.security.providers.preauth. PreAuthenticatedGrantedAuthoritiesUserDetailsService"/> </property> <property name="throwExceptionWhenTokenRejected" value="true"/> </bean> <!-- Service layer authentication --> <bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased"> <property name="decisionVoters"> <list> <bean class="org.springframework.security.vote.RoleVoter" /> <bean class="org.springframework.security.vote.AuthenticatedVoter" /> </list> </property> </bean> </beans> - Import the created XML config in portletContext.xml with following directive: <import resource="${securityConfig filename}"/> Further information on Spring Security can be found at http://static.springframework.org/springsecurity/site/ Open Portal Adapter (1.0) 10