# Presentation: 009408

## CSM SDK Adapterfor caCORE SDK

**caBIG Developer’s Boot Camp**
**August, 2005**
- National Cancer Institute Center for Bioinformatics
- Ekagra Software Technologies Ltd.

## Outline

- Overview
- Where Are We ...
- What is CSM ???
- Introduction to CSM SDK Adapter
- New Features
- Changes from Client Application’s Perspective
- Architecture
- Overview
- SDKApplicationService Interface
- Installation and Usage
- General Workflow
- Server Configurations
- Client Configurations
- Usage
- Demo
- Q&A

## Where Are We ...

- UML Modeling for the application has been done
- Application has been generated using the caCORE SDK
- We have a fully functional client server application
- However this application doesn’t provide
- Security Integration
- Session Management
- Writable Capability
- CSM SDK Adapter adds these capabilities to the application generated using caCORE SDK
- What is CSM ??

## What is CSM ???

- CSM – Common Security Module is the common infrastructure application provided by NCICB
- Provides programmatic security to Java application
- Functionalities provided by CSM
- APIs
- Authentication
- Authorization
- Web based Applications
- User Provisioning Tool
- Reference Implementation

## Introduction to CSM SDKAdapter

- CSM-SDK Adapter is a wrapper over existing caCORE SDK output
- Takes caCORE SDK server & client as input and produces CSM SDK server & client
- Uses the same domain objects generated by caCORE SDK
- Provide all the functionality provided by the caCORE SDK except the utility methods
- Adds the following functionality to caCORE SDK
- Security Integration
- Session Management
- Writable APIs
- Standard Spring HTTP Remoting

## New Features

- Security Integration
- Authentication
- Authorization
- User Provisioning
- Session Management
- User Session Management
- Inactive session time-out
- No need to re-authenticate
- Writable APIs
- To create objects
- To update objects
- To delete objects
- Standard HTTP Remoting through Spring

## From Client Application’s Perspective

- None of the method’s signature changes
- None of the method’s functionality changes
- Instead of using ApplicationService from caCORE SDK, clients will use SDKApplicationService from the CSM-SDK Adapter
- Now all the methods will throw a common exception “ApplicationException”

## Architecture Diagram

- CSM SDK Adapter
- generated war file

- caCORE SDK
- generated
- business logic

- CSM
- APIs

- Spring
- Remoting

- caCORE
- SDK
- generated
- database
- schema

- CSM
- Authorization
- Schema

- Authentication
- Credential
- Provider

- Session
- Management

- CSM SDK
- generated
- client

- Spring
- Remoting

**HTTP Remoting**

- Client
- Application

- Server

- Client

## Architecture Contd...

- Implementation

- Client
- Application

- Application
- Service
- Interface

- User
- Session

- Security
- &
- User
- Session

- Blocks for Managing User Session and Security

- Hidden from User

- Application
- Service
- Interface

## SDKApplicationServiceInterface

- Methods exposed through SDKApplicationService interface
- Method parameters and return type are similar to caCORE API’s ApplicationService Interface
- Similar in functionality to caCORE API’s ApplicationService Interface
- Provides all the query methods
- Provides all the search methods
- Provides all the EVS methods
- All methods throw the ApplicationException
- Utility methods such as print are not provided
- Currently does not support dependent objects

## Installation Workflow 

- Build the server and client components for the SDK generated war
- Configure CSM. Use the _[CSM Guide for Application Developers](ftp://ftp1.nci.nih.gov/pub/cacore/CSM/CSM_Guide_ApplicationDevelopers.pdf)_
- Configure the application’s authorization policy using the User Provisioning Tool (UPT)
- Configure the client to point to the server hosting the CSM-SDK Application Service
- Use CSM-SDK Adapter Client in your application

## Building the Components 

- Obtain the war and client zip file generated by the caCORE SDK process
- Place them in the directory where the CSM-SDK Adapter is unzipped
- Edit the sdkBuild.xml file
- Change the warFileName value to the war file name which is generated by the caCORE toolkit
- Change the clientFileName value to the name of the client zip file which is generated by the caCORE toolkit
- Update value for arg4 is the web context root name for the HTTPService, for example, sdkremoting or your application name.
- Update value for arg6 is the unique name for the application as configured for CSM
- Run sdkBuild.xml file using ant

## Building the Components 

- Output will be generated in release folder
- Copy the war file on JBoss Server from the release/server folder
- Copy the jars and configuration files for the client application from the release/client folder

## Server Configurations 

- Create the database using caCORE SDK generated schema
- Place the datasource file generated by caCORE SDK in deploy directory of JBoss
- Session Management
- Declare a time out period (session Inactive timeout)
- Modify the properties-service.xml file
- CSM
- Turn CSM on or off
- Modify the properties-service.xml file

- <attribute name="Properties">
-     gov.nih.nci.security.configFile=c:/csm-config/ApplicationSecurityConfig.xml
-     gov.nih.nci.sdk.remote.**sdk**.securityLevel=1
-     gov.nih.nci.**sdk**.applications.session.timeout=120000
- </attribute>

## Configuring CSM

- Configure Credential Provider using login-config.xml file of JBoss for Authentication
- Create ApplicationSecurityConfig.xml and add entry for the application
- Configure the hibernate & datasource files appropriately to point to the correct Authorization Schema
- Configure the Application’s Security Policy through UPT
- Refer to CSM’s Documentation for detailed steps

## Configuring Client

- Add all the jars from the release/client folder into the lib directory of the client application
- Copy the remoteService.xml file in the classpath of the application and edit it
- Replace {Host} with the name of the server hosting the service

- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
- <beans>
-   <beanid="remoteService"class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
-     <property name="serviceUrl">
-       <value>http://localhost:8080/sdkremoting/http/remoteService</value>
-     </property>
-     <property name="srviceInterface">
-       <value>com.codegen.application.common.RemoteSDKApplicationService</value>
-     </property>
-   </bean>
- </beans>

## Usage

- Import the necessary classes
- Instantiate an object of ClientSession Class
- Initialize the session by passing the login credentials of a valid User
- Instantiate an object of ApplicationServiceProvider Class
- Obtain Implementation of SDKApplicationService Interface
- Invoke Business methods to perform the required task
- Handle the ApplicationException thrown
- Terminate the client session

- package gov.nih.nci.csm.sdk.test;
- import java.util.Date;
- import java.util.List;
- import gov.nih.nci.cadsr.domain.impl.DataElementImpl;
- import gov.nih.nci.csm.sdk.application.client.ApplicationServiceProvider;
- import gov.nih.nci.system.applicationservice.SDKApplicationService;
- import org.hibernate.criterion.DetachedCriteria;
- import org.hibernate.criterion.Expression;
- public class TestClient {
-     public static void main(String[] args) {
-         ApplicationServiceProvider asp = new ApplicationServiceProvider();
-         SDKApplicationService appService = asp.getApplicationService();
-         ClientSession cs = ClientSession.getInstance();
-         try{
-             cs.startSession("userId","password");
-         }catch(Exception ex){
-             System.out.println(ex.getMessage());
-         }
-         try{
-             DetachedCriteria deCrit = DetachedCriteria.forClass(DataElementImpl.class);
-             deCrit.add(Expression.eq("publicID", new Long(2199715)));
-             int count = appService.getQueryRowCount(deCrit,DataElementImpl.class.getName());
-             val = String.valueOf(count);
-             System.out.println("The size of the records is " + val);
-             List listR = appService.query(deCrit,DataElementImpl.class.getName());
-             System.out.println("The size of the records is second time is " + listR.size());
-             cs.terminateSession();
-         }
-         catch(Exception e) {
-             e.printStackTrace();
-         }
-     }
- }

## Further Reading

- caCORE SDK Programmer’s Guide
- ftp://ftp1.nci.nih.gov/pub/cacore/SDK/caCORE_SDK1.0_Programmers_Guide.pdf
- caCORE Technical Guide
- ftp://ftp1.nci.nih.gov/pub/cacore/caCORE2.0_Tech_Guide.pdf
- ftp://ftp1.nci.nih.gov/pub/cacore/caCORE3.0_Tech_Supp.pdf
- CSM Guide for Application Developers
- ftp://ftp1.nci.nih.gov/pub/cacore/CSM/CSM_Guide_ApplicationDevelopers.pdf
- caCORE SDK and CSM Web site
- http://ncicb.nci.nih.gov/core/SDK
- http://ncicb.nci.nih.gov/core/CSM

## Questions?				     Thank You