56 lines
1.8 KiB
Java
Executable File
56 lines
1.8 KiB
Java
Executable File
package com.plannaplan.security.cas;
|
|
|
|
import org.jasig.cas.client.validation.Assertion;
|
|
import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
|
|
import org.jasig.cas.client.validation.TicketValidationException;
|
|
|
|
/**
|
|
* Cas Validator for UAM with domain registered for email and usosid as a
|
|
* repsonse
|
|
*/
|
|
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;
|
|
|
|
/**
|
|
* craste new instance
|
|
*
|
|
* @param service string with url of our service from where request began
|
|
* @param ticket ticket returned after user provided creeds on cas page
|
|
*/
|
|
public CustomUAMCasValidator(String service, String ticket) {
|
|
this.service = service;
|
|
this.ticket = ticket;
|
|
}
|
|
|
|
@Override
|
|
public CasUserIdentity validate() {
|
|
final Cas20ServiceTicketValidator validator = new Cas20ServiceTicketValidator(CustomUAMCasValidator.CAS_URL);
|
|
|
|
try {
|
|
final Assertion assertion = validator.validate(this.ticket, this.service);
|
|
|
|
if (assertion == null) {
|
|
throw new CasValidationExcepiton(
|
|
"Validation failed. Assertion could not be retrieved for ticket " + "");
|
|
}
|
|
|
|
final String usosid = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.USOS_ID)
|
|
.toString();
|
|
|
|
final String mail = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.EMAIL_FIELD)
|
|
.toString();
|
|
|
|
return new CasUserIdentity(usosid, mail);
|
|
|
|
} catch (TicketValidationException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|