Renamed CasValidator -> DefaultUAMCasValidator

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2020-12-02 12:38:17 +01:00
parent c3fd450499
commit 7d747b60a8
Signed by: y0rune
GPG Key ID: F204C385F57EB348
3 changed files with 8 additions and 8 deletions

View File

@ -2,7 +2,7 @@ package com.plannaplan.controllers;
import com.plannaplan.exceptions.UserNotFoundException;
import com.plannaplan.security.CasValidationExcepiton;
import com.plannaplan.security.CasValidator;
import com.plannaplan.security.DefaultUAMCasValidator;
import com.plannaplan.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,7 +31,7 @@ public class TokenController {
@ApiOperation(value = "Endpoint to access token required to call secured endpoints. In order to access token we need to provide access token comming from unviersity CAS system")
public ResponseEntity<String> getToken(
@RequestParam("ticket") @ApiParam(value = "Ticket get from CAS system. It should look like ST-1376572-wo41gty5R0JCZFKMMie2-cas.amu.edu.pl") final String ticket) {
final CasValidator validator = new CasValidator(SERVICE_URL, ticket);
final DefaultUAMCasValidator validator = new DefaultUAMCasValidator(SERVICE_URL, ticket);
try {
String authority = validator.validate();

View File

@ -9,19 +9,19 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class CasValidator {
public class DefaultUAMCasValidator {
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
private final CloseableHttpClient httpClient = HttpClients.createDefault();
private String service;
private String ticket;
public CasValidator(String service, String ticket) {
public DefaultUAMCasValidator(String service, String ticket) {
this.service = service;
this.ticket = ticket;
}
public String validate() throws Exception, CasValidationExcepiton {
HttpGet request = new HttpGet(CasValidator.CAS_URL + "/validate?service="
HttpGet request = new HttpGet(DefaultUAMCasValidator.CAS_URL + "/validate?service="
+ URLEncoder.encode(this.service, "UTF-8") + "&ticket=" + URLEncoder.encode(this.ticket, "UTF-8"));
try (CloseableHttpResponse response = httpClient.execute(request)) {

View File

@ -5,14 +5,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Ignore;
import org.junit.Test;
public class CasValidatorTest {
public class DefaultUAMCasValidatorTest {
@Test
@Ignore
public void shouldValidateTicket() {
// you need to privide fresh ticket to make this test pass that's why it is
// marked as ignored
final CasValidator validator = new CasValidator("http://localhost:3000",
final DefaultUAMCasValidator validator = new DefaultUAMCasValidator("http://localhost:3000",
"ST-572267-cbgKrcJLd0tdCubeLqdW-cas.amu.edu.pl");
try {
System.out.println(validator.validate());
@ -24,7 +24,7 @@ public class CasValidatorTest {
@Test
public void shouldNotValidateTicket() {
final CasValidator validator = new CasValidator("http://localhost:3000", "notticket");
final DefaultUAMCasValidator validator = new DefaultUAMCasValidator("http://localhost:3000", "notticket");
try {
assertTrue(validator.validate().trim().equals(""));
} catch (CasValidationExcepiton e) {