2424import ai .elimu .util .GitHubLfsHelper ;
2525import jakarta .servlet .ServletException ;
2626import jakarta .servlet .http .HttpServletRequest ;
27+ import jakarta .servlet .http .HttpServletResponse ;
2728import jakarta .servlet .http .HttpSession ;
2829
2930import java .io .IOException ;
3637import lombok .RequiredArgsConstructor ;
3738import lombok .extern .slf4j .Slf4j ;
3839import org .apache .commons .lang .StringUtils ;
40+ import org .springframework .http .HttpStatus ;
3941import org .springframework .stereotype .Controller ;
4042import org .springframework .ui .Model ;
4143import org .springframework .validation .BindingResult ;
@@ -185,10 +187,17 @@ protected void initBinder(HttpServletRequest request, ServletRequestDataBinder b
185187 @ ResponseBody
186188 public String handleAddContentLabelRequest (
187189 HttpServletRequest request ,
190+ HttpServletResponse response ,
188191 HttpSession session ,
189192 @ PathVariable Long id ) {
190193 log .info ("handleAddContentLabelRequest" );
191194
195+ Contributor contributor = (Contributor ) session .getAttribute ("contributor" );
196+ if (contributor == null ) {
197+ response .setStatus (HttpStatus .FORBIDDEN .value ());
198+ return "error" ;
199+ }
200+
192201 log .info ("id: " + id );
193202 Video video = videoDao .read (id );
194203
@@ -204,7 +213,7 @@ public String handleAddContentLabelRequest(
204213 videoDao .update (video );
205214
206215 VideoContributionEvent videoContributionEvent = new VideoContributionEvent ();
207- videoContributionEvent .setContributor (( Contributor ) session . getAttribute ( " contributor" ) );
216+ videoContributionEvent .setContributor (contributor );
208217 videoContributionEvent .setTimestamp (Calendar .getInstance ());
209218 videoContributionEvent .setVideo (video );
210219 videoContributionEvent .setRevisionNumber (video .getRevisionNumber ());
@@ -225,7 +234,7 @@ public String handleAddContentLabelRequest(
225234 videoDao .update (video );
226235
227236 VideoContributionEvent videoContributionEvent = new VideoContributionEvent ();
228- videoContributionEvent .setContributor (( Contributor ) session . getAttribute ( " contributor" ) );
237+ videoContributionEvent .setContributor (contributor );
229238 videoContributionEvent .setTimestamp (Calendar .getInstance ());
230239 videoContributionEvent .setVideo (video );
231240 videoContributionEvent .setRevisionNumber (video .getRevisionNumber ());
@@ -246,7 +255,7 @@ public String handleAddContentLabelRequest(
246255 videoDao .update (video );
247256
248257 VideoContributionEvent videoContributionEvent = new VideoContributionEvent ();
249- videoContributionEvent .setContributor (( Contributor ) session . getAttribute ( " contributor" ) );
258+ videoContributionEvent .setContributor (contributor );
250259 videoContributionEvent .setTimestamp (Calendar .getInstance ());
251260 videoContributionEvent .setVideo (video );
252261 videoContributionEvent .setRevisionNumber (video .getRevisionNumber ());
@@ -262,10 +271,17 @@ public String handleAddContentLabelRequest(
262271 @ ResponseBody
263272 public String handleRemoveContentLabelRequest (
264273 HttpServletRequest request ,
274+ HttpServletResponse response ,
265275 HttpSession session ,
266276 @ PathVariable Long id ) {
267277 log .info ("handleRemoveContentLabelRequest" );
268278
279+ Contributor contributor = (Contributor ) session .getAttribute ("contributor" );
280+ if (contributor == null ) {
281+ response .setStatus (HttpStatus .FORBIDDEN .value ());
282+ return "error" ;
283+ }
284+
269285 log .info ("id: " + id );
270286 Video video = videoDao .read (id );
271287
@@ -286,7 +302,7 @@ public String handleRemoveContentLabelRequest(
286302 videoDao .update (video );
287303
288304 VideoContributionEvent videoContributionEvent = new VideoContributionEvent ();
289- videoContributionEvent .setContributor (( Contributor ) session . getAttribute ( " contributor" ) );
305+ videoContributionEvent .setContributor (contributor );
290306 videoContributionEvent .setTimestamp (Calendar .getInstance ());
291307 videoContributionEvent .setVideo (video );
292308 videoContributionEvent .setRevisionNumber (video .getRevisionNumber ());
@@ -311,7 +327,7 @@ public String handleRemoveContentLabelRequest(
311327 videoDao .update (video );
312328
313329 VideoContributionEvent videoContributionEvent = new VideoContributionEvent ();
314- videoContributionEvent .setContributor (( Contributor ) session . getAttribute ( " contributor" ) );
330+ videoContributionEvent .setContributor (contributor );
315331 videoContributionEvent .setTimestamp (Calendar .getInstance ());
316332 videoContributionEvent .setVideo (video );
317333 videoContributionEvent .setRevisionNumber (video .getRevisionNumber ());
@@ -336,7 +352,7 @@ public String handleRemoveContentLabelRequest(
336352 videoDao .update (video );
337353
338354 VideoContributionEvent videoContributionEvent = new VideoContributionEvent ();
339- videoContributionEvent .setContributor (( Contributor ) session . getAttribute ( " contributor" ) );
355+ videoContributionEvent .setContributor (contributor );
340356 videoContributionEvent .setTimestamp (Calendar .getInstance ());
341357 videoContributionEvent .setVideo (video );
342358 videoContributionEvent .setRevisionNumber (video .getRevisionNumber ());
0 commit comments