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