Updated
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
c24aa73bb0
commit
6298bb4765
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user