Java Reference
In-Depth Information
14.2 Example: managing user logins
Now that we have discussed some ways of using JMX with Enterprise JavaBeans,
let's develop some examples. A friend called us recently with the following inter-
esting dilemma, which can be resolved through the use of JMX .
14.2.1
The problem
Our friend was building an enterprise system that provided inventory tracking.
He was working with an EJB system that uses entity beans to work with the appli-
cation data. The EJB s ran in a J2EE -compliant container, and he provided a UI via
a web browser. In addition, session beans provided the link between the user
interface and the entity beans.
To ensure that a user could not log in from two browsers simultaneously, our
friend needed a way to track the number of times a particular user attempted to
log in to the system. In addition, he wanted to be able to enable or disable the
login rights for a particular user. This capability lets an application administra-
tor manage the set of users that can log in to the application.
Our friend had decided to write additional functionality into the system to
create an administration application, but then did not have the time or desire to
do so.
14.2.2
The JMX solution
Combining MBeans with entity EJB s can easily solve this problem. The next sev-
eral sections construct an example to solve our friend's problem.
First, you will need to build an entity bean that tracks the number of logins
for a user and is capable of disabling or enabling the user's account. Then, you
can build an MBean that uses the entity EJB to retrieve the number of logins for
a user, or to disable and enable a user account. In essence, the MBean will expose
the entity bean's business methods as a management interface.
From the management console (the web browser), our friend will then be able
to query user login attempts and get and set a user's permissions.
To simplify this example, you will not build the persistence mechanism,
but will rely on the activate and passivate capabilities of the EJB contain-
er to persist your data. If you would like to learn more about building
persistence in EJB s, begin by looking at some of the examples provided
in the JBoss server's free distribution.
NOTE
Search WWH ::




Custom Search