<s> """<STR_LIT>""" <EOL> from twisted . python import log <EOL> from opennsa import nsa <EOL> LOG_SYSTEM = '<STR_LIT>' <EOL> NSA = '<STR_LIT>' <EOL> USER = '<STR_LIT:user>' <EOL> GROUP = '<STR_LIT>' <EOL> TOKEN = '<STR_LIT>' <EOL> HOST_DN = '<STR_LIT>' <EOL> HEADER_ATTRIBUTES = [ NSA , USER , GROUP , TOKEN ] <EOL> REQUEST_ATTRIBUTES = [ HOST_DN ] <EOL> AUTH_ATTRIBUTES = HEADER_ATTRIBUTES + REQUEST_ATTRIBUTES <EOL> class AuthorizationRule ( object ) : <EOL> pass <EOL> class AuthorizationAttribute ( AuthorizationRule ) : <EOL> def __init__ ( self , type_ , value ) : <EOL> self . type_ = type_ <EOL> self . value = value <EOL> def match ( self , sa ) : <EOL> assert type ( sa ) is nsa . SecurityAttribute , '<STR_LIT>' <EOL> return self . type_ == sa . type_ and self . value == sa . value <EOL> def isAuthorized ( port , security_attributes , request_info , stp , start_time , end_time ) : <EOL> """<STR_LIT>""" <EOL> default = False if port . authz else True <EOL> for rule in port . authz : <EOL> if rule . type_ in HEADER_ATTRIBUTES : <EOL> if any ( [ rule . match ( sa ) for sa in security_attributes ] ) : <EOL> log . msg ( '<STR_LIT>' % ( port . name , rule . type_ ) , system = LOG_SYSTEM ) <EOL> return True <EOL> elif rule . type_ in REQUEST_ATTRIBUTES and rule . type_ == HOST_DN : <EOL> if rule . value == request_info . cert_host_dn : <EOL> log . msg ( '<STR_LIT>' % ( port . name , request_info . cert_host_dn ) , system = LOG_SYSTEM ) <EOL> return True <EOL> else : <EOL> log . msg ( "<STR_LIT>" % rule . type_ , system = '<STR_LIT>' ) <EOL> return default </s>
