@@ -12,7 +12,6 @@ const Security = require('../security');
1212const CONTEXT_BROKER = process . env . CONTEXT_BROKER || 'http://localhost:1026/ngsi-ld/v1' ;
1313const DEVICE_BROKER = process . env . DEVICE_BROKER || CONTEXT_BROKER ;
1414const NGSI_LD_TENANT = process . env . NGSI_LD_TENANT !== undefined ? process . env . NGSI_LD_TENANT : 'openiot' ;
15- const AUTHZFORCE_ENABLED = process . env . AUTHZFORCE_ENABLED || false ;
1615
1716const port = process . env . WEB_APP_PORT || '3000' ;
1817const devicesPort = process . env . DUMMY_DEVICES_PORT || 3001 ;
@@ -129,26 +128,16 @@ function sendCommand(req, res) {
129128 } ) ;
130129}
131130
132- // Ringing the bell and unlocking the door are restricted actions, everything else
133- // can be done by any user. This is a simple access control function to ensure
134- // only users who are authorized can do certain things.
131+ // Tractor commands (start/stop) require equipment-supervisor; water commands (on/off) require livestock-supervisor.
132+ // All other actions require authentication only.
133+ const SUPERVISED_ACTIONS = new Set ( [ 'start' , 'stop' , 'on' , 'off' ] ) ;
134+
135135function accessControl ( req , res , next ) {
136136 debug ( 'accessControl' ) ;
137137 const action = req . body . action ;
138- if ( action === 'ring' ) {
139- // LEVEL 2: BASIC AUTHORIZATION - Resources are accessible on a User/Verb/Resource basis
140- // LEVEL 3: ADVANCED AUTHORIZATION - Resources are accessible on XACML Rules
141- return AUTHZFORCE_ENABLED
142- ? Security . authorizeAdvancedXACML ( req , res , next , '/bell/ring' )
143- : Security . authorizeBasicPDP ( req , res , next , '/bell/ring' ) ;
144- } else if ( action === 'unlock' ) {
145- // LEVEL 2: BASIC AUTHORIZATION - Resources are accessible on a User/Verb/Resource basis
146- // LEVEL 3: ADVANCED AUTHORIZATION - Resources are accessible on XACML Rules
147- return AUTHZFORCE_ENABLED
148- ? Security . authorizeAdvancedXACML ( req , res , next , '/door/unlock' )
149- : Security . authorizeBasicPDP ( req , res , next , '/door/unlock' ) ;
138+ if ( SUPERVISED_ACTIONS . has ( action ) ) {
139+ return Security . authorizeBasicPDP ( req , res , next ) ;
150140 }
151- // LEVEL 1: AUTHENTICATION ONLY - Every user is authorized, just ensure the user exists.
152141 return Security . authenticate ( req , res , next ) ;
153142}
154143
0 commit comments