Dashboard > Documentation > ... > 2. Developer Guide > 2.6. Spring Services

View Info

2.6. Spring Services

 Documentation Summary
 Page Summary

Introduction

Granite Data Services supports out-of-box Spring framework integration. You can easily power your Java destinations with all Spring features: Inversion of Control/Dependency Injection, AOP interceptors, transaction management, etc.

GDS/Spring also fully support Acegi security system.

For a basic sample with Granite DS/Spring/Acegi/Ejb3 entity beans working together, download graniteds-spring-ejb3-1.0.0.zip and import it as a new Eclipse project.

Spring Services Configuration

The first step is to configure your Spring destinations:

services-config.xml
<?xml version="1.0" encoding="UTF-8"?>

<services-config>

    <services>
        <service
            id="granite-service"
            class="flex.messaging.services.RemotingService"
            messageTypes="flex.messaging.messages.RemotingMessage">
            <destination id="test">
                <channels>
                    <channel ref="my-graniteamf"/>
                </channels>
                <properties>
                    <factory>springFactory</factory>
                    <source>springBean</source>
                </properties>
                <security>
                    <security-constraint>
                        <auth-method>Custom</auth-method>
                        <roles>
                            <role>ROLE_USER</role>
                            <role>ROLE_ADMIN</role>
                        </roles>
                    </security-constraint>
                </security>
            </destination>
        </service>
    </services>

    <factories>
        <factory id="springFactory"
            class="org.granite.messaging.service.SpringServiceFactory" />
    </factories>

    <channels>
        <channel-definition id="my-graniteamf" class="mx.messaging.channels.AMFChannel">
            <endpoint
                uri="http://{server.name}:{server.port}/{context.root}/graniteamf/amf"
                class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>
    </channels>

</services-config>

Some comments:

<properties>...</properties>

This block tells GDS to use factory class springFactory (see below) to instantiate current destination.
Tag 'source' names a Spring bean, used to represent your destination.

<security>...</security>

This block (optional) tells the GDS Acegi security service (see below) to check for required roles when accessing the "test" destination. See the acegiSecurityContext.xml file in graniteds-spring-ejb3-1.0.0.zip for role configuration.

<factories>...</factories>

This block declares a Spring factory which is used to instantiate your destinations.

You may also customize your granite-config.xml in order to use automated externalization, etc.

Acegi Security Service Configuration

To enable Acegi security, you must put a declaration in granite-config.xml:

<granite-config>
   ...
   <!--
    ! Use Acegi based security service.
    !-->
    <security type="org.granite.messaging.service.security.AcegiSecurityService"/>

</granite-config>

You may then secure your Flex destinations as shown earlier. Please refer to Acegi documentation for specific configuration details.

General Web Configuration (web.xml)

In order to initialize Spring and Acegi security, you must also customize your web.xml as follow:

<web-app version="2.4" ...>
    ...
    <!-- Path to Spring config -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/conf/applicationContext.xml,
            /WEB-INF/conf/acegiSecurityContext.xml
        </param-value>
    </context-param>

    <!-- Spring listener -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <!-- Spring listener for web-scopes (request, session) -->
    <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
    </listener>

    <filter>
        <filter-name>Acegi Filter Chain Proxy</filter-name>
        <filter-class>
            org.acegisecurity.util.FilterToBeanProxy
        </filter-class>
        <init-param>
            <param-name>targetBean</param-name>
            <param-value>filterChainProxy</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>Acegi Filter Chain Proxy</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    ...
</web-app>

For a full example, please download graniteds-spring-ejb3-1.0.0.zip.


Browse Space
- Pages
- Labels
- Attachments
- Mail
- Bookmarks
- News
- Activity
- Advanced

Explore Confluence
- Popular Labels
- Notation Guide

Your Account
Log In

Other Features

View a printable version of the current page.

Add Content
- Add Comment


Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.0 Build:#913 Sep 27, 2007)
Bug/feature request - Contact Administrators

SourceForge.net Logo
Copyright © 2007-2008 Adequate Systems. All Rights Reserved.