|
|
|
|
|
Realm
Action : tom.realm (Category : tom, Name : realm, By : kikonf)
Complete Name : tom.realm.by.kikonf Version : 4.0 License : Modified BSD License Purpose of the tom category : Easy to customize. This category use in background the Kikonf Repoz tools to create and configure Apache Tomcat ® root installs and Catalina bases at any level (server.xml, hosts or defaults). You can use it to manage the whole Tomcat ® Architecture. Purpose of this realm plugin : This Action configures a Tomcat Realm. The following shows the main Source Code File for the Action : tom.realm Toggle lines
## Copyright (c) 2008, Patrick Germain Placidoux
## All rights reserved.
##
## This file is part of Kikonf Public Software.
##
## Kikonf Public Software is released under the modified BSD License,
## which should accompany it or any part of it in the file "COPYING".
## If you do not have this file you can access the license
## through the WWW at http://www.kikonf.org/license/bsd/license.txt.
##
## Home: http://www.kikonf.org
## Contact: kikonf@gmx.com
REALMS={
'udb' : 'org.apache.catalina.realm.UserDatabaseRealm',
'mem' : 'org.apache.catalina.realm.MemoryRealm',
'jaas' : 'className="org.apache.catalina.realm.JAASRealm',
'jdbc' : 'org.apache.catalina.realm.JDBCRealm',
'datarsc' : 'org.apache.catalina.realm.DataSourceRealm',
'ldap' : 'org.apache.catalina.realm.JNDIRealm'
}
#-------------------#
# Utility functions #
#-------------------#
def checkUdbescIntegrity(udbrsc, level=0, indent=None, logFile=None):
# Checks udbesc integrity
print
print '# Checks udbesc integrity'
#:mount $target_scope_alias # get Steady
var datarsc_name=udbrsc
# check for a resource
print '#-- Does a Resource named:' + udbrsc + ' exists for the context ?'
%select name at Resource where name=${datarsc_name} and type=org.apache.catalina.UserDatabase
if len(ro)==0:
# check for a resourceLink
print '#-- Does a ResourceLink named:' + udbrsc + ' exists for the context ?'
%select name at ResourceLink where name=${datarsc_name} and type=org.apache.catalina.UserDatabase
if len(ro)==0:
verbose('Tomcat configuration inconsistency no Resource or ResourceLink found for referenced UserDatabase Resource:' + datarsc_name + ' ! Keep going on.', level=level, ifLevel=3, indent=indent, logFile=logFile)
return False
return True
def checkDatarscIntegrity(datarsc, level=0, indent=None, logFile=None):
# Checks datarsc integrity
print
print '# Checks datarsc integrity'
#:mount $target_scope_alias # get Steady
var datarsc_name=datarsc
# check for a resource
print '#-- Does a Resource named:' + datarsc_name + ' exists for the context ?'
%select name at Resource where name=${datarsc_name} and type=javax.sql.DataSource
if len(ro)==0:
# check for a resourceLink
print '#-- Does a ResourceLink named:' + datarsc_name + ' exists for the context ?'
%select name at ResourceLink where name=${datarsc_name} and type=javax.sql.DataSource
if len(ro)==0:
verbose('Tomcat configuration inconsistency no Resource or ResourceLink found for referenced JDBC DataSource Resource:' + datarsc + ' ! Keep going on.', level=level, ifLevel=3, indent=indent, logFile=logFile)
return False
return True
def injRealm(top_node, realm_node, realm, level=0, indent=None, logFile=None):
""" Creates a Realm """
realm_attrs=realm_node.getdAttrs()
if realm=='udb':checkUdbescIntegrity(realm_attrs['resourceName'], level=level, indent=indent, logFile=logFile)
elif realm=='datarsc':checkDatarscIntegrity(realm_attrs['dataSourceName'], level=level, indent=indent, logFile=logFile)
verbose('Realm:' + realm + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
attrs={}
attrs.update(realm_attrs)
attrs['digest']=top_node.getAttr('digest')
attrs['className']=REALMS[realm]
# creates
target_node.newNode('Realm', **attrs)
verbose('Realm:' + realm + ' Created.', level=level, ifLevel=3, indent=indent, logFile=logFile)
#------#
# Main #
#------#
# Stores the Action File's Processor Alias
var source_action_alias=ro['alias']
# Stores the Action File's First Node <=> self_action.getTop()
:ls
source_action_node=ro[0]
try:
## Retreives the Scope
print
print '## Retreives the Scope'
scope_name, scope_attrs, scope=self_action.getScope(parent_node=self_action.getTop(), indent=self_action.getIndent())
self_action.verbose(scope_name=scope_name, scope_attrs=scope_attrs)
indent=self_action.getIndent() + 3*' '
## Stores the target Scope Processor Alias and mount it
print '## Stores the target Scope Processor Alias and mount it'
var target_scope_alias=scope.pc_ro['alias']
:mount $target_scope_alias
:ls
target_node=ro[0]
realms=[]
# Intergrity check
for realm in REALMS:
if self_action.getTop().hasNode(realm):realms.append(realm)
if len(realms)==0:raise xception.kikonfActionSystemException(self_action, 'inject', 'At least on realm (in ' + str(REALMS)[1:-1] + ') is required !')
if len(realms)>1:raise xception.kikonfActionSystemException(self_action, 'inject', 'Over numbered Realms: only one realm is allowed ! Found: ' + str(realms)[1:-1] + '.')
if not scope_name.startswith('context') and scope_name not in ('engine', 'host'):raise xception.kikonfActionSystemException(self_action, 'inject', 'Bad Scope: ' + scope_name + ', Scope should be one of: "engine", "host" or "context" !')
realm=realms[0]
class_name=REALMS[realm]
## Destroys first
print
print '## Destroys first'
verbose('Realm: ' + realm + ' Removing.', level=self_action.getVerbose(), ifLevel=4, indent=indent, logFile=self_action.getLogFile())
var class_name=class_name
:rm Realm@className=${class_name}
#%delete Realm where className = ${class_name}
deleted_nodes=ro
if deleted_nodes!=None:n=len(deleted_nodes)
else:n=0
if n>0:verbose('Realm: ' + realm + ' Removed:' + str(n) + ' configuration Entry.', level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile())
## Creates the Realm
print
print '## Creates the Realm'
realm_node=self_action.getTop().getNode(realm)[0]
injRealm(self_action.getTop(), realm_node, realm, level=self_action.getVerbose(), indent=indent, logFile=self_action.getLogFile())
except Exception, e:
_e=xception.kikonfActionSystemException(self_action, 'inject', 'An exception occures ! SubException is:' + str(e) + ' !')
_e.setSubException(e)
REPOZ.recordSessionException(self_action.getName(), _e)
if self_action.getVerbose()>=10:raise
# Dont forget to skipt a strict empty line at the end to let the Interpretor to interprete the End of the bloc !
Trademarks :
|