diff --git a/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java b/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java index 67b8885..764be01 100644 --- a/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java +++ b/restservice/src/main/java/com/plannaplan/security/cas/CustomUAMCasValidator.java @@ -1,12 +1,44 @@ package com.plannaplan.security.cas; -public class CustomUAMCasValidator implements CasValidator { +import org.jasig.cas.client.validation.Assertion; +import org.jasig.cas.client.validation.Cas20ServiceTicketValidator; +import org.jasig.cas.client.validation.TicketValidationException; - public CustomUAMCasValidator(){} +public class CustomUAMCasValidator implements CasValidator { + private static String CAS_URL = "https://cas.amu.edu.pl/cas"; + private static String EMAIL_FIELD = "mail"; + private static String USOS_ID = "usos_id"; + private String service; + private String ticket; + + public CustomUAMCasValidator(String service, String ticket){ + this.service = service; + this.ticket = ticket; + } @Override public String validate() { - + /* + * TO DO + * Dodać case z CAS10/CAS20/CAS30 + */ + Cas20ServiceTicketValidator validator = new Cas20ServiceTicketValidator(CustomUAMCasValidator.CAS_URL); + + try { + Assertion assertion = validator.validate(this.ticket, this.service); + if (assertion == null) { + throw new CasValidationExcepiton("Validation failed. Assertion could not be retrieved for ticket " + ""); + } + String usosid = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.USOS_ID).toString(); + String mail = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.EMAIL_FIELD).toString(); + + System.out.println(usosid); + System.out.println(mail); + + } catch (TicketValidationException e) { + e.printStackTrace(); + } + return null; } } diff --git a/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java b/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java index 2abcd48..8069d0e 100644 --- a/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java +++ b/restservice/src/test/java/com/plannaplan/security/cas/CustomUAMCasValidatorTest.java @@ -1,28 +1,14 @@ package com.plannaplan.security.cas; import org.junit.Test; -import org.jasig.cas.client.validation.Assertion; -import org.jasig.cas.client.validation.Cas20ServiceTicketValidator; -import org.jasig.cas.client.validation.TicketValidationException; public class CustomUAMCasValidatorTest { @Test public void shouldValidateWithDomain() { - /* - * TO DO - * Dodać case z CAS10/CAS20/CAS30 - */ - Cas20ServiceTicketValidator validator = new Cas20ServiceTicketValidator("https://cas.amu.edu.pl/cas"); + CustomUAMCasValidator validator = new CustomUAMCasValidator("https://wmi.plannaplan.pl", "ST-54649-5x4h09vzUpEIyAGmf1sz-cas.amu.edu.pl"); + + validator.validate(); - try { - Assertion assertion = validator.validate("ST-53723-d0gcC3qovlJhhnKZBhTN-cas.amu.edu.pl","https://wmi.plannaplan.pl"); - if (assertion == null) { - throw new CasValidationExcepiton("Validation failed. Assertion could not be retrieved for ticket " + ""); - } - - } catch (TicketValidationException e) { - e.printStackTrace(); - } } }