Java AppServer-01: Intro Application Server

September 15th, 2009 by Enrique Leave a reply »

Now we have an RPC service can be used as the basis for implementing an application server, but only an RPC service is not enough. Therefore, we will implement these modules / services:

  • Security: authorization, authentication and auditing

  • Pool of connections to the database

  • Asynchronous messaging service

And, besides having an API to add services, the server will provide an API to add user modules. Now the server component diagram:

Diagrama de componentes

Component Diagram

The components of the upper layer uses functionality of the components of the bottom layer. Now let's explore each of the components.

Security realms manager

This is mandatory in any AppServer. In the Realms Security Manager installs the security realms. What is a security realm? Conceptually it is a component that controls access to services. From the technical point of view, is the implementation of the interface:

 SecurityRealm public interface {/ ** * The login method.  * @ Param credentials The credentials to validate * @ throws LoginException If an exeption ocurrs DURING login * / void login (Credentials credentials) throws LoginException; / ** * The logout method.  * @ Param credentials The credentials * / void logout (Credentials credentials) / ** * This method returns true if and only if the service's method * Can Be Executed With The Given credentials.  * * @ Param credentials the credentials of the executing user * @ param serviceName the service name * @ param methodName the method name to execute * @ param params the paramenters to pass to the method * @ throws NotExecutedException That signals the execution is not allowed for Given the credentials, serviceName, methodName and params * / void executionAllowed (Credentials credentials, String serviceName, String methodName, Object ... params) throws NotExecutedException;} 

There are only three methods: login, logout and isExecutionAllowed. The first two relate to the concept of authentication and the third refers to the concept of release, but can also be associated to audit and which is always executed before the invocation of the service.

The security manager uses the interceptor realms that appear in Java RPC-07: in the method onPreExecution () method is called executionAllowed () in the security realm and continues execution if this exception does not NotExecutedException. For security reasons, does not run if there is any exception (or error) in the executionAllowed () and so prevents a bug break the security system.

Then placing arbitrary code executionAllowed method () can authorize or prohibit the execution of a method of a service with certain parameters.

The security realms manager manages a collection of security realms. They run all and only authorized taken for the call if all authorized. The security server has implemented an abstract realm that is based on username and password and other security realm for auditing (logging).

  public abstract class extends AbstractUserPasswordSecurityRealm SecurityRealmAdapter {

     public AbstractUserPasswordSecurityRealm () {
     }

     public void login (Credentials c) throws LoginException {
         UserPasswordCredentials cred = (UserPasswordCredentials) c;
         if (cred! = null) {
             Cred.getUser String user = ();
             Cred.getPassword String pass = ();
             validate (user, pass);
         Else {}
             throw new LoginException ("null credentials");
         }
     }

     public void executionAllowed (Credentials credentials, String serviceName, String methodName, Object ... params) throws NotExecutedException {
         if (credentials == null) {
             throw new NotExecutedException ("not logged in");
         }
     }

     public abstract void validate (String user, String pass) throws LoginException;
 } 

Module manager

As we saw, the server is extensible. But how? By modules. A module is just a bean that has a name and two methods for managing the life cycle: startup () and shutdown (). Then, the server has a method to get the module name. As the interface is so simple, easily adapted to incorporate any service to the server. For example, asynchronous messaging service implemented separately and created a module to suit this application server. Ditto with the pool of connections to the database. The interface:

  Module {public interface
     void setName (String name);
     String getName ();

     void startup () throws Exception;
     void shutdown ();
 } 

For a module from a service, we ask the ServerContext:

ServerContext.getModule (moduleName);

The class nuclear ServerContext a set of static methods that provide access to different parts of the application server. Those who are most GetModule desatacan () and getServerConfig (). The first one we saw. The second returns a map with properties that are loaded from a configuration file. We'll see the configuration in a section devoted to it.

Loader Services

This is the component responsible for reading a configuration file and create services in the PRC. It is implemented as a module and can be easily replaced by another and attached to the server. Basically reads a configuration file describing the services and adds parameters to the server.

In the next article I will describe the pool of connections to the database and messaging service. I will also describe the configuration files.

Until next time.

Blogger Post Digg Reddit Google Reader Share
Advertisement

Leave a comment

Spam protection by WP Captcha-Free