Monday, August 17, 2009

Create J2C authentication alias and assign to database

Here you can create a J2C authentication alias and then assign it to a database.

# create a new J2C authentication entry
# set the security object
set security_root [$AdminConfig list Security]
# set the attributes for the new object
set auth_alias [list alias "$alias"]
set auth_descr [list description "Login for 4.0 Application"]
set auth_userId [list userId "$username"]
set auth_password [list password "$password"]
# put the new object together
set auth_entry [list $auth_alias $auth_descr $auth_userId $auth_password]
# create the new object
$AdminConfig create JAASAuthData $security_root $auth_entry
# saving the configuration
$AdminConfig save
puts "Created J2C Authentication Alias for $application"


# sets the new auth alias to TheDatabase

set ds_arg $YourDatabaseName
set alias_arg $YourDatabaseAlias
set datasources [$AdminConfig list DataSource]
foreach datasource $datasources {if {[regexp $ds_arg $datasource]} { set datasource_root $datasource; break }}
set datasource_root
$AdminConfig modify $datasource_root [list [list authDataAlias $alias_arg]]
$AdminConfig save
puts "Set the J2C Authentication Alias for $YourDatabaseName"