Hi,
Thanks to Sanjay for asking a very good query. In Response to Sanjay’s Comment on SQLAuthenticator.
http://middlewaremagic.com/weblogic/?p=2034#comment-2838 with Form Based Authentication.
Here we are going to see a very Simple example of Using FormBased Authentication of demo. But in this case we won’t use the WebLogic’s default Authenticator provider, Rather we will create a separate SQL Authenticator provider inside the Security Realm and the we will insert some Users information in the Database so that we can validate the Database users using our FormBased Authentication technique.
Step1). Create the following Tables “USERS”, “GROUPS” and “GROUPMEMBERS” with exactly same Data Definition as mentioned below:
CREATE TABLE USERS ( U_NAME VARCHAR(200) NOT NULL, U_PASSWORD VARCHAR(50) NOT NULL, U_DESCRIPTION VARCHAR(1000)); ALTER TABLE USERS ADD CONSTRAINT PK_USERS PRIMARY KEY (U_NAME); CREATE TABLE GROUPS ( G_NAME VARCHAR(200) NOT NULL, G_DESCRIPTION VARCHAR(1000) NULL); ALTER TABLE GROUPS ADD CONSTRAINT PK_GROUPS PRIMARY KEY (G_NAME); CREATE TABLE GROUPMEMBERS ( G_NAME VARCHAR(200) NOT NULL, G_MEMBER VARCHAR(200) NOT NULL); ALTER TABLE GROUPMEMBERS ADD CONSTRAINT PK_GROUPMEMS PRIMARY KEY ( G_NAME, G_MEMBER ); ALTER TABLE GROUPMEMBERS ADD CONSTRAINT FK1_GROUPMEMBERS FOREIGN KEY ( G_NAME ) REFERENCES GROUPS (G_NAME) ON DELETE CASCADE;
Step2). Insert the following records in the Above Tables.
insert into USERS values('weblogic','weblogic','This is an Admin User with username weblogic, password weblogic'); insert into GROUPS values('Adminsitrators','This is an Administrators Group'); insert into GROUPMEMBERS values('Adminsitrators','weblogic');
Step3). Create a DataSource baed on whetever dataSource you want to chose. I created a Simple DataSource like following “$DOMAIN_HOME/config/jdbc/SQLAuthDS-8981-jdbc.xml”:
<?xml version='1.0' encoding='UTF-8'?> <jdbc-data-source xmlns="http://www.bea.com/ns/weblogic/jdbc-data-source" xmlns:sec="http://www.bea.com/ns/weblogic/90/security" xmlns:wls="http://www.bea.com/ns/weblogic/90/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/jdbc-data-source http://www.bea.com/ns/weblogic/jdbc-data-source/1.0/jdbc-data-source.xsd"> <name>SQLAuthDS</name> <jdbc-driver-params> <url>jdbc:oracle:thin:@10.65.209.158:1521:xe</url> <driver-name>oracle.jdbc.OracleDriver</driver-name> <properties> <property> <name>user</name> <value>SYSTEM</value> </property> </properties> <password-encrypted>{3DES}sUnlI08xXhw=</password-encrypted> </jdbc-driver-params> <jdbc-connection-pool-params> <test-table-name>SQL SELECT 1 FROM DUAL</test-table-name> </jdbc-connection-pool-params> <jdbc-data-source-params> <jndi-name>SQLAuthDS_Jndi</jndi-name> <global-transactions-protocol>OnePhaseCommit</global-transactions-protocol> </jdbc-data-source-params> </jdbc-data-source>
And inside your “config.xml” file you will see DataSource file entry ike following:
<jdbc-system-resource> <name>SQLAuthDS</name> <target>AdminServer</target> <descriptor-file-name>jdbc/SQLAuthDS-8981-jdbc.xml</descriptor-file-name> </jdbc-system-resource>
Step4). Now login to Admin Console and create the SQL Authenticator Provider like following:
Home ———)Summary of Security Realms —————-)myrealm ——————)Providers (Tab) Click “New” button
Provider Name: MySQLAuthenticatorProvider
Provider Type: SQL Authenticator
Now Click On your ProviderName “MySQLAuthenticatorProvider” and go to “Provider Specific” (Tab) and then select the following values:
Plaintext Passwords Enabled (Check this Check Box)
Data Source Name: SQLAuthDS
Group Membership Searching: unlimited
Rest of the things will be as it is Default.
Step5). Now Go to Security Realm and the do the following:
Home——————)Summary of Security Realms ——————)myrealm ——————)Providers ——————) DefaultAuthenticator (click) Now Change it’s “Control Flag” to “OPTIONAL”
Save above Changes.
Step6). Now again Go to Security Realm and the do the following:
Home——————)Summary of Security Realms——————)myrealm ——————)Providers——————) MySQLAuthenticatorProvider (click) Now Change it’s “Control Flag” to “REQUIRED”
Save above Changes.
Step7). Now restart your Server so that the Changes will take effect (Make Sure that the Database is running).
====================Form Based Authentication Below======================
Step8). Now insert some more records in the database:
insert into USERS values('testuser','testpassword','This is an testuser User with username testuser, password testpassword'); insert into GROUPS values('testgroup','This is an test Group'); insert into GROUPMEMBERS values('testgroup','testuser');
Step9). Now use the Following FormBased Authentication Program to deploy on the WebLogic Server: http://middlewaremagic.com/weblogic/?p=2034
Step10). Now Deploy the Above Application On the Server and test it.
username: testuser
password: testpassword
Thanks
Jay SenSharma