development and deployment roles

42
Development and Deployment Roles Venugopal Pakanati

Upload: gari

Post on 14-Jan-2016

35 views

Category:

Documents


0 download

DESCRIPTION

Development and Deployment Roles. Venugopal Pakanati. What is EJB technology ? What is an EJ bean ? Types of Beans Entity Bean Session Bean. EJB Architecture :. EJB Server. EJB Container. Locate, Create, Remove instances of EJB. Home Interface. EJB Client. EJB. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Development and Deployment Roles

Development and Deployment Roles

Venugopal Pakanati

Page 2: Development and Deployment Roles

• What is EJB technology ?

• What is an EJ bean ?

• Types of Beans• Entity Bean• Session Bean

Page 3: Development and Deployment Roles

EJB Architecture :

DatabasesEJB

HomeInterface

RemoteInterface

EJB Server

EJB Container

EJBClient

Locate, Create, Remove instances of EJB

Invoke business methods of EJB

Page 4: Development and Deployment Roles

5 Roles in the application development and deployment life cycle

1. Enterprise Java Bean providers

2. Application Assemblers

3. Deployers

4. System Adminstrators

5. Application Server Vendors

Page 5: Development and Deployment Roles

EJB Provider Application Assembler

Deployer

ApplicationServer Vendor

SystemAdministrator

Development and Deployment Scenario

Page 6: Development and Deployment Roles

1. The Enterprise Java Bean Provider

• referred to as an ‘application domain expert’.

• needs to be an expert in the business logic.

• needs to be able to express business logic using Java code.

• does not need to be an expert in system-level programming

• do not need to understand the details of the target environment

Page 7: Development and Deployment Roles

The enterprise bean provider produces --- a JAR containing :

(i) The bean’s home interface

(ii) The bean’s remote interface

(iii) The bean’s implementation class

(iv) The bean’s primary key class, in case of an entity bean

(v) A partially-complete deployment descriptor

Page 8: Development and Deployment Roles

Example: Banking Account

Entity Bean Session Beanmembers: accountID

customerNamecustomerTypeaccountBalance

Bean Name: Account Bean Name: AccountManagerHome Interface: AccountHome Home Interface: AccountManagerHomeHI methods: create( ); HI methods: create( ); findbyPrimaryKey( ); Remote Interface: Account Remote Interface: AccountManagerRI methods: withdraw( ); RI methods: createAccount( );

deposit( ); withdraw( ); getCustomerType( ); deposit( );

cancel( );

Implementation class: AccountEJB Implementation class: AccountManagerEJB

Security Roles: UnmediatedAccess (Web, ATM) ----- deposit( ), withdraw( ) Teller ----- deposit( ), withdraw( ) Manager ----- All methods

Ofsessionbean

Page 9: Development and Deployment Roles

(i) The Bean’s Home Interface

(a) Home Interface for the Entity Bean

(b) Home Interface for the Session Bean

Page 10: Development and Deployment Roles

(a) Home interface for the entity bean :

package wrox.some_isv ;

import javax.ejb.* ;import java.rmi.RemoteException ;

public interface AccountHome extends EJBHome { public Account create (int accountID, String customerName, String customerType, double initialBalance)

throws CreateException, RemoteException ;

public Account findByPrimaryKey (Integer accountID) throws FinderException, RemoteException ;

}

Page 11: Development and Deployment Roles

(b) Home Interface for the Session Bean :

package wrox.some_isv ;

import javax.ejb.* ;import java.rmi.RemoteException ;

public interface AccountManagerHome extends EJBHome { AccountManager create ( )

throws CreateException, RemoteException ;}

Page 12: Development and Deployment Roles

(ii) The Bean’s Remote Interface

(a) Remote Interface for the Entity Bean

(b) Remote Interface for the Session Bean

Page 13: Development and Deployment Roles

(a) Remote Interface for the Entity Bean :

package wrox.some_isv ;

import javax.ejb.* ;import java.rmi.RemoteException ;

public interface Account extends EJBObject { void withdraw (double amount) throws InsufficientFundsException, RemoteException ;

void deposit (double amount) throws RemoteException ;

String getCustomerType( ) throws RemoteException ;}

Page 14: Development and Deployment Roles

(b) Remote Interface for the Session Bean :

package wrox.some_isv ;

import javax.ejb.* ;import java.rmi.RemoteException ;

public interface AccountManager extends EJBObject { void createAccount (int accountID, String customerName, String customerType, double initialBalance) throws NoAccountCreatedException, RemoteException ;

void withdraw (int accountID, double amount) throws InsufficientFundsException, NoSuchAccountException,

RemoteException ;

void deposit (int accountID, double amount) throws NoSuchAccountException, RemoteException ;

public void cancel (int accountID) throws RemoteException ;}

Page 15: Development and Deployment Roles

(iii) Bean’s Implementation Class :Session Bean implementation class :package wrox.some_isv;import javax.ejb.*;import javax.naming.*;import java.rmi.RemoteException;

public class AccountManagerEJB implements SessionBean { public SessionContext ctx;

public void createAccount(int accountID, String customerName, String customerType, double initialBalance) throws NoAccountCreatedException { try { AccountHome accountHome = getAccountHome(); accountHome.create(accountID, customerName, customerType, initialBalance); } catch (CreateException ce) { throw new NoAccountCreatedException(ce.getMessage()); } catch (RemoteException re) { throw new EJBException(re); } }

Page 16: Development and Deployment Roles

public void withdraw(int accountID, double amount) throws InsufficientFundsException, NoSuchAccountException { try { Account account = getAccount(accountID);

if ((amount > 250) && account.getCustomerType().equals(CustomerTypes.INDIVIDUAL) && ctx.isCallerInRole("ATM")) { throw new SecurityException();

} account.withdraw(amount); } catch (RemoteException re) { throw new EJBException(re); } }

Page 17: Development and Deployment Roles

public void deposit(int accountID, double amount) throws NoSuchAccountException { try { Account account = getAccount(accountID); account.deposit(amount); } catch (RemoteException re) { throw new EJBException(re); } }

public void cancel(int accountID) { try { Account account = getAccount(accountID); account.remove(); } catch (NoSuchAccountException nsae) { } catch (Exception e) { throw new EJBException(e); } }

Page 18: Development and Deployment Roles

private Account getAccount(int accountID) throws NoSuchAccountException { try { AccountHome home = getAccountHome(); return home.findByPrimaryKey(new Integer(accountID)); } catch (RemoteException re) { throw new EJBException(re); } catch (FinderException fe) { throw new NoSuchAccountException(); } }

private AccountHome getAccountHome() { try {

InitialContext initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/GenericAccount");

AccountHome home = (AccountHome) javax.rmi.PortableRemoteObject .narrow(objref, AccountHome.class);

return home; } catch (NamingException ne) { throw new EJBException(ne); } }

Page 19: Development and Deployment Roles

public void ejbCreate() {} public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} }}

Page 20: Development and Deployment Roles

Entity Bean implementation class :package wrox.some_isv;import javax.ejb.*;import javax.naming.*;public class AccountEJB implements EntityBean { public Integer accountID; public String customerName; public String customerType; public double accountBalance;

public void withdraw(double amount) throws InsufficientFundsException { if (accountBalance - amount < 0) { throw new InsufficientFundsException(); } accountBalance -= amount; } public void deposit(double amount) { accountBalance += amount; }public String getCustomerType() { return customerType; }

Page 21: Development and Deployment Roles

public Integer ejbCreate(int accountID, String customerName, String customerType, double initialBalance) throws CreateException {

if (!customerType.equals(CustomerTypes.CORPORATION) &&!customerType.equals(CustomerTypes.INDIVIDUAL)) {

throw new CreateException("Unknown customer type."); }

this.accountID = new Integer(accountID); this.customerName = customerName; this.customerType = customerType; this.accountBalance = initialBalance; return this.accountID; }

public void ejbActivate() {} public void ejbLoad() {} public void ejbPassivate() {} public void ejbRemove() {}}

Page 22: Development and Deployment Roles

(v) Deployment Descriptor :

2 types of information contained within a deployment descriptor :

• structural information of the EJBs (provided by the Bean Developer) • Application Assembly information (provided by the Application Assembler)

Page 23: Development and Deployment Roles

At this stage, the Deployment Descriptor contains the following information for each bean :

• Bean’s type: session or entity• Bean’s name• Bean’s implementation class • Bean’s home interface• Bean’s remote interface• Whether an entity bean is re-entrant or not• Whether a session bean is stateful or stateless• Whether or not a session bean manages its own transactions• Whether an entity bean uses BMP or CMP• Bean’s primary key class• Any references in the code to other EJBs• Any references in the code to security roles

Page 24: Development and Deployment Roles

Indirection :

• to avoid dependencies on a particular security implementation, a particular database etc.

• is the use of a reference ‘placeholder’ in your Java code or deployment descriptor, rather than a reference to an actual entity in the implementation environment

• 3 types of references : references to other EJBs references to resources references to security roles

• At the deployment stage, the deployer creates a map between these virtual references and the real resources (like database connections)

Page 25: Development and Deployment Roles

2. The Application Assembler

• just needs to understand the home and remote interfaces, and the business logic

• need not understand the implementation of any EJBs

• combines EJBs into a deployable application by (i) completing the deployment descriptor (ii) adding other types of application components

(to test the functionality of EJBs)

Page 26: Development and Deployment Roles

(i) Completing the deployment descriptor :

Application Assembler

• may define one or more security roles

• may define method permissions

• must link any security role references declared by an EJB to a security role that they have defined

Page 27: Development and Deployment Roles

Final version of our application’s deployment descriptor :

<?xml version="1.0" ?>

<ejb-jar>

// provided by Bean Developer

<enterprise-beans>

<session>

<ejb-name>AccountManager</ejb-name>

<home>wrox.some_isv.AccountManagerHome</home>

<remote>wrox.some_isv.AccountManager</remote>

<ejb-class>wrox.some_isv.AccountManagerEJB</ejb-class>

<session-type>Stateless</session-type>

Page 28: Development and Deployment Roles

<ejb-ref>

<ejb-ref-type>Entity</ejb-ref-type>

<ejb-link>Account</ejb-link>

<home>wrox.some_isv.AccountHome</home>

<remote>wrox.some_isv.Account</remote>

</ejb-ref>

<security-role-ref>

<description>This role refers to automated customer withdrawals from the account;

no bank intermediary is involved.</description>

<role-name>ATM</role-name>

<role-link>UnmediatedAccess</role-link>

</security-role-ref>

</session>

Page 29: Development and Deployment Roles

<entity>

<ejb-name>Account</ejb-name>

<home>wrox.some_isv.AccountHome</home>

<remote>wrox.some_isv.Account</remote>

<ejb-class>wrox.some_isv.AccountEJB</ejb-class>

<persistence-type>Container</persistence-type>

<reentrant>False</reentrant>

<cmp-field>

<field-name>customerType</field-name>

</cmp-field>

<cmp-field>

<field-name>accountID</field-name>

</cmp-field>

<cmp-field>

<field-name>accountBalance</field-name>

</cmp-field>

Page 30: Development and Deployment Roles

<cmp-field>

<field-name>customerName</field-name>

</cmp-field>

<primkey-field>accountID</primkey-field>

</entity>

</enterprise-beans>

Page 31: Development and Deployment Roles

// provided by Application Assembler

<assembly-descriptor>

<security-role>

<description>This role is performed by any account access in which a bank employee

is not involved, such as an internet transaction or ATM withdrawal.</description>

<role-name>UnmediatedAccess</role-name>

</security-role>

<security-role>

<description>This role is peformed by any customer-service representative who does not

have account-manager status. They will be able to handle deposits and withdrawals,

but not account management.</description>

<role-name>Teller</role-name>

</security-role>

Page 32: Development and Deployment Roles

<security-role>

<description>This role is performed by professionals who are allowed to

manage an account (open, close).</description>

<role-name>Manager</role-name>

</security-role>

<method-permission>

<role-name>Manager</role-name>

<method>

<ejb-name>Account</ejb-name>

<method-name>*</method-name>

</method>

<method>

<ejb-name>AccountManager</ejb-name>

<method-name>*</method-name>

</method>

</method-permission>

Page 33: Development and Deployment Roles

<method-permission>

<role-name>Teller</role-name>

<role-name>UnmediatedAccess</role-name>

<method>

<ejb-name>Account</ejb-name>

<method-name>withdraw</method-name>

</method>

<method>

<ejb-name>Account</ejb-name>

<method-name>deposit</method-name>

</method>

<method>

<ejb-name>Account</ejb-name>

<method-name>getCustomerType</method-name>

</method>

Page 34: Development and Deployment Roles

<method>

<ejb-name>Account</ejb-name>

<method-name>findByPrimaryKey</method-name>

</method>

<method>

<ejb-name>AccountManager</ejb-name>

<method-name>withdraw</method-name>

</method>

<method>

<ejb-name>AccountManager</ejb-name>

<method-name>deposit</method-name>

</method>

</method-permission>

</assembly-descriptor>

</ejb-jar>

Page 35: Development and Deployment Roles

(ii) adding other types of application components :

test client:Let the security role of this client be “ATM”

package wrox.some_isv;

import java.rmi.RemoteException;import javax.ejb.*;import javax.naming.*;import javax.rmi.PortableRemoteObject;

public class TestClient { public static void main(String[] args) { try { InitialContext initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/AccountAccess"); AccountManagerHome home = (AccountManagerHome) PortableRemoteObject.narrow(objref, AccountManagerHome.class);

Page 36: Development and Deployment Roles

AccountManager accountManager = home.create();

System.out.println("withdrawing small amount from individual account"); accountManager.withdraw(1, 100.0);

System.out.println("withdrawing large amount from corporate account"); accountManager.withdraw(2, 1000.0);

System.out.println("withdrawing large amount from individual account"); accountManager.withdraw(1, 1000.0);

} catch (Exception e) { e.printStackTrace(); } } }

Page 37: Development and Deployment Roles

3. Deployer

• maps the logical references that the bean provider uses onto actual resources or identities

• need not be a domain expert

• need to be an expert in the environment in which the application will execute

Page 38: Development and Deployment Roles

Mapping the logical references :

(i) map the logical security roles to actual users or groups

(ii) map logical database accesses to an actual database

(iii) map all the beans and references into the JNDI namespace

Page 39: Development and Deployment Roles

4. The System Adminstrator

• responsible for configuring the application server, EJB container, and the environment in which they execute --- including the database, network, and security systems

• responsible for the ‘well-being’ of the EJBs that are executing in the container

• must monitor logs for system problems, security problems, etc.

Page 40: Development and Deployment Roles

5. Application Server / Container Vendor

• a role that we, as application developers, are unlikely to play

Page 41: Development and Deployment Roles

Choosing an Application Server :

• Do you need an ORB-based product to communicate with non-Java clients or for vendor interoperability ?

• What object/relational mapping capabilities do you require ?

• What kind of development and deployment tools are supported by a vendor’s application server ?

• What version of EJB specification does the application server support ?

• What platform(s) does the application server run on ?

Page 42: Development and Deployment Roles

Thank You !