link = URLDecoder.decode(link, "UTF-8");
} catch (UnsupportedEncodingException e1) {
logger.error(e1.getMessage());
}
log.debug("Decoded Link: " + link);
XDirectLinkData data = new XDirectLinkData();
List <Boolean> list = new ArrayList<Boolean>();
try {
myInitDbConnection(getServletContext(), false);
PaloSuiteData psd;
try {
psd = initPaloSuiteData(log);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
return null;
}
if (psd.secret == null) {
data.addError("No shared secret information found. Can't continue.<br/>");
}
if (psd.host == null) {
data.addError("No palo configuration database host specified. Can't continue.<br/>");
}
if (psd.port == null) {
data.addError("No palo configuration database port specified. Can't continue.<br/>");
}
if (data.getErrors() != null && data.getErrors().length > 0) {
psd.secret = null;
psd = null;
return data;
}
StringTokenizer tok = new StringTokenizer(link, "&");
Map <String, String> parameters = new HashMap<String, String>();
parameters.put("hideviewtabs", "1");
parameters.put("hidenavigator", "1");
parameters.put("hidetitlebar", "1");
parameters.put("hidesaveas", "1");
parameters.put("hideconnectionpicker", "1");
while (tok.hasMoreTokens()) {
String parameter = tok.nextToken();
if (parameter.startsWith("?")) {
parameter = parameter.substring(1);
}
int equal = parameter.indexOf("=");
if (equal == -1) {
continue;
}
String key = parameter.substring(0, equal);
String value = "";
if ((equal + 1) < parameter.length()) {
value = parameter.substring(equal + 1);
}
parameters.put(key.toLowerCase(), value);
}
list.add(checkFlag("hideviewtabs", parameters));
list.add(checkFlag("hidenavigator", parameters));
data.setGlobalDisplayFlags(list);
String user = parameters.get("user");
String passEnc64 = parameters.get("pass");
String viewId = parameters.get("viewid");
if (user == null) {
data.addError(UserSession.trans(locale, "noDirectLinkUsernameSpecified"));
}
if (passEnc64 == null) {
data.addError(UserSession.trans(locale, "noDirectLinkPasswordSpecified"));
}
if (viewId == null) {
data.addError(UserSession.trans(locale, "noDirectLinkViewSpecified"));
}
if (data.getErrors() != null && data.getErrors().length > 0) {
return data;
}
if (!checkChecksum(encodedLink, psd.secret, log)) {
data.addError(UserSession.trans(locale, "checksumDoesNotMatch"));
return data;
}
String decPass = null;
try {
decPass = decodePass(psd.secret, user, passEnc64, viewId, log);
} catch (Exception e) {
data.addError(UserSession.trans(locale, "directLinkAuthenticationFailed"));
}
if (decPass == null || (data.getErrors() != null && data.getErrors().length > 0)) {
return data;
}
data = readConfigForUser(user, decPass, psd, viewId, data, log, locale);
List <Boolean> displayFlags = new ArrayList<Boolean>();
displayFlags.add(checkFlag("hidetitlebar", parameters));
displayFlags.add(checkFlag("hidetoolbar", parameters));
displayFlags.add(checkFlag("hidesave", parameters));
displayFlags.add(true); //checkFlag("hidesaveas", link));
displayFlags.add(checkFlag("hidefilter", parameters));
displayFlags.add(checkFlag("hidestaticfilter", parameters));
displayFlags.add(checkFlag("hidehorizontalaxis", parameters));
displayFlags.add(checkFlag("hideverticalaxis", parameters));
displayFlags.add(checkFlag("hideconnectionpicker", parameters));
int counter = 0;
for (Boolean b: displayFlags) {
log.debug("Display flag " + counter++ + ": " + b);
}
if (data.getViews() != null && data.getViews().length == 1) {
XView xView = data.getViews()[0];
xView.setDisplayFlags(displayFlags);
}
data.setDisplayFlags(displayFlags);
// log.debug("DecPass = " + decPass);
} catch (Throwable t) {
log.error("Error parsing configuration: ", t);
}
return data;