Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.

Slides:



Advertisements
Similar presentations
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Advertisements

Transactions Celsina Bignoli Motivations Atomic operations –Group of operation that must all succeed or all fail Network or machine.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
6/1/20151 Luca Simone Software Engineering 2 a.a. 2001/2002.
1 Softsmith Open Learning - EJB 21-Nov Enterprise Java Beans Introduction –Application ServerApplication Server –Java 2 Enterprise EditionJava.
Distributed System Using Java 2 Enterprise Edition (J2EE) B.Ramamurthy.
Enterprise Applications & Java/J2EE Technologies Dr. Douglas C. Schmidt Professor of EECS.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Java 2 Platform, Enterprise Edition (J2EE). Source: Computer, August 2000 J2EE and Other Java 2 Platform Editions.
JMS Java Message Service Instructor Professor: Charles Tappert By Student: Amr Fouda.
J2EE Security and Enterprise Java Beans Mrunal G. Dhond Department of Computing and Information Sciences Master of Science, Final Defense February 26,
ECSE Software Engineering 1I HO 7 © HY 2012 Lecture 7 Publish/Subscribe.
Version # Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999 by Carnegie.
Version # Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Sponsored by the U.S. Department of Defense © 1999 by Carnegie.
CS 483 Enterprise and Web Application Programming
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
Distributed Multitiered Applications The J2EE platform uses a multitiered distributed application model. Application logic is divided into components 1.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
1 Session Bean Chuyên đề Lập trình Java & J2EE Chương 14 Biên soạn: Th.S Nguyễn văn Lành.
Enterprise Java Beans - (EJB)
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
Developing and Deploying Business Components using PowerJ.
Entity Beans BMP Celsina Bignoli
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Introduction to J2EE Architecture Portions by Kunal Mehta.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
第十四章 J2EE 入门 Introduction What is J2EE ?
J2EE Structure & Definitions Catie Welsh CSE 432
J2EE Overview ver 1.0Page 1 © Wipro Technologies Talent Transformation J2EE Overview.
Source: Peter Eeles, Kelli Houston, and Wojtek Kozaczynsky, Building J2EE Applicationa with the Rational Unified Process, Addison Wesley, 2003 Prepared.
Collaborate Lesson 4C / Slide 1 of 22 Collaborate Knowledge Byte In this section, you will learn about: The EJB timer service Message linking in EJB 2.1.
1 Java EE Programming Enterprise JavaBeans. 2 Topics J2EE Overview Enterprise JavaBeans Overview Enterprise Entity Beans Case Study How to build them.
1 Transactions Michael Brockway Sajjad Shami CG0165: Advanced Applications Development in Java Northumbria University School of Computing, Engineering.
Assignment of JAVA id : BSSE-F10-M-10-JAVA1 Overview of J2EE/Session 2/Slide 1 of 38.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
DEVELOPING ENTERPRISE APPLICATIONS USING EJB
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
红杉树(中国)信息技术有限公司公司 地址:杭州市天目山路 176 号西湖数源软件园 11 号楼 3 层 电话: (86) Transaction & JAVA Fondy Wang 12/7/07.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
EJB Enterprise Java Beans JAVA Enterprise Edition
Securing Web Applications Lesson 4B / Slide 1 of 34 J2EE Web Components Pre-assessment Questions 1. Identify the correct return type returned by the doStartTag()
September 28, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Transactions and Security. Contents  Transactions  Transaction Support in EJB  Security  Security Support in EJB.
J2EE Application Development
Java Messaging Service (JMS)
Understanding and Designing with EJB
Luca Simone Software Engineering 2 a.a. 2001/2002
Objectives In this lesson, you will learn to:
Objectives In this lesson you will learn about: Need for servlets
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Knowledge Byte In this section, you will learn about:
Component-based Applications
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
J2EE Lecture 13: JMS and WebSocket
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Objectives In this lesson, you will learn about:
Presentation transcript:

Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features of message-driven beans Explain the life cycle of message-driven beans Identify steps to create message-driven beans Create applications using message-driven bean Secure EJB applications

Message-Driven Beans and EJB Security Lesson 4B / Slide 2 of 37 J2EE Server Components Pre-assessment Questions 1.Which ACID property of a transaction ensures that data loss does not occur when a network or a system failure occurs? a.atomicity b.consistency c.isolation d.durability

Message-Driven Beans and EJB Security Lesson 4B / Slide 3 of 37 J2EE Server Components Pre-assessment Questions (Contd.) 2.Which ACID property allows multiple transactions to read from or write to a database, one at a time? a.atomicity b.consistency c.isolation d.durability 3.Which transaction attribute specifies that a bean method must always be part of an existing transaction? a.Mandatory b.Required c.RequiresNew d.Supports

Message-Driven Beans and EJB Security Lesson 4B / Slide 4 of 37 J2EE Server Components Pre-assessment Questions (Contd.) 4.What is the responsibility of the bean provider? a.Rolls back the transaction. b.Generates an application error. c.Throws the exceptions, java.rmi.RemoteException or javax.ejb.EJBException, depending on whether the client is remote or local, respectively. d.Enables a JTA transaction to invoke a method in a stateful session bean even if the method has closed the connection to the database.

Message-Driven Beans and EJB Security Lesson 4B / Slide 5 of 37 J2EE Server Components Pre-assessment Questions 5.Which constant declared in the javax.transaction.Status interface specifies that the current transaction is preparing for transaction commit? a.STATUS_PREPARING b.STATUS_ACTIVE c.STATUS_COMMITTING d.STATUS_PREPARED

Message-Driven Beans and EJB Security Lesson 4B / Slide 6 of 37 J2EE Server Components Solutions to Pre-assessment Questions 1.d. durability 2.c. isolation 3.a. Mandatory 4.d. Enables a JTA transaction to invoke a method in a stateful session bean even if the method has closed the connection to the database. 5.a. STATUS_PREPARING

Message-Driven Beans and EJB Security Lesson 4B / Slide 7 of 37 J2EE Server Components Introducing Message-Driven Beans Provide asynchronous messaging between two Java components. Uses Java Message Service (JMS) Application Programming Interface (API) to receive messages from the components. Introducing JMS JMS API allows Java programs to send and receive messages. Difference between JMS and RMI

Message-Driven Beans and EJB Security Lesson 4B / Slide 8 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Advantages of JMS API are: Better performance Reliability Multiple Messaging JMS API supports two types of messaging techniques: Publish/Subscribe (Pub/Sub) Point-to-Point (PTP)

Message-Driven Beans and EJB Security Lesson 4B / Slide 9 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Features of Message-Driven Beans They are stateless because they do not store the state of the client. Instances are stored in a shared pool and EJB container can use any instance from this pool to receive and process the incoming message. They cannot return values or throw exceptions to the client. They can be declared as durable or non durable JMS consumers.

Message-Driven Beans and EJB Security Lesson 4B / Slide 10 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Life Cycle of Message-Driven Beans

Message-Driven Beans and EJB Security Lesson 4B / Slide 11 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Ready Stage Message-driven bean instance remains in the pool to service the messages sent by the clients. To add a new message-driven bean instance to the pool, EJB container performs the following steps: Call the setMessageDrivenContext () method to pass the context object to a message-driven bean instance. Call the ejbCreate () method of the instance to initialize the message-driven bean.

Message-Driven Beans and EJB Security Lesson 4B / Slide 12 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Does Not Exist Stage Message-driven bean is permanently removed from the message- driven bean pool. The onMessage() method is called whenever a message is received from the client.

Message-Driven Beans and EJB Security Lesson 4B / Slide 13 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Methods in a Message-Driven Bean setMessageDrivenContext(MessageDrivenContext) ejbCreate() onMessage(Message) ejbRemove()

Message-Driven Beans and EJB Security Lesson 4B / Slide 14 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) The setMessageDrivenContext(MessageDrivenContext) Method Receives a MessageDrivenContext object setRollbackOnly() : Declares that the current transaction should be rolled back. getRollbackOnly() : Checks whether the current transaction is declared for rollback or not. getUserTransaction(): Returns the javax.transaction.UserTransaction interface that enables you to retrieve information about a transaction and manage it.

Message-Driven Beans and EJB Security Lesson 4B / Slide 15 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) The ejbCreate() Method Creates a new message-driven bean. You can also pass arguments in the ejbCreate() method to initialize a message-driven bean instance. The ejbRemove() Method Destroys a message-driven bean and releases all the resources associated with it. Throws the exception, EJBException, to handle errors that occur during the removal of a message-driven bean.

Message-Driven Beans and EJB Security Lesson 4B / Slide 16 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) The onMessage(Message) Method Implements the business logic in a message-driven bean. Accepts the incoming message as an argument of the Message class type.

Message-Driven Beans and EJB Security Lesson 4B / Slide 17 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Deployment descriptor of Message-Driven Bean Various tags in a message-driven bean are:

Message-Driven Beans and EJB Security Lesson 4B / Slide 18 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Responsibilities of the Bean Provider and the EJB Container Provider The code of a message-driven bean class should fulfill the following criteria: Should implement the javax.ejb.MessageDrivenBean and javax.jms.MessageListener interfaces. Should be defined as a public class. However, it cannot be defined as the final or abstract class. Should contain one constructor that takes no arguments. Should implement the ejbCreate(), ejbRemove(), and onMessage() methods.

Message-Driven Beans and EJB Security Lesson 4B / Slide 19 of 37 J2EE Server Components Introducing Message-Driven Beans (Contd.) Responsibilities of the Bean Provider and the EJB Container Provider The code of a message-driven bean class should fulfill the following criteria: Should implement the javax.ejb.MessageDrivenBean and javax.jms.MessageListener interfaces. Should be defined as a public class. However, it cannot be defined as the final or abstract class. Should contain one constructor that takes no arguments. Should implement the ejbCreate(), ejbRemove(), and onMessage() methods.

Message-Driven Beans and EJB Security Lesson 4B / Slide 20 of 37 J2EE Server Components Creating Message-Driven Beans Creating Java File to Implement a Message-driven Bean Contains the code to implement the business logic of a message-driven bean. The following code snippet shows the onMessage() method in the MessageListener interface: public interface javax.jms.MessageListener { public void onMessage(Message message); }

Message-Driven Beans and EJB Security Lesson 4B / Slide 21 of 37 J2EE Server Components Creating Message-driven Beans (Contd.) Compiling and Deploying a Message-driven Bean Compiled using the javac compiler. Deployed in J2EE1.4 Application Server using the deploytool utility. The Enterprise Bean Wizard of the deploytool utility is used to deploy a message-driven bean. Accessing Message-driven Beans Application clients are stand-alone Java programs that can send JMS compatible messages to the message driven beans. Web-based clients are the Java components, such as JSP and servlets, which are run on a Web browser to access the message-driven beans.

Message-Driven Beans and EJB Security Lesson 4B / Slide 22 of 37 J2EE Server Components Creating Message-driven Beans (Contd.) Handling Exceptions in a Message-Driven Bean Condition for Exception EJB Container’s Handling Action Message-driven bean method is declared with the Required container- managed transaction attribute and a system exception occurs during the method execution. EJB container saves the system exception into the log file and performs the rollback of the current transaction. EJB container also removes the current message-driven bean instance.

Message-Driven Beans and EJB Security Lesson 4B / Slide 23 of 37 J2EE Server Components Creating Message-driven Beans (Contd.) Condition for Exception EJB Container’s Handling Action Message-driven bean method is declared with the NotSupported container-managed transaction attribute and a system exception occurs during the method execution. EJB container saves the exception into the log file and removes the current message-driven bean instance from EJB container.

Message-Driven Beans and EJB Security Lesson 4B / Slide 24 of 37 J2EE Server Components Demonstration-Implementing Message-driven Beans Problem Statement Nancy is developing an application that will be used by a client to send JMS-compliant messages to the server. The application needs to store the received messages in a server log file. Nancy needs to use a message-driven bean for developing this application.

Message-Driven Beans and EJB Security Lesson 4B / Slide 25 of 37 J2EE Server Components Demonstration-Implementing Message-driven Beans (Contd.) Solution To solve the problem, perform the following tasks: 1.Create the message-driven bean class. 2.Create the application client. 3.Create the JMS connection factory resource. 4.Create the JMS destination resource. 5.Create the physical destination. 6.Package the message-driven bean. 7.Creating the application client JAR file. 8.Configure the bean JAR file and client JAR module. 9.Deploy the application. 10.Test the application.

Message-Driven Beans and EJB Security Lesson 4B / Slide 26 of 37 J2EE Server Components Securing EJB Applications Overview of EJB Security A J2EE server provides two methods to implement security, which are authorization and authentication. Authorization Refers to the process where the J2EE server controls the access to the methods in an enterprise bean. Declarative: Involves using EJB container to grant or deny the permission for accessing the methods. Programmatic: Involves explicitly writing the code for granting or denying permissions.

Message-Driven Beans and EJB Security Lesson 4B / Slide 27 of 37 J2EE Server Components Securing EJB Applications (Contd.) Authentication Used to control access to the components in an application. The ways of classifying clients: Users Groups Realms Roles

Message-Driven Beans and EJB Security Lesson 4B / Slide 28 of 37 J2EE Server Components Securing EJB Applications (Contd.) Specifying EJB Security Requirements in Deployment Descriptor The application assembler defines the security roles in the deployment descriptor to allow specific clients to access the resources. The code snippet to define a security role in the deployment descriptor is: This role includes the customers of a bank. The role allows the customers to view and update their information. Customer

Message-Driven Beans and EJB Security Lesson 4B / Slide 29 of 37 J2EE Server Components Securing EJB Applications (Contd.) Accessing EJB Caller Security Context Bean provider uses the getCallerPrincipal() and the isCallerInRole() methods of the javax.ejb.EJBContext interface to retrieve information about a caller. The getCallerPrincipal() method returns an implementation of the java.security.Principal interface. The getName() method of the java.security.principal interface is used to retrieve the name of the caller.

Message-Driven Beans and EJB Security Lesson 4B / Slide 30 of 37 J2EE Server Components Securing EJB Applications (Contd.) Responsibilities for Implementing Security Bean provider Application Assembler Deployer EJB container System administrator

Message-Driven Beans and EJB Security Lesson 4B / Slide 31 of 37 J2EE Server Components Securing EJB Applications (Contd.) Responsibilities of the Bean Provider Use either programmatic or declarative method to specify the security attributes of an enterprise bean. Specify the names of the security roles in the tag of the deployment descriptor.

Message-Driven Beans and EJB Security Lesson 4B / Slide 32 of 37 J2EE Server Components Securing EJB Applications (Contd.) Responsibilities of the Application Assembler Defining the security roles, which have the permission to access the resources in an enterprise bean application. Defining the method permissions for accessing the methods in the home and the component interface of an enterprise bean. Linking the security role names in the tag to the role names specified in the tag of the deployment descriptor. Specifying the methods that need to be authorized prior to their invocation by the container. Specifying the methods that cannot be accessed by including them in the tag in the deployment descriptor.

Message-Driven Beans and EJB Security Lesson 4B / Slide 33 of 37 J2EE Server Components Securing EJB Applications (Contd.) Responsibilities of the Deployer Defining method permission for those methods that are neither present in the tag nor associated with any security role. Matching the security attributes specified in the deployment descriptor to their corresponding security domains, where the application deploys.

Message-Driven Beans and EJB Security Lesson 4B / Slide 34 of 37 J2EE Server Components Securing EJB Applications (Contd.) Responsibilities of EJB container Providing deployment tools to the deployer. Throwing the exceptions, java.rmi.RemoteException and javax.ejb.EJBException. Allowing the deployer to state whether the caller identity obtained from the getCallerPrincipal() method. Responsibilities of the System Administrator Creating a new user account. Adding a user account to a specific group. Removing a user account from a specific group. Deleting user account. Managing the security principals.

Message-Driven Beans and EJB Security Lesson 4B / Slide 35 of 37 J2EE Server Components Practice-Implementing Message- driven Bean to Receive Messages Problem Statement The management of Blue Valley organization wants to implement messaging system in their organization. Robert, a software developer, is assigned the task of developing the messaging application. He needs to create a message-driven bean that receives JMS-compliant messages from a client application and stores them in the server log file.

Message-Driven Beans and EJB Security Lesson 4B / Slide 36 of 37 J2EE Server Components Summary In this lesson, you learned: EJB  2.0 specification introduces a new type of bean known as message-driven beans. Message-driven beans are used for asynchronous messaging between two components of an EJB application. Message-driven beans act as the consumers of the messages that are sent by the clients capable of sending JMS-compatible messages. Message-driven beans contain a single business method, onMessage(), which is invoked on receiving a message. Message-driven bean contains the life cycle methods: ejbRemove(), ejbCreate(), and setMessageDrivenContext(). The life cycle of a message-driven bean consists of two stages, Does Not Exist and Ready.

Message-Driven Beans and EJB Security Lesson 4B / Slide 37 of 37 J2EE Server Components Summary (Contd.) The deployment descriptor of a message-driven bean is an XML file that specifies various features of the message-driven bean to the container. EJB security process involves allowing only authorized users to access the resources and applications. J2EE server provides two types of security, authentication and authorization. Application assembler defines the security roles that allow a client to access the resources. The application assembler uses the tag to define the security roles and the methods associated with each security role, in the deployment descriptor. Bean provider uses the getCallerPrincipal() and isCallerInRole() methods to check whether the current client has the right to perform the operation or not.