package Ġio . eh dev . account . web . endpoints . api Ċ Ċ import Ġio . eh dev . account . database . api . Access Manager Ċ import Ġio . eh dev . account . database . api . Target Manager Ċ import Ġio . eh dev . account . web . endpoints . api . internal . Endpoint Helper Ċ import Ġio . eh dev . account . web . endpoints . api . internal . to Value OrThrow Ċ import Ġio . eh dev . account . web . endpoints . api . internal . verify LoggedIn Ċ import Ġio . eh dev . account . web . endpoints . api . model . New Subject Resource Ċ import Ġio . eh dev . account . web . endpoints . api . model . Subject Resource Model Ċ import Ġorg . springframework . http . HttpStatus Ċ import Ġorg . springframework . http . MediaType Ċ import Ġorg . springframework . web . reactive . function . server . Server Request Ċ import Ġorg . springframework . web . reactive . function . server . Server Response Ċ import Ġorg . springframework . web . server . ResponseStatus Exception Ċ import Ġreactor . core . publisher . Mono Ċ Ċ class ĠAuthorization Endpoints ( ĊĠĠĠ Ġprivate Ġval Ġtarget Manager : ĠTarget Manager , ĊĠĠĠ Ġprivate Ġval Ġaccess Manager : ĠAccess Manager , ĊĠĠĠ Ġprivate Ġval Ġendpoint Helper : ĠEndpoint Helper Ċ ) Ġ{ ĊĠĠĠ Ġfun Ġretrieve Subject ( request : ĠServer Request ): ĠMono < Server Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaccount Principal Ġ= Ġrequest . verify LoggedIn () ĊĠĠĠĠĠĠĠ Ġval Ġsubject Name Ġ= Ġrequest . path Variable (" subject ") ĊĠĠĠĠĠĠĠ Ġval Ġtarget Ġ= Ġendpoint Helper . verify User Has Admin Rule Access ( subject Name , Ġaccount Principal . account Manager User ) ĊĠĠĠĠĠĠĠ Ġreturn ĠServer Response . ok () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( Mono . just ( Subject Resource Model . create ( target )), ĠSubject Resource Model :: class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdelete Subject ( request : ĠServer Request ): ĠMono < Server Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaccount Principal Ġ= Ġrequest . verify LoggedIn () ĊĠĠĠĠĠĠĠ Ġval Ġsubject Name Ġ= Ġrequest . path Variable (" subject ") ĊĠĠĠĠĠĠĠ Ġendpoint Helper . verify User Has Admin Rule Access ( subject Name , Ġaccount Principal . account Manager User ) ĊĠĠĠĠĠĠĠ Ġtarget Manager . delete Target ( subject Name ) ĊĠĠĠĠĠĠĠ Ġreturn ĠServer Response . ok (). build () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcreate Subject ( request : ĠServer Request ): ĠMono < Server Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaccount Principal Ġ= Ġrequest . verify LoggedIn () ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġrequest . body To Mono ( New Subject Resource :: class . java ). map Ġ{ Ġbody Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( target Manager . has Target ( body . subject Name )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠResponse Status Exception ( HttpStatus . BAD _ REQUEST , Ġ" The Ġsubject Ġalready Ġexists ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġsubject Ġ= Ġtarget Manager . create Target ( body . subject Name ). to Value OrThrow () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsubject . rule Container . rules . forEach Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccess Manager . grant Permission ( account Principal . account Manager User , Ġit ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSubject Resource Model . create ( subject ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn ĠServer Response . ok () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. contentType ( MediaType . APPLICATION _ JSON ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. body ( response , ĠSubject Resource Model :: class . java ) ĊĠĠĠ Ġ} Ċ }