SSO 0.4
This commit is contained in:
parent
db46106696
commit
8c230a5bac
|
@ -29,7 +29,8 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler {
|
|||
private String service;
|
||||
private boolean encodeServiceUrl;
|
||||
private String casSeverLoginUrl;
|
||||
Cas10TicketValidator ticketValidator10;
|
||||
private String casServerUrlPrefix;
|
||||
Cas10TicketValidator ticketValidator;
|
||||
private AuthenticationRedirectStrategy authenticationRedirectStrategy;
|
||||
|
||||
public SSOLoginPugin() {
|
||||
|
@ -43,21 +44,22 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler {
|
|||
this.initialServiceData(request);
|
||||
if (this.casSeverLoginUrl == null) {
|
||||
this.casSeverLoginUrl = this.initCasLoginUrl();
|
||||
this.casServerUrlPrefix = this.casSeverLoginUrl.substring(0, this.casSeverLoginUrl.indexOf("sso") + 3);
|
||||
}
|
||||
|
||||
String urlToRedirectTo = "";
|
||||
String path = request.getRequestURI();
|
||||
if (path.contains("/auth/logout.do")) {
|
||||
urlToRedirectTo = initCasLogoutUrl() + "?service=" + service;
|
||||
// urlToRedirectTo = initCasLogoutUrl() + "?service=" + service;
|
||||
urlToRedirectTo = StringUtils.getPathString(this.casServerUrlPrefix) + "/logout?service=" + this.serverName;
|
||||
// urlToRedirectTo = StringUtils.getPathString(this.casSeverLoginUrl) + "logout?service=" + RevProxyUtil.getURLContextPath(request);
|
||||
} else {
|
||||
String serviceUrl = this.constructServiceUrl(request, response);
|
||||
logger.debug(String.format("Constructed service url: %s", serviceUrl));
|
||||
urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casSeverLoginUrl, this.getProtocol().getServiceParameterName(), serviceUrl, false, false, (String) null);
|
||||
urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casSeverLoginUrl,
|
||||
this.getProtocol().getServiceParameterName(), serviceUrl, false, false, (String) null);
|
||||
}
|
||||
|
||||
logger.debug(String.format("redirecting to \"%s\"", urlToRedirectTo));
|
||||
|
||||
try {
|
||||
this.authenticationRedirectStrategy.redirect(request, response, urlToRedirectTo);
|
||||
} catch (IOException var7) {
|
||||
|
@ -93,6 +95,7 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler {
|
|||
this.initialServiceData(request);
|
||||
if (this.casSeverLoginUrl == null) {
|
||||
this.casSeverLoginUrl = this.initCasLoginUrl();
|
||||
this.casServerUrlPrefix = this.casSeverLoginUrl.substring(0, this.casSeverLoginUrl.indexOf("sso") + 3);
|
||||
}
|
||||
|
||||
String ticket = this.retrieveTicketFromRequest(request);
|
||||
|
@ -100,35 +103,34 @@ public class SSOLoginPugin implements ThirdSSOAuthHandler {
|
|||
try {
|
||||
logger.info(String.format("Attempting to validate ticket: %s", ticket));
|
||||
//logger.debug(String.format("Attempting to validate ticket: %s", ticket));
|
||||
String service2 = this.constructServiceUrl(request, response);
|
||||
logger.info(String.format("Attempting to validate service2: %s", service2));
|
||||
//logger.debug(String.format("Attempting to validate service2: %s", service2));
|
||||
// "https://oa-uat.elmleaf.com.cn/sso/proxyValidate"
|
||||
String tempXml = HttpRequest.post("http://10.157.226.9:8088/sso/proxyValidate")
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.form("ticket",ticket)
|
||||
.form("service", service2).execute().body();
|
||||
logger.info(String.format("Attempting to validate tempXml: %s", tempXml));
|
||||
if (tempXml != null) {
|
||||
JSONObject user = XML.toJSONObject(tempXml);
|
||||
String username = user.getJSONObject("cas:serviceResponse")
|
||||
.getJSONObject("cas:authenticationSuccess").getStr("cas:user");
|
||||
if(username != null){
|
||||
result.setUser(username);
|
||||
result.setSucess(true);
|
||||
}
|
||||
}
|
||||
//if (this.ticketValidator == null) {
|
||||
// this.ticketValidator = new Cas11TicketValidator(this.casSeverLoginUrl);
|
||||
//}
|
||||
//String userName = null;
|
||||
//Assertion assertion = this.ticketValidator.validate2(ticket, this.constructServiceUrl(request, response));
|
||||
//logger.debug(String.format("Successfully authenticated user: %s", assertion.getPrincipal().getName()));
|
||||
//if (assertion != null) {
|
||||
// userName = assertion.getPrincipal().getName();
|
||||
// result.setUser(userName);
|
||||
// String service2 = this.constructServiceUrl(request, response);
|
||||
// logger.info(String.format("Attempting to validate service2: %s", service2));
|
||||
// //logger.debug(String.format("Attempting to validate service2: %s", service2));
|
||||
// // "https://oa-uat.elmleaf.com.cn/sso/proxyValidate"
|
||||
// String tempXml = HttpRequest.post("http://10.157.226.9:8088/sso/proxyValidate")
|
||||
// .contentType("application/x-www-form-urlencoded")
|
||||
// .form("ticket",ticket)
|
||||
// .form("service", service2).execute().body();
|
||||
// logger.info(String.format("Attempting to validate tempXml: %s", tempXml));
|
||||
// if (tempXml != null) {
|
||||
// JSONObject user = XML.toJSONObject(tempXml);
|
||||
// String username = user.getJSONObject("cas:serviceResponse")
|
||||
// .getJSONObject("cas:authenticationSuccess").getStr("cas:user");
|
||||
// if(username != null){
|
||||
// result.setUser(username);
|
||||
// result.setSucess(true);
|
||||
// }
|
||||
// }
|
||||
if (this.ticketValidator == null) {
|
||||
this.ticketValidator = new Cas10TicketValidator(this.casServerUrlPrefix);
|
||||
}
|
||||
Assertion assertion = this.ticketValidator.validate(ticket, this.constructServiceUrl(request, response));
|
||||
if (assertion != null) {
|
||||
logger.debug(String.format("Successfully authenticated user: %s", assertion.getPrincipal().getName()));
|
||||
String userName = assertion.getPrincipal().getName();
|
||||
result.setUser(userName);
|
||||
result.setSucess(true);
|
||||
}
|
||||
} catch (Exception var7) {
|
||||
logger.error(var7);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue