@Override public void onClick(View v) { if (v == go) { if (dest != null) { String requestUrl = "http://snarti.nu/?data=package&action=send"; requestUrl += "&token=" + activeUser.getString("token"); requestUrl += "&recipient=" + dest.getString("username"); if (useTrustedCheck.isChecked()) { requestUrl += "&usetrust"; } JSONObject result = Database.get(requestUrl); if (result != null && result.has("id")) { try { pkg = UserAuth.buildBundle(result.getJSONObject("package")); } catch (Exception e) { Log.e("TPDS", e.getMessage()); } } else { Log.e("TPDS", "Unable to plan path."); } } if (pkg != null) { setResult(PKG_FOUND, new Intent().putExtras(pkg)); } else { setResult(PKG_NOT_FOUND); } finish(); } }
@Override protected void useData(JSONObject dbResult) { try { path = makePath(dbResult.getJSONArray("path")); src = path.get(0); dest = path.get(path.size() - 1); pkg = UserAuth.buildBundle(dbResult.getJSONObject("package")); } catch (Exception e) { Log.e("TPDS", e.getMessage()); } }
/** * 사용자권한 추가 * * @param usersAuth * @return * @throws DataAccessException */ public int insertUserAuth(UserAuth userAuth) throws DataAccessException { String sql = QueryUtil.getStringQuery( "admin_sql", "admin.usergroup.insertauth"); // 쿼리 프로퍼티파일의 키값에 해당되는 sql문을 읽어온다. Object[] params = { userAuth.getUserID(), userAuth.getMainMenuID(), userAuth.getSubMenuID(), userAuth.getAuthType(), userAuth.getSubMenuAuth() }; Map<String, Object> param = new HashMap<String, Object>(); param.put("userID", userAuth.getUserID()); param.put("mainMenuID", userAuth.getMainMenuID()); param.put("subMenuID", userAuth.getSubMenuID()); param.put("authType", userAuth.getAuthType()); param.put("subMenuAuth", userAuth.getSubMenuAuth()); return getSimpleJdbcTemplate().update(sql, params); }
@Override protected void useData(JSONObject dbResult) { dest = UserAuth.buildBundle(dbResult); }
@Override public boolean start(Session session) throws Exception { super.start(session); if (userinfo != null && !(userinfo instanceof UIKeyboardInteractive)) { return false; } String dest = username + "@" + session.host; if (session.port != 22) { dest += (":" + session.port); } byte[] password = session.password; boolean cancel = false; byte[] _username = null; _username = Util.str2byte(username); while (true) { // send // byte SSH_MSG_USERAUTH_REQUEST(50) // string user name (ISO-10646 UTF-8, as defined in [RFC-2279]) // string service name (US-ASCII) "ssh-userauth" ? "ssh-connection" // string "keyboard-interactive" (US-ASCII) // string language tag (as defined in [RFC-3066]) // string submethods (ISO-10646 UTF-8) packet.reset(); buf.putByte((byte) SSH_MSG_USERAUTH_REQUEST); buf.putString(_username); buf.putString("ssh-connection".getBytes()); // buf.putString("ssh-userauth".getBytes()); buf.putString("keyboard-interactive".getBytes()); buf.putString("".getBytes()); buf.putString("".getBytes()); session.write(packet); boolean firsttime = true; loop: while (true) { buf = session.read(buf); int command = buf.getCommand() & 0xff; if (command == SSH_MSG_USERAUTH_SUCCESS) { return true; } if (command == SSH_MSG_USERAUTH_BANNER) { buf.getInt(); buf.getByte(); buf.getByte(); byte[] _message = buf.getString(); byte[] lang = buf.getString(); String message = null; try { message = new String(_message, "UTF-8"); } catch (java.io.UnsupportedEncodingException e) { message = new String(_message); } if (userinfo != null) { userinfo.showMessage(message); } continue loop; } if (command == SSH_MSG_USERAUTH_FAILURE) { buf.getInt(); buf.getByte(); buf.getByte(); byte[] foo = buf.getString(); int partial_success = buf.getByte(); // System.err.println(new String(foo)+ // " partial_success:"+(partial_success!=0)); if (partial_success != 0) { throw new JSchPartialAuthException(new String(foo)); } if (firsttime) { return false; // throw new JSchException("USERAUTH KI is not supported"); // cancel=true; // ?? } break; } if (command == SSH_MSG_USERAUTH_INFO_REQUEST) { firsttime = false; buf.getInt(); buf.getByte(); buf.getByte(); String name = new String(buf.getString()); String instruction = new String(buf.getString()); String languate_tag = new String(buf.getString()); int num = buf.getInt(); String[] prompt = new String[num]; boolean[] echo = new boolean[num]; for (int i = 0; i < num; i++) { prompt[i] = new String(buf.getString()); echo[i] = (buf.getByte() != 0); } byte[][] response = null; if (num > 0 || (name.length() > 0 || instruction.length() > 0)) { if (userinfo != null) { UIKeyboardInteractive kbi = (UIKeyboardInteractive) userinfo; String[] _response = kbi.promptKeyboardInteractive(dest, name, instruction, prompt, echo); if (_response != null) { response = new byte[_response.length][]; for (int i = 0; i < _response.length; i++) { response[i] = Util.str2byte(_response[i]); } } } else if (password != null && prompt.length == 1 && !echo[0] && prompt[0].toLowerCase().startsWith("password:"******"response.length="+response.length); // else // System.err.println("response is null"); packet.reset(); buf.putByte((byte) SSH_MSG_USERAUTH_INFO_RESPONSE); if (num > 0 && (response == null || // cancel num != response.length)) { if (response == null) { // working around the bug in OpenSSH ;-< buf.putInt(num); for (int i = 0; i < num; i++) { buf.putString("".getBytes()); } } else { buf.putInt(0); } if (response == null) cancel = true; } else { buf.putInt(num); for (int i = 0; i < num; i++) { // System.err.println("response: |"+new String(response[i])+"| <- replace here with // **** if you need"); buf.putString(response[i]); } } session.write(packet); /* * if(cancel) break; */ continue loop; } // throw new JSchException("USERAUTH fail ("+command+")"); return false; } if (cancel) { throw new JSchAuthCancelException("keyboard-interactive"); // break; } } // return false; }