Instructions for DB2
-------------------------------

Database Setup
-------------------------------
Uncomment the following lines in createTables.sql.
-- CREATE DATABASE OAUTH2DB USING CODESET UTF8 TERRITORY US;
-- CONNECT TO OAUTH2DB;

If you want to use another database user than DB2 administrator, create a new OS account, i.e dbuser,
and uncomment the following lines. The dbuser's account and password will be used when creating J2C 
alias on WebSphere for datasource.
-- GRANT ALL ON OAuthDBSchema.OAUTH20CACHE TO USER dbuser;
-- GRANT ALL ON OAuthDBSchema.OAUTH20CLIENTCONFIG TO USER dbuser;

Execute the following command with DB2 administrator user.
db2 -tvf createTables.sql

The default DB2 listening port is 50000. If you want to find it out, execute the following command and 
find the value of SVCENAME parameter. If it is a number, then it is the port number. If it is a name, 
look for the name in the /etc/services file (or Windows equivalent if using Windows). 
(Linux/Unix) db2 get dbm cfg | grep SVCENAME 
(Windows) db2 get dbm cfg | findstr SVCENAME 

WebSphere Configuration
-----------------------

Go to Resources->JDBC->JDBC Providers. 
* Pick a scope (server is what I used) 
* Click New. Wizard will start. 
* Select: 
    Database Type = DB2. 
    Provider Type: DB2 Universal JDBC Driver Provider. 
    Implementation Type: Connection pool data source 
* Click Next. 
* Set: 
    DB2_UNIVERSAL_JDBC_DRIVER_PATH = /home/ldapdb2/sqllib/java 
    DB2_UNIVERSAL_JDBC_DRIVER_NATIVEPATH = /home/ldapdb2/sqllib/lib 
* Click Next, then Finish. 
* Save the config. 


Go to Security->Secure administration, applications and infrastructure->Java Authentication and Authorization Service->J2C authentication data 
* Click New. 
* Set: 
    Alias: oauthalias 
    UserID: dbuser   <===== This is the operating system user we created originally.
    Password: That user's password. 
* Click OK. 
* Save Config. 


Go to Resources->JDBC->Data Sources. 
* Pick a scope (server is what I used) 
* Click New. Wizard will start. 
* Set: 
    Data source name: OAuth JDBC Service 
    JNDI Name: jdbc/OAuth2DB 
    Component-managed authentication alias: Should be <scope>/oauthalias 
* Click Next. 
* Select an existing JDBC Provider. Should be the DB2 Universal JDBC Driver Provider. 
* Click Next. 
* Set: 
    Database name: OAuth2DB 
    Driver type: 4 
    Server name: <DB2 server> - maybe localhost 
    Port number: <See the comments on SVCNAME above> 
    Container Managed Persistence: Checked 
* Click Next, Finish. 
* Save the config. 
You can now test the connection, and the component should work when configured with the JDBC plugins for OAuth. 

Eg client add:
INSERT INTO OAuthDBSchema.OAUTH20CLIENTCONFIG (COMPONENTID, CLIENTID, CLIENTSECRET, DISPLAYNAME, REDIRECTURI, ENABLED) VALUES ('1', 'key', 'secret', 'My Client', 'https://localhost:9443/oauth/redirect.jsp', 1)

Finally don't forget to change your component configuration class to use the 
JDBC plugins classnames for the client provider and token cache. There is an
example of how to do this in the com.ibm.oauth.examples.config.OAuthComponentConfigurationTestImpl class.

Tomcat Configuration
-----------------------
Copy DB2 JDBC drivers to the lib folder of Tomcat installation directory. DB2 JDBC drivers can be found at /home/ldapdb2/sqllib/java, 
specifically, you need to copy db2jcc.jar and db2jcc_license_cu.jar.

To create a datasource, open context.xml file in $CATALINA_HOME$/conf and add datasource declaration 
like the followings:
	<Resource name="jdbc/OAuth2DB" auth="Container" type="javax.sql.DataSource"
               driverClassName="com.ibm.db2.jcc.DB2Driver"
               url="jdbc:db2://localhost:50000/OAuth2DB"
               username="dbuser" password="pwd_to_dbuser" />
Here we assume DB2 server is localhost and DB2 port is 50000.           
Refer to Tomcat documentation for more details. 