Added auth endpoint
This commit is contained in:
		| @@ -1,7 +1,9 @@ | ||||
| package com.plannaplan.controllers; | ||||
|  | ||||
| import com.plannaplan.security.CasValidationExcepiton; | ||||
| import com.plannaplan.security.CasValidator; | ||||
|  | ||||
| import org.springframework.http.HttpStatus; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.web.bind.annotation.CrossOrigin; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | ||||
| @@ -14,8 +16,20 @@ public class TokenController { | ||||
|  | ||||
|     public static String SERVICE_URL = "http://localhost:3000"; | ||||
|  | ||||
|     // @GetMapping("/token") | ||||
|     // public ResponseEntity<String> getToken(@RequestParam("ticket") final String ticket) { | ||||
|     //     CasValidator validator = new CasValidator(SERVICE_URL,ticket); | ||||
|     // } | ||||
|     @GetMapping("/token") | ||||
|     public ResponseEntity<String> getToken(@RequestParam("ticket") final String ticket) { | ||||
|         CasValidator validator = new CasValidator(SERVICE_URL,ticket); | ||||
|  | ||||
|         try{ | ||||
|             String authority = validator.validate(); | ||||
|             return new ResponseEntity<>(authority,HttpStatus.OK); | ||||
|         } | ||||
|         catch(CasValidationExcepiton e){ | ||||
|             return new ResponseEntity<>("Wrong ticket",HttpStatus.UNAUTHORIZED); | ||||
|         } | ||||
|         catch(Exception e){ | ||||
|             return new ResponseEntity<>(e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR); | ||||
|         } | ||||
|  | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user