The User Manager service is designed to be a component in an SOA application. It can be used in an SOA application to provide user management functions. It is designed to be deployed in the Axis2 engine as a SOAP service. The user manager service can be configured to perform different functions by adding parameters to axis2.xml of the Axis2 server. For example, it can be configured to talk to an RDBMS or a JNDI user store by adding parameters to the axis2.xml.
There are many advantages of using the User Manager in an SOA application.
The user manager service can be configured to,
org.wso2.commons.usermanager.elements.User.java

The source code of the User Manager Service is available at http://wso2.org/repos/wso2/trunk/commons/usermanager/
First this tutorial describes the basic usage, i.e., how to add, edit, delete, and authenticate users in the built-in database of the User Manager. The default built-in database will store only the username and password of the user.
Then the tutorial gives a pointer to the client API.
The next section of the tutorial focuses on how to configure the user manager. The user manager's power is in its configurations. It can be configured to read and write into any new or existing LDAP or RDBMS user store. Configuration is done by adding parameters/values into axis2.xml. The tutorial describes how to configure the three built-in realms. These descriptions are followed by the most powerful option of all, which is coding your own custom realm.
The user manager is shipped with the capabilities to manage a simple user, which stores only the username and password. It is configured to use a Derby database named “UserDatabase”, which has a single table with the columns User name and Password.
Download and build the User Manager.
mvn clean install. This will create a UserMan.aar in the modules/userman-service/target directory.
Windows users please execute the create_default_db.bat command in the command prompt.
create_default_db.shThese scripts will create a directory named "UserDatabase" in the current directory. This is the database.
Find the axis2.xml file of your Aixs2 server. If you are running the Axis2 standalone server, then the axis2.xml is available inside Axis2_HOME/repository/conf. If you are using Tomcat, it is inside the “conf” directory.
Add the following parameter, where “dbpath” is the complete path to your database.
<parameter name="userman.connection.url">jdbc:derby:/dbpath/UserDatabase</parameter> If this parameter is not present, then a “NullPointer Exception” will be thrown from the server.
Congratulations!! Now the User Management service is working.
Methods in the Axis service can be invoked by using the User Manager client API. Therefore, the application only sees a simple set of methods, and the complexity is handled by the user manger client. Developers must provide the end point address and the invocation parameters. Please refer to the API: org.wso2.commons.usermanager.client.UserManagerClient
When reading parameters, the first priority is given to the axis2.xml, i.e., if the parameters are not present in the axis2.xml then the default parameters are loaded or else a UserManager exception will be thrown. |
Available parameters and their description. The next section describes how to use the parameters in detail.
Parameter Name | Usage | Description |
|---|---|---|
userman.userbase.driver_type | Type of connection to the Userstore
| Indicates the type of connectivity to the user store. When using JDBC ( default), When using JNDI, For hibernate, |
| userman.connection.url | JDBC/JNDI | Connection URL For JNDI ldap: //host-ip:port Normally port is 389. For JDBC MySQL jdbc:mysql://localhost/ database_name For JDBC Embedded derby jdbc:derby:path/database_name |
| userman.connection.name | JDBC/JNDI | The username used when UserManager creates the connection to the JNDI or JDBC |
| userman.connection.pass | JDBC/JNDI | Password of the connection |
userman.jdbc.driver | Mandatory for JDBC | Indicates the JDBC driver class. When using MySQL, |
userman.jdbc.user_table | Mandatory for JDBC | Name of the user table |
userman.jdbc.username_col | Mandatory for JDBC | Name of the username column in the user table |
userman.userclass | Indicates the user class. JDBC/JNDI/Hibernate | The default value is, |
userman.user.fields
| JDBC/JNDI | Comma separated list of attributes of the user object. Used with the parameter “userman.user.binding” to show the mapping. Please refer to step2 in Configuring the User Manager |
userman.user.binding | JDBC/JNDI | Shows the mapping between object attributes and user store attributes. Used with “userman.user.fields” to show the mapping. Please refer to step2 in Configuring the User Manager |
| userman.jndi.digest_algo | Mandatory when using JNDI | Digest algorithm of the password attribute in the LDAP directory. |
| userman.jndi.password_attrId | Mandatory when using JNDI | Attribute ID of the password. |
| userman.jndi.user_pattern | Mandatory when using JNDI | User pattern to be used when searching for users. |
The user manager is configured using two main steps. They are:
Step 1 : Picking a user implementation. This step must be carried out by the application developer, because he is the one who knows what information of the user is needed.
Step 2: Configuring the user store. You can connect to a user store using one of the following three approaches.
This step is carried out by the system administrators at the user end. If this step is carried out by the application developer, it will limit the flexibility.
Now let's look us these two steps in detail.
org.wso2.commons.usermanager.elements.User.javaThe following is an example. This is the default implementation packaged in the user manager. It is a very basic user class which stores the username and password.
org.wso2.commons.usermanager.elements.impl.UserBase
If you need to read or write more information from the user store, include more attributes in the class.
This is how you indicate a custom user in axis2.xml
<parameter name="userman.userclass">org.wso2.some.service.MyUser</parameter>
The user manager can be configured to use existing or new databases from different vendors. This is handled by the JDBC realm of the user management service, which is the default method. A JDBC realm can add, edit, and delete users and it can also execute SQL statements on a set of users and return an array of users.
The user manager must know how to load and store user objects in the correct database. You have to indicate this data in the axis2.xml file.
The URL of the database must be given in the axis2.xml. If “dbpath” is the path to the database, then the connection URL would be,
<parameter name="userman.connection.url">jdbc:derby:dbpath/UserDatabase </parameter>
<parameter name="userman.jdbc.username_col">username</parameter>
<parameter name="userman.jdbc.user_table">users</parameter>
<parameter name="userman.user.fields">status, name, password</parameter>
<parameter name="userman.user.binding">status, username, pass</parameter>
Now the User Manager Service is up and running with a custom user and its mapping database.
The user manager can be configured to use the company's existing LDAP directory or a new LDAP directory. This is handled by the JNDI realm of the user manager. It cannot add users in the LDAP directory, but it can read, delete users, and also modify their attributes. LDAP directories have a standard set of digest algorithms. Currently, the user manager assumes that all passwords are digested using a single algorithm.
<parameter name="userman.userbase.driver_type">org.wso2.commons.usermanager
.realm.generic.GenericJNDI</parameter>
userman.connection.name - ldap://host-ip:port port is normally 389
userman.connection.pass - username to make the connection to the database
userman.connection.url- password of the connection
<parameter name="userman.user.fields">status, name, password</parameter>
<parameter name="userman.user.binding">status, username, pass</parameter>
<parameter name="userman.jndi.user_pattern">uid={0},ou=People,dc=wso2,dc=or</parameter>
The user manager can be configured to use hibernate for object relational mapping. Hibernate is a mature ORM technology, but the user manager provides a very basic implementation. You can always write your own custom hibernate realm using a preferred session/transaction management architecture.
Please refer to Coding a Custom Realm on how to code your own realms. This implementation creates a hibernate session per Web service call.
<parameter name="userman.userbase.driver_type">org.wso2.commons.usermanager.realm.generic.
HibernateRealm</parameter>
Name the file with the suffix hbm.xml and specify it in axis2.xml using the parameter "userman.hibernate.cfg_file". Refer to http://www.hibernate.org for how to write a hibernate config file.
If you are using a JDBC driver other than MySQL and Derby, you have to add it to the classpath.
The user manager has a plug-in architecture, which enables you to write your own realm. If you are not satisfied with the three built-in realms, you can code your own realm by following these steps.
org.wso2.commons.usermanager.realm.generic.UserBaseDriver The three built-in realms in the user manager also implement this interface.userman.userbase.driver_type. Let your class be “my.CustomRealm”. Then in axis2.xml, specify the following:
<parameter name="userman.userbase.driver_type">my.CustomRealm</parameter>
The key feature of the user manager is that it can be configured to talk to existing user stores and all the finer details will be transparent to your application. When requirements arise, new realms will be added to the user manager other than to the starting built-in realms. In the future, the User Manager will support user roles as well.
Dimuthu Leelarathne, Senior Software Engineer - WSO2 Inc. dimuthul at wso2 dot com
marc jacobs handbags