1

The below code creates the datasource sucessfully but there is an exception when test connection is called. But when i restart the server and use the Test connection in console it works.

How to avoid server restart and make the test connection work in the script. I do have this error after the script is executed and before restart:

J2CA0130I: Data Source [nMINEDB] has Component-managed Authentication Alias [test/nMINEDBUser] but no corresponding J2C Authentication Data Entry is defined in security.xml. This may have undesirable effects.

Code:

#
# Jython Script to create MINE web data-source and JDBC provider. 
#

#Import Statements
import os
import re
import sys

# Create JDBC provider for MINE oracle database.
def createMINEJDBCProvider():
    server = '/Server:server1'
    # Set the Node ID
    serverID = AdminConfig.getid(server)
    print 'Server ID:' + serverID

    #Configuring J2c auth
    userAlias='test/nMINEDBUser'
        alias = ['alias', userAlias]
    userid = ['userId', 'MINEDB']
    password = ['password', 'MINEpass']
    jaasAttrs = [alias, userid, password]
    security = AdminConfig.getid('/Security:/')
    print 'security:'+security
    j2cUser=AdminConfig.create('JAASAuthData', security, jaasAttrs)
    AdminConfig.save()
    print 'Creating MINE User sucessfull'

    # Test to see if the provider has already been created.
    MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:nOracle JDBC Driver/')
    if len(MINEJDBCprovider) == 0:
        providerName='nOracle JDBC Driver'
        print 'creating Oracle JDBC provider on server:'+serverID
        print 'JDBC provider Name:'+providerName
        MINEJDBCprop1 = ['name', providerName]
        MINEJDBCprop2 = ['description','Oracle JDBC Driver for MINE Application']
        MINEJDBCprop3 = ['implementationClassName','oracle.jdbc.pool.OracleConnectionPoolDataSource']
        MINEJDBCprop4 = ['classpath','C:/jars/ojdbc/ojdbc6.jar']
        MINEJDBCprops=[MINEJDBCprop1,MINEJDBCprop2,MINEJDBCprop3,MINEJDBCprop4]
        providerID = AdminConfig.create('JDBCProvider', serverID, MINEJDBCprops)
        AdminConfig.save()
        print 'Creating Oracle JDBC provider on server sucessfull with provider:'+providerID
        createMINEDataSource()
    else:
        print 'oracle provider exists:'+MINEJDBCprovider


def createMINEDataSource():
    providerName='nOracle JDBC Driver'
    userAlias='test/nMINEDBUser'
    MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:nOracle JDBC Driver/')
    MINEDataSource = AdminConfig.getid('/JDBCProvider:'+providerName+'/DataSource:MINEDB/')
    if len(MINEDataSource) == 0:
        # Set the datasource attributes
            MINEDSprop1 = ['name', 'nMINEDB']
            MINEDSprop2 = ['jndiName', 'jdbc/nMINEdb']
            MINEDSprop3 = ['description', 'MINE database']
            MINEDSprop4 = ['datasourceHelperClassname', 'com.ibm.websphere.rsadapter.Oracle11gDataStoreHelper']
            MINEDSprop5 = ['authDataAlias' , userAlias]
            mapConfigprop=["mappingConfigAlias", "DefaultPrincipalMapping"] 
        mapConfigs=[MINEDSprop5 , mapConfigprop] 
        mappingConfig=["mapping", mapConfigs]

            MINEDSprops = [MINEDSprop1, MINEDSprop2, MINEDSprop3, MINEDSprop4, MINEDSprop5, mappingConfig]
            MINEDataSource = AdminConfig.create('DataSource', MINEJDBCprovider, MINEDSprops)

            #Set the DB URL
            propSet = AdminConfig.create('J2EEResourcePropertySet', MINEDataSource, [])
            AdminConfig.create('J2EEResourceProperty', propSet, [["name", "URL"], ["value", "jdbc:oracle:thin:@myserver:1523:MINED2"]])

            AdminConfig.save()


                        print 'Creating MINE JDBC Datasource on server sucessfull with datasource:'+MINEDataSource

        #Mapping module not trying right now
        #AdminConfig.create('MappingModule', MINEDataSource, mappingConfig)



    else:
        print 'MINE Datasource already exists in the server:'+MINEDataSource
    print 'Testing datasource connection'
    print AdminControl.testConnection(MINEDataSource)

try:

    print 'start'
    createMINEJDBCProvider()
    createMINEDataSource()
    print 'end'
except:
    print "***** Unexpected error while creating JDBC datasource:", sys.exc_info(), " *****"
    raise

1 Answer 1

1

j2c authentication isn't initialized until the server is recycled.

2
  • I generally use wsadmin for my scripts as I am not familiar with how the jython scripts are done. However I have seen that when you create a new j2c authentication and use it with a new datasource a recycle of the jvm or node sync is required. I have tested this multiple times, the datasource will throw a j2c authentication error unless a recycle/node sync is done.
    – ssalih
    May 8, 2015 at 14:54
  • So the only way is as i have done in my code to restart the server, so is this a bug @Websphere.
    – Vishnu
    May 11, 2015 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.