Authentication using an external database
For that you can use an external database for member authentication, you have to do three things:
- Provide a view of the member information stored in the external database and map the member object's attributes the the fields of this view.
- Configure the connection to the external database.
- Tell the system to use the org.hip.vif.member.external bundle to authenticate.
1. Mapping
To map the member object's attributes to the table's or view's fields, you have to create a XML file with the name 'MEMBEROBJECTDEF.xml' and place it in $TOMCAT_HOME/webapps/vifapp/WEB-INF/conf/.
The view has to provide the following information:
Attribute | Description | Type | |
ID | Unique ID identifying the member entry. | Number | mandatory |
UserID | The member's user name. | String | mandatory |
Name | The member's family name. | String | mandatory |
Firstname | The member's firstname. | String | mandatory |
The member's mail address. | String | mandatory | |
Password | The member's password. The password has to be encrypted using the Unix encryption. | String | mandatory |
Sex | The member's sex. The values have to be coded as follows: male=0, female=1. | Number | optional |
City | The city the member's living. | String | optional |
Street | The street the member's living. | String | optional |
ZIP | The postal code of the member's address. | String | optional |
Tel | The member's phone number. | String | optional |
Fax | The member's fax number. | String | optional |
Let's assume you have a member table in an external database having the following structure:
CREATE TABLE tblExtMember ( ExtMemberID int unsigned not null auto_increment, sMyUserID varchar(20) not null, sMyName varchar(50) not null, sMyFirstname varchar(50), sMyMail varchar(50), bMySex tinyint not null default 0, sMyPassword varchar(70), PRIMARY KEY (ExtMemberID) );
For that you can access the information stored in this table's fields, you have the map the model object's attributes to the table's fields. This mapping is done in MEMBEROBJECTDEF.xml which is the Object Definition XML of our external Member model. In our case, the mapping XML file will look as follows:
<?xml version='1.0' encoding='ISO-8859-1'?> <objectDef objectName='Member' parent='org.hip.kernel.bom.DomainObject' version='1.0'> <keyDefs> <keyDef> <keyItemDef seq='0' keyPropertyName='ID'/> </keyDef> </keyDefs> <propertyDefs> <propertyDef propertyName='ID' valueType='Number' propertyType='simple'> <mappingDef tableName='tblExtMember' columnName='ExtMemberID'/> </propertyDef> <propertyDef propertyName='UserID' valueType='String' propertyType='simple'> <mappingDef tableName='tblExtMember' columnName='sMyUserID'/> </propertyDef> <propertyDef propertyName='Name' valueType='String' propertyType='simple'> <mappingDef tableName='tblExtMember' columnName='sMyName'/> </propertyDef> <propertyDef propertyName='Firstname' valueType='String' propertyType='simple'> <mappingDef tableName='tblExtMember' columnName='sMyFirstname'/> </propertyDef> <propertyDef propertyName='Mail' valueType='String' propertyType='simple'> <mappingDef tableName='tblExtMember' columnName='sMyMail'/> </propertyDef> <propertyDef propertyName='Sex' valueType='Number' propertyType='simple'> <mappingDef tableName='tblExtMember' columnName='bMySex'/> </propertyDef> <propertyDef propertyName='Password' valueType='String' propertyType='simple'> <mappingDef tableName='tblExtMember' columnName='sMyPassword'/> </propertyDef> </propertyDefs> </objectDef>
The key elements are the propertyDef nodes with the mappingDef childs. With the propertyDef's propertyName attribute you specify the model's attribute that has to be mapped. With the mappingDef's tableName and columnName attributes, you can fully qualify the mapping counterpart in the table.
The property providing the information about the members' sex is optional. Therefore, you could omit this property without compromising the application's functionality.
2. Connection configuration
You configure the connection to the external database the same way you configure the connection to the VIF database through the application's configuration. Connection configuration is done with the following settings:
- ext. database: driver
- Select the driver to connect to the external database containing the table or view with the member data.
- ext. database: server
- The DNS or IP address of the database server running the external database.
- database/schema
- The schema on the external database containing the table or view with the member data.
- username
- The username to access the external database schema.
- password
- The password to access the external database schema.
3. Activating the org.hip.vif.member.external authenticator
Select the org.hip.vif.member.external authenticator on the application's configuration page.