}
// check the resource URL
if ((resourceUrl != null) && (resourceUrl.length() > 0)) {
LOGGER.finer("Checking resource URL: "+resourceUrl);
RequestContext rc = null;
String samlToken = null;
try {
rc = RequestContext.extract(request);
User user = rc.getUser();
IntegrationResponse resp = null;
IntegrationContextFactory icf = new IntegrationContextFactory();
if (icf.isIntegrationEnabled()) {
IntegrationContext ic = icf.newIntegrationContext();
if (ic != null) {
resp = ic.checkUrl(resourceUrl,user,null,null,null);
if ((resp != null) && resp.isLicensed()) {
if ((user != null) && (user.getProfile() != null)) {
if (user.getProfile().containsKey(SDI_SECURITY_TOKEN)) {
samlToken = ic.getBase64EncodedToken(user);
}
}
}
}
}
// handle a licensed URL
if ((resp != null) && resp.isLicensed()) {
String wssUrl = resp.getUrl();
String licenseSelectionUrl = resp.getLicenseSelectionClientUrl();
if ((licenseSelectionUrl != null) && (licenseSelectionUrl.length() > 0) &&
(wssUrl != null) && (wssUrl.length() > 0)) {
// save resource URL parameters
String wssUrlParams = null;
int idx = wssUrl.indexOf("?");
if (idx != -1) {
wssUrlParams = wssUrl.substring(idx+1).trim();
wssUrl = wssUrl.substring(0,idx);
}
// make the callback URL
String callbackUrl = RequestContext.resolveBaseContextPath(request)+"/link";
callbackUrl += "?lcb="+URLEncoder.encode("true","UTF-8");
callbackUrl += "&act="+URLEncoder.encode(act,"UTF-8");
callbackUrl += "&fwd="+URLEncoder.encode(fwd,"UTF-8");
if ((wssUrlParams != null) && (wssUrlParams.length() > 0)) {
callbackUrl += "&rqs="+URLEncoder.encode(wssUrlParams,"UTF-8");
}
if ((addToMapHint != null) && (addToMapHint.length() > 0)) {
callbackUrl += "&atmh="+URLEncoder.encode(addToMapHint,"UTF-8");
}
// make the full license selection URL (can set &embedded=true)
licenseSelectionUrl += "?WSS="+URLEncoder.encode(wssUrl,"UTF-8");
licenseSelectionUrl += "&returnURL="+URLEncoder.encode(callbackUrl,"UTF-8");
// if user is logged in,
// return an HTML response that immediately posts the SAML token to the license selection URL
// else
// forward to the licenseSelectionUrl
if ((samlToken != null) && (samlToken.length() > 0)) {
LOGGER.finer("Sending POST redirect with token to: " + licenseSelectionUrl);
fwd = null;
String title = "License redirect SSO page";
StringBuilder sbHtml = new StringBuilder();
sbHtml.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
sbHtml.append("\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">");
sbHtml.append("\r\n<head>");
sbHtml.append("\r\n<title>").append(Val.escapeXmlForBrowser(title)).append("</title>");
sbHtml.append("\r\n<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>");
sbHtml.append("\r\n<meta http-equiv=\"Expires\" content=\"Mon, 01 Jan 1990 00:00:01 GMT\"/>");
sbHtml.append("\r\n<meta http-equiv=\"pragma\" content=\"no-cache\"/>");
sbHtml.append("\r\n<meta http-equiv=\"cache-control\" content=\"no-cache\"/>");
sbHtml.append("\r\n<meta name=\"robots\" content=\"noindex\"/>");
sbHtml.append("\r\n</head>");
sbHtml.append("\r\n<body onload=\"document.forms[0].submit();\">");
sbHtml.append("\r\n<form method=\"post\" action=\"").append(Val.escapeXmlForBrowser(licenseSelectionUrl)).append("\">");
sbHtml.append("\r\n<input type=\"hidden\" name=\"ticket\" value=\"").append(Val.escapeXmlForBrowser(samlToken)).append("\"/>");
sbHtml.append("\r\n</form>");
sbHtml.append("\r\n</body>");
sbHtml.append("\r\n</html>");
this.writeCharacterResponse(response,sbHtml.toString(),"UTF-8","text/html; charset=UTF-8");
} else {
fwd = licenseSelectionUrl;
}
} else {
String msg = "IntegrationResponse isLicensed() was true, but getLicenseSelectionClientUrl() was empty.";
LOGGER.warning(msg);
}
// handle a secured URL
} else if ((resp != null) && resp.isSecured()) {
String securedUrl = resp.getUrl();
if ((securedUrl != null) && !securedUrl.equals(resourceUrl)) {
if (act.equals("open")) {
fwd = securedUrl;
} else if (act.equals("preview")) {
fwd = this.replaceParam(fwd,"url",securedUrl);
} else if (act.equals("addToMap")) {
if ((addToMapHint != null) && (addToMapHint.length() > 0)) {
securedUrl = addToMapHint+":"+securedUrl;
}
fwd = this.replaceParam(fwd,"resource",securedUrl);
} else {
fwd = securedUrl;
}
}
}
} catch (NotAuthorizedException e) {
String msg = "Error checking resource URL";
LOGGER.log(Level.SEVERE,msg,e);
this.writeError(request,response,msg+": "+e.toString(),null);
return;
} catch (Exception e) {
String msg = "Error checking resource URL";
LOGGER.log(Level.SEVERE,msg,e);
this.writeError(request,response,msg+": "+e.toString(),null);
return;
} finally {
if (rc != null) rc.onExecutionPhaseCompleted();
}
}
// send the redirect
if ((fwd != null) && (fwd.length() > 0)) {