Added CasValidator.java; Update DefaultUAMCasValidator
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
cd96e74c29
commit
1e3cccc991
@ -0,0 +1,7 @@
|
|||||||
|
package com.plannaplan.security.cas;
|
||||||
|
|
||||||
|
public interface CasValidator {
|
||||||
|
|
||||||
|
String validate();
|
||||||
|
|
||||||
|
}
|
@ -9,7 +9,7 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
public class DefaultUAMCasValidator {
|
public class DefaultUAMCasValidator implements CasValidator {
|
||||||
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
|
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
|
||||||
private final CloseableHttpClient httpClient = HttpClients.createDefault();
|
private final CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||||
private String service;
|
private String service;
|
||||||
@ -20,7 +20,9 @@ public class DefaultUAMCasValidator {
|
|||||||
this.ticket = ticket;
|
this.ticket = ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String validate() throws Exception, CasValidationExcepiton {
|
@Override
|
||||||
|
public String validate() {
|
||||||
|
try {
|
||||||
HttpGet request = new HttpGet(DefaultUAMCasValidator.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"));
|
+ URLEncoder.encode(this.service, "UTF-8") + "&ticket=" + URLEncoder.encode(this.ticket, "UTF-8"));
|
||||||
try (CloseableHttpResponse response = httpClient.execute(request)) {
|
try (CloseableHttpResponse response = httpClient.execute(request)) {
|
||||||
@ -40,6 +42,10 @@ public class DefaultUAMCasValidator {
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new CasValidationExcepiton("Cas Validation has failed.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user