-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Address reviewers from abandoned PR #1597. #3091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,20 +23,34 @@ | |
|
|
||
| public class ConsoleProxyHttpHandlerHelper { | ||
| private static final Logger s_logger = Logger.getLogger(ConsoleProxyHttpHandlerHelper.class); | ||
| private static final String AND = "&"; | ||
| private static final String EQUALS = "="; | ||
| private static final String HOST = "host"; | ||
| private static final String PORT = "port"; | ||
| private static final String SID = "sid"; | ||
| private static final String TAG = "tag"; | ||
| private static final String CONSOLE_URL = "consoleurl"; | ||
| private static final String SESSION_REF = "sessionref"; | ||
| private static final String TICKET = "ticket"; | ||
| private static final String LOCALE = "locale"; | ||
| private static final String HYPERV_HOST = "hypervHost"; | ||
| private static final String USERNAME = "username"; | ||
| private static final String PASSWORD = "password"; | ||
| private static final String TOKEN = "token"; | ||
|
|
||
| public static Map<String, String> getQueryMap(String query) { | ||
| String[] params = query.split("&"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to parse URL (possibly a get request) to get the key/value map of params?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there is, thanks for pointing that! |
||
| String[] params = query.split(AND); | ||
| Map<String, String> map = new HashMap<String, String>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable should be named "tokenMap" or something similar to show that it should only store a token key-value item. This will save computation by getting rid of the guardUserInput(map) call in Line #59 |
||
| for (String param : params) { | ||
| String[] paramTokens = param.split("="); | ||
| String[] paramTokens = param.split(EQUALS); | ||
| if (paramTokens != null && paramTokens.length == 2) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GabrielBrascher can you change this line to this "If (ArrayUtils.isNotEmpty(paramTokens) && paramTokens.length == 2)"? |
||
| String name = param.split("=")[0]; | ||
| String value = param.split("=")[1]; | ||
| String name = paramTokens[0]; | ||
| String value = paramTokens[1]; | ||
| map.put(name, value); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think another "if n(name.equalsIgnoreCase(TOKEN)" is needed here considering that the map should only contain a "TOKEN" key. and then remove "guardUserInput(map)" call in line 59 |
||
| } else if (paramTokens.length == 3) { | ||
| // very ugly, added for Xen tunneling url | ||
GabrielBrascher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String name = paramTokens[0]; | ||
| String value = paramTokens[1] + "=" + paramTokens[2]; | ||
| String value = paramTokens[1] + EQUALS + paramTokens[2]; | ||
| map.put(name, value); | ||
| } else { | ||
| if (s_logger.isDebugEnabled()) | ||
|
|
@@ -46,53 +60,53 @@ public static Map<String, String> getQueryMap(String query) { | |
|
|
||
| // This is a ugly solution for now. We will do encryption/decryption translation | ||
GabrielBrascher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // here to make it transparent to rest of the code. | ||
| if (map.get("token") != null) { | ||
| if (map.get(TOKEN) != null) { | ||
| ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(ConsoleProxy.getEncryptorPassword()); | ||
|
|
||
| ConsoleProxyClientParam param = encryptor.decryptObject(ConsoleProxyClientParam.class, map.get("token")); | ||
| ConsoleProxyClientParam param = encryptor.decryptObject(ConsoleProxyClientParam.class, map.get(TOKEN)); | ||
|
|
||
| // make sure we get information from token only | ||
| guardUserInput(map); | ||
| if (param != null) { | ||
| if (param.getClientHostAddress() != null) { | ||
| s_logger.debug("decode token. host: " + param.getClientHostAddress()); | ||
| map.put("host", param.getClientHostAddress()); | ||
| map.put(HOST, param.getClientHostAddress()); | ||
| } else { | ||
| s_logger.error("decode token. host info is not found!"); | ||
| logMessageIfCannotFindClientParam(HOST); | ||
| } | ||
| if (param.getClientHostPort() != 0) { | ||
| s_logger.debug("decode token. port: " + param.getClientHostPort()); | ||
| map.put("port", String.valueOf(param.getClientHostPort())); | ||
| map.put(PORT, String.valueOf(param.getClientHostPort())); | ||
| } else { | ||
| s_logger.error("decode token. port info is not found!"); | ||
| logMessageIfCannotFindClientParam(PORT); | ||
| } | ||
| if (param.getClientTag() != null) { | ||
| s_logger.debug("decode token. tag: " + param.getClientTag()); | ||
| map.put("tag", param.getClientTag()); | ||
| map.put(TAG, param.getClientTag()); | ||
| } else { | ||
| s_logger.error("decode token. tag info is not found!"); | ||
| logMessageIfCannotFindClientParam(TAG); | ||
| } | ||
| if (param.getClientHostPassword() != null) { | ||
| map.put("sid", param.getClientHostPassword()); | ||
| map.put(SID, param.getClientHostPassword()); | ||
| } else { | ||
| s_logger.error("decode token. sid info is not found!"); | ||
| logMessageIfCannotFindClientParam(SID); | ||
| } | ||
| if (param.getClientTunnelUrl() != null) | ||
| map.put("consoleurl", param.getClientTunnelUrl()); | ||
| map.put(CONSOLE_URL, param.getClientTunnelUrl()); | ||
| if (param.getClientTunnelSession() != null) | ||
| map.put("sessionref", param.getClientTunnelSession()); | ||
| map.put(SESSION_REF, param.getClientTunnelSession()); | ||
| if (param.getTicket() != null) | ||
| map.put("ticket", param.getTicket()); | ||
| map.put(TICKET, param.getTicket()); | ||
| if (param.getLocale() != null) | ||
| map.put("locale", param.getLocale()); | ||
| map.put(LOCALE, param.getLocale()); | ||
| if (param.getHypervHost() != null) | ||
| map.put("hypervHost", param.getHypervHost()); | ||
| map.put(HYPERV_HOST, param.getHypervHost()); | ||
| if (param.getUsername() != null) | ||
| map.put("username", param.getUsername()); | ||
| map.put(USERNAME, param.getUsername()); | ||
| if (param.getPassword() != null) | ||
| map.put("password", param.getPassword()); | ||
| map.put(PASSWORD, param.getPassword()); | ||
| } else { | ||
| s_logger.error("Unable to decode token"); | ||
| s_logger.error("Unable to decode token due to null console proxy client param"); | ||
| } | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This else statement seems redundant and can go if the tokenMap only contains 1 TOKEN item |
||
| // we no longer accept information from parameter other than token | ||
|
|
@@ -102,17 +116,21 @@ public static Map<String, String> getQueryMap(String query) { | |
| return map; | ||
| } | ||
|
|
||
| private static void logMessageIfCannotFindClientParam(String param) { | ||
| s_logger.error("decode token. " + param + " info is not found!"); | ||
| } | ||
|
|
||
| private static void guardUserInput(Map<String, String> map) { | ||
| map.remove("host"); | ||
| map.remove("port"); | ||
| map.remove("tag"); | ||
| map.remove("sid"); | ||
| map.remove("consoleurl"); | ||
| map.remove("sessionref"); | ||
| map.remove("ticket"); | ||
| map.remove("locale"); | ||
| map.remove("hypervHost"); | ||
| map.remove("username"); | ||
| map.remove("password"); | ||
| map.remove(HOST); | ||
| map.remove(PORT); | ||
| map.remove(TAG); | ||
| map.remove(SID); | ||
| map.remove(CONSOLE_URL); | ||
| map.remove(SESSION_REF); | ||
| map.remove(TICKET); | ||
| map.remove(LOCALE); | ||
| map.remove(HYPERV_HOST); | ||
| map.remove(USERNAME); | ||
| map.remove(PASSWORD); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.