home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
custsechan.tcl
< prev
next >
Wrap
Text File
|
1997-10-10
|
9KB
|
332 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)custsechan.tcl /main/titanic/4
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)custsechan.tcl /main/titanic/4 10 Oct 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
require custfileut.tcl
# End user added include file section
Class CustSecHandler : {Object} {
constructor
method destructor
method initialize
method readFile
method readRoles
method readUserRoles
method addRoles
method addUsers
method addUserRoleLinks
method setAccess
method updateAccess
method getAllowedMap
method setAllowedMap
method removeAllowedMap
attribute roleInfo
attribute userRoleInfo
attribute roleList
attribute userList
attribute showProjectInfo
attribute corporate
attribute project
attribute config
attribute allowedMap
}
constructor CustSecHandler {class this name} {
set this [Object::constructor $class $this $name]
$this allowedMap [Dictionary new]
# Start constructor user section
[$this allowedMap] contents [list \
M 1 \
C [expr 2|32] \
R 8 \
U [expr 16|128|256|512] \
D [expr 4|64] \
]
set cc [ClientContext::global]
$this showProjectInfo 1
$this corporate [$cc currentCorporate]
$this project [$cc currentProject]
$this config [$cc currentConfig]
# End constructor user section
return $this
}
method CustSecHandler::destructor {this} {
# Start destructor user section
# End destructor user section
}
method CustSecHandler::initialize {this} {
if [$this showProjectInfo] {
puts "Project : [[$this project] name]"
$this showProjectInfo 0
} else {
puts ""
}
puts "Configuration: [[$this config] text]"
set warning 0
foreach phaseV [[$this config] phaseVersions] {
if {! [lempty [$phaseV systemVersions]]} {
if {! $warning} {
puts ""
}
wmtkwarning "WARNING: Phase '[[$phaseV phase] name]' is not empty"
set warning 1
}
}
if $warning {
puts ""
wmtkwarning "WARNING: Changing the access rights within a non-empty \
PhaseVersion could make\naccess control for the current users of \
that PhaseVersion very complicated."
puts -nonewline "Do you want to Continue ? \[n\]: "
flush stdout
set answer [string tolower [gets stdin]]
puts ""
if {"$answer" != "y"} {
return "stop"
}
}
set errorMsg "[$this readRoles]"
if {"$errorMsg" != ""} {
return "$errorMsg"
}
set errorMsg "[$this readUserRoles]"
if {"$errorMsg" != ""} {
return "$errorMsg"
}
return ""
}
method CustSecHandler::readFile {this fileName} {
set contents [CustFileUtilities::contents "" $fileName $fileName]
if [lindex $contents 0] {
set contents [lindex $contents 1]
} else {
set cc [ClientContext::global]
if [catch {
set contents [$cc getCustomFileContents $fileName $fileName etc]
}] {
resetErrorVars
set etcDir [path_name concat [path_name directory [pwd]] etc]
set file [open [path_name concat $etcDir $fileName $fileName]]
set contents [read $file]
close $file
}
}
set lines {}
foreach line [split $contents "\n"] {
set first [string index $line 0]
if {$first == "" || $first == "#"} continue
lappend lines $line
}
return $lines
}
method CustSecHandler::readRoles {this} {
set roleInfo {}
set roleList {}
foreach line [$this readFile roles] {
set triple [split $line '|']
set len [llength $triple]
if {$len != 3} {
return "\
syntax of configuration file 'roles' invalid:\n\
line '$line' contains $len parts"
}
set roleName [string trim [lindex $triple 0]]
set phaseName [string trim [lindex $triple 1]]
set accessList [string trim [lindex $triple 2]]
foreach access $accessList {
case "$access" in {
{M m C c R r U u D d} {}
default {
return "\
syntax of configuration file 'roles' invalid:\n\
line '$line' contains invalid access '$access'"
}
}
}
if {! [info exists role($roleName)]} {
set role($roleName) 1
lappend roleList "$roleName"
}
lappend roleInfo [list "$roleName" "$phaseName" "$accessList"]
}
$this roleInfo $roleInfo
$this roleList $roleList
return ""
}
method CustSecHandler::readUserRoles {this} {
set userRoleInfo {}
set userList {}
foreach line [$this readFile userroles] {
set userInfo {}
set tuple [split $line '|']
set len [llength $tuple]
if {$len != 2} {
return "\
syntax of configuration file 'userroles' invalid:\n\
line '$line' contains $len parts"
}
set roleName [string trim [lindex $tuple 0]]
if {[lsearch -exact "[$this roleList]" "$roleName"] == -1} {
return "\
syntax of configuration file 'userroles' invalid:\n\
line '$line' contains unknown role '$roleName'"
}
set userPartList [string trim [lindex $tuple 1]]
foreach userPart $userPartList {
set tuple [split $userPart ':']
set len [llength $tuple]
if {$len != 2} {
return "\
syntax of configuration file 'userroles' invalid:\n\
line '$line' contains invalid user part '$userPart'"
}
set userName [string trim [lindex $tuple 0]]
set indicator [string trim [lindex $tuple 1]]
case "$indicator" in {
{Y y N n} {}
default {
return "\
syntax of configuration file 'userroles' invalid:\n\
line '$line' contains invalid user part '$userPart'"
}
}
if {! [info exists user($userName)]} {
set user($userName) 1
lappend userList "$userName"
}
lappend userInfo [list "$userName" "$indicator"]
}
lappend userRoleInfo [list "$roleName" "$userInfo"]
}
$this userRoleInfo $userRoleInfo
$this userList $userList
return ""
}
method CustSecHandler::addRoles {this} {
foreach roleName [$this roleList] {
if [[[$this corporate] findRole "$roleName"] isNil] {
puts "Creating Role '$roleName' ..."
[$this corporate] createRole "$roleName"
}
}
}
method CustSecHandler::addUsers {this} {
foreach userName [$this userList] {
if [[[$this corporate] findUser "$userName"] isNil] {
puts "Creating User '$userName' ..."
[$this corporate] createUser "$userName"
}
}
}
method CustSecHandler::addUserRoleLinks {this} {
foreach userRoleInfo [$this userRoleInfo] {
set roleName [lindex $userRoleInfo 0]
set role [[$this corporate] findRole "$roleName"]
foreach userInfo [lindex $userRoleInfo 1] {
set userName [lindex $userInfo 0]
set user [[$this corporate] findUser "$userName"]
case "[lindex $userInfo 1]" in {
{Y y} {
set use defaultOn
}
default {
set use defaultOff
}
}
set link [[$this project] findUserRoleLink $user $role]
set msg " link between User '$userName' and Role '$roleName' ..."
if [$link isNil] {
puts -nonewline "Creating"
puts $msg
[$this project] createUserRoleLink "$userName" $role $use
} else {
puts -nonewline "Updating"
puts $msg
$link use $use
}
}
}
}
method CustSecHandler::setAccess {this obj roleName allowedMap prohibitedMap undefinedMap isList} {
if $isList {
$obj modifyNewChildRights \
"$roleName" $allowedMap $prohibitedMap $undefinedMap
}
# Mask-out possible unvalid access rights
set controlledActions [$obj controlledActions]
set allowedMap [expr $controlledActions & $allowedMap]
set prohibitedMap [expr $controlledActions & $prohibitedMap]
set undefinedMap [expr $controlledActions & $undefinedMap]
$obj modifyPermission "$roleName" $allowedMap $prohibitedMap $undefinedMap
}
method CustSecHandler::updateAccess {this} {
foreach link [[$this config] phaseVersionLinks] {
set phaseV [$link phaseVersion]
set phase [$phaseV phase]
set phaseName [$phase name]
puts "\tPhase $phaseName"
foreach roleInfo [$this roleInfo] {
if {! [string match "[lindex $roleInfo 1]" "$phaseName"]} continue
set roleName [lindex $roleInfo 0]
set accessList [lindex $roleInfo 2]
puts "\t\tSet access rights for Role '$roleName' to $accessList ..."
set allowedMap 0
foreach access $accessList {
set allowedMap \
[expr $allowedMap|[[$this allowedMap] set $access]]
}
set prohibitedMap [expr 1023 - $allowedMap]
$this setAccess $phaseV \
"$roleName" $allowedMap $prohibitedMap 0 0
$this setAccess [$phase phaseVersionList] \
"$roleName" $allowedMap $prohibitedMap 0 1
$this setAccess [$phaseV systemVersionLinkList] \
"$roleName" $allowedMap $prohibitedMap 0 1
$this setAccess [$phase systemList] \
"$roleName" $allowedMap $prohibitedMap 0 1
}
}
}
# Do not delete this line -- regeneration end marker
method CustSecHandler::getAllowedMap {this access} {
return [[$this allowedMap] set $access]
}
method CustSecHandler::setAllowedMap {this access newAllowedMap} {
[$this allowedMap] set $access $newAllowedMap
}
method CustSecHandler::removeAllowedMap {this access} {
[$this allowedMap] unset $access
}