private void loadComponentVars(String input) { if (input == null || input.equals("")) { return; } String[] keyValues = input.split(","); for (String kvs : keyValues) { String[] split = kvs.split(":"); String keyEncoded = split[0]; String valueEncoded = split[1]; String key = StringUtils.toAsciiString(Base64Coder.decode(keyEncoded)); String value = StringUtils.toAsciiString(Base64Coder.decode(valueEncoded)); this.componentVars.put(key, value); } }
private void loadSavedMessages(String input) { String[] messages = input.split(","); for (String encodedMessage : messages) { String message = StringUtils.toAsciiString(Base64Coder.decode(encodedMessage)); this.savedMessages.add(message); } }
/** * @Title: parseJsonToUser @Description: 将json字符串转为user对象 * * @param @param json * @param @return 设定文件 * @return User 返回类型 * @throws */ private User parseJsonToUser(String json) { if (StringUtils.isNullOrEmpty(json)) { return null; } else { User user = JSON.parseObject(json, User.class); return user; } }
// 编辑模块 public void edit() { String method = getRequest().getMethod(); Integer id = getParaToInt("id"); if(method.equalsIgnoreCase(Constants.RequestMethod.GET)) { Section oneSection=Section.me.findById(id); setAttr("section", oneSection); String section_admin=oneSection.getStr("section_admin"); if(!StrUtil.isBlank(section_admin)){ User oneUser= User.me.findById(section_admin); if(oneUser!=null){ setAttr("section_admin_name",oneUser.getStr("nickname")); } } render("edit.html"); } else if(method.equalsIgnoreCase(Constants.RequestMethod.POST)) { String name = getPara("name"); Integer show_status = getParaToInt("show_status"); String tab = getPara("tab"); String desc_text = getPara("desc_text"); String image_logo = getPara("image_logo"); String section_admin = getPara("section_admin"); String section_admin_name = getPara("section_admin_name"); //效验版主 if(!StringUtils.isNullOrEmpty(section_admin_name)){ User oneUser= User.me.findByNickname(section_admin_name); if(oneUser==null){ setAttr("msg","绑定的版主不存在!"); render("add.html"); return; }else{ section_admin=oneUser.getStr("id"); } } Section section = Section.me.findById(id); section.set("name", name) .set("show_status", show_status) .set("tab", tab) .set("desc_text", desc_text) .set("image_logo", image_logo) .set("section_admin", section_admin) .update(); // clear cache clearCache(Constants.CacheName.SECTIONLIST, null); clearCache(Constants.CacheName.SECTIONSHOWLIST, null); redirect(Constants.getBaseUrl() + "/admin/section/index"); } }
@SuppressWarnings("unchecked") public List<Employee> findByCriteria(Employee employee) { Criteria c = getCurrentSession().createCriteria(Employee.class); if (!StringUtils.isNullOrEmpty(employee.getNameEng())) { c.add(Restrictions.like("nameEng", "%" + employee.getNameEng() + "%")); } return c.list(); }
/** * @Title: getUserById @Description: 根据用户id获取用户 * * @param @param json * @param @return 设定文件 * @return User 返回类型 * @throws */ public User getUserById(String json) { if (StringUtils.isNullOrEmpty(json)) { return null; } else { User user = get(String.valueOf(json)); return user; } }
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException { toServer.clear(); if (this.password == null || this.password.length() == 0 || fromServer == null) { // no password or changeUser() Buffer bresp = new Buffer(new byte[] {0}); toServer.add(bresp); } else if (((MySQLConnection) connection).getIO().isSSLEstablished()) { // allow plain text over SSL Buffer bresp = new Buffer(StringUtils.getBytes(this.password)); bresp.setPosition(bresp.getBufLength()); int oldBufLength = bresp.getBufLength(); bresp.writeByte((byte) 0); bresp.setBufLength(oldBufLength + 1); bresp.setPosition(0); toServer.add(bresp); } else if (this.connection.getServerRSAPublicKeyFile() != null) { // encrypt with given key, don't use "Public Key Retrieval" this.seed = fromServer.readString(); Buffer bresp = new Buffer( encryptPassword(this.password, this.seed, this.connection, this.publicKeyString)); toServer.add(bresp); } else { if (!this.connection.getAllowPublicKeyRetrieval()) { throw SQLError.createSQLException( Messages.getString("Sha256PasswordPlugin.2"), SQLError.SQL_STATE_UNABLE_TO_CONNECT_TO_DATASOURCE, connection.getExceptionInterceptor()); } // We must request the public key from the server to encrypt the password if (this.publicKeyRequested) { // read key response Buffer bresp = new Buffer( encryptPassword( this.password, this.seed, this.connection, fromServer.readString())); toServer.add(bresp); this.publicKeyRequested = false; } else { // build and send Public Key Retrieval packet this.seed = fromServer.readString(); Buffer bresp = new Buffer(new byte[] {1}); toServer.add(bresp); this.publicKeyRequested = true; } } return true; }
private static byte[] encryptPassword( String password, String seed, Connection connection, String key) throws SQLException { byte[] input = StringUtils.getBytesNullTerminated(password != null ? password : ""); byte[] mysqlScrambleBuff = new byte[input.length]; Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length); return ExportControlled.encryptWithRSAPublicKey( mysqlScrambleBuff, ExportControlled.decodeRSAPublicKey( key, ((MySQLConnection) connection).getExceptionInterceptor()), ((MySQLConnection) connection).getExceptionInterceptor()); }
private static String readRSAKey(Connection connection, String pkPath) throws SQLException { String res = null; byte[] fileBuf = new byte[2048]; BufferedInputStream fileIn = null; try { File f = new File(pkPath); String canonicalPath = f.getCanonicalPath(); fileIn = new BufferedInputStream(new FileInputStream(canonicalPath)); int bytesRead = 0; StringBuffer sb = new StringBuffer(); while ((bytesRead = fileIn.read(fileBuf)) != -1) { sb.append(StringUtils.toAsciiString(fileBuf, 0, bytesRead)); } res = sb.toString(); } catch (IOException ioEx) { if (connection.getParanoid()) { throw SQLError.createSQLException( Messages.getString("Sha256PasswordPlugin.0", new Object[] {""}), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, connection.getExceptionInterceptor()); } throw SQLError.createSQLException( Messages.getString("Sha256PasswordPlugin.0", new Object[] {"'" + pkPath + "'"}), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, ioEx, connection.getExceptionInterceptor()); } finally { if (fileIn != null) { try { fileIn.close(); } catch (Exception ex) { SQLException sqlEx = SQLError.createSQLException( Messages.getString("Sha256PasswordPlugin.1"), SQLError.SQL_STATE_GENERAL_ERROR, ex, connection.getExceptionInterceptor()); throw sqlEx; } } } return res; }
@Override public UserInfo getUserByUsername(String json) { UserInfo info = new UserInfo(); MResult mResult = new MResult(false); // true 找到用户 false 未找到用户 User user = null; if (!StringUtils.isNullOrEmpty(json)) { user = userDao.selectByUsername(String.valueOf(JSON.parseObject(json, String.class))); if (user != null) { mResult.setSuccess(true); } } info.setmResult(mResult); info.setUser(user); return info; }
@RequestMapping("/Token/{usernme}/{pwd}") public ResponseObj getToken( @PathVariable("usernme") String usernme, @PathVariable("pwd") String pwd) { ResponseObj resp = null; try { String uid = userDao.identifyByUsernmeAndPwd(usernme, pwd); if (!StringUtils.isNullOrEmpty(uid)) { String uuid = mercuryUtils.getUUID(); tokenDao.save(new Token(uid, uuid, mercuryUtils.currentTimeStamp)); resp = new ResponseObj(MercuyConstants.RESPONSE_SUC, MessageCode.S000, uuid); } else { resp = new ResponseObj( MercuyConstants.RESPONSE_SUC, MessageCode.E100, MercuryUtils.EMPTY_STRING); } } catch (Exception e) { e.printStackTrace(); resp = new ResponseObj(MercuyConstants.RESPONSE_EER, e.getMessage(), MercuryUtils.EMPTY_STRING); } return resp; }
/** * パラメータがnullか空だったらブランクで返却します * * @param inputParam 入力パラメータ * @return ブランク */ public static String chkParam(String inputParam) { if (StringUtils.isNullOrEmpty(inputParam)) { inputParam = ""; } return inputParam; }
@Override protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { try { String deleteException = request.getParameter("deleteException"); if (deleteException != null && !StringUtils.isEmptyOrWhitespaceOnly(deleteException)) { String[] exceptionId = request.getParameterValues("exceptionId"); if (exceptionId != null && exceptionId.length > 0) { for (int i = 0; i < exceptionId.length; ++i) { rfiService.deleteLayerExceptions(Long.valueOf(exceptionId[i])); } } return null; } LayerException layerException = (LayerException) command; String actionType = request.getParameter("actionType"); if ("add".equals(actionType)) { List<LayerException> layerExceptionList = rfiService.getLayerExceptionsList( 0, 0, "", " where activity = '" + layerException.getActivity() + "' AND item_description = '" + layerException.getItemDescription() + "' and side = '" + layerException.getSide() + "' "); if (layerExceptionList.contains(layerException)) { response.setContentType("text/xml"); PrintWriter out = response.getWriter(); out.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result><resultCode>error</resultCode><resultText>Layer Exception cannot be added because it overlap with database entry!</resultText></result>"); out.close(); return null; } else { rfiService.addLayerException(layerException); response.setContentType("text/xml"); PrintWriter out = response.getWriter(); out.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result><resultCode>success</resultCode><resultText>Layer Exception added successfully!</resultText></result>"); } } else if ("edit".equals(actionType)) { List<LayerException> layerExceptionList = rfiService.getLayerExceptionsList( 0, 0, "", " where exception_id <> '" + layerException.getExceptionId() + "' and item_description = '" + layerException.getItemDescription() + "' and side = '" + layerException.getSide() + "' "); if (layerExceptionList.contains(layerException)) { response.setContentType("text/xml"); PrintWriter out = response.getWriter(); out.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result><resultCode>error</resultCode><resultText>Layer Exception cannot be added because it overlap with database entry!</resultText></result>"); out.close(); return null; } else { rfiService.editLayerExceptions(layerException); response.setContentType("text/xml"); PrintWriter out = response.getWriter(); out.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result><resultCode>success</resultCode><resultText>Layer Exception edited successfully!</resultText></result>"); out.close(); } } return null; // return new ModelAndView("rfiSuccess","rfi",rfi); // return new ModelAndView("redirect:addRFI.htm"); } catch (Exception e) { System.out.println("skdjaldj \n"); e.printStackTrace(); throw e; } }
/** * Test case for transportable tablespaces syntax support: * * <p>FLUSH TABLES ... FOR EXPORT ALTER TABLE ... DISCARD TABLESPACE ALTER TABLE ... IMPORT * TABLESPACE * * @throws SQLException */ public void testTransportableTablespaces() throws Exception { if (versionMeetsMinimum(5, 6, 8)) { String tmpdir = null; String uuid = null; this.rs = this.stmt.executeQuery( "SHOW VARIABLES WHERE Variable_name='tmpdir' or Variable_name='innodb_file_per_table' or Variable_name='server_uuid'"); while (this.rs.next()) { if ("tmpdir".equals(this.rs.getString(1))) { tmpdir = this.rs.getString(2); if (tmpdir.endsWith(File.separator)) { tmpdir = tmpdir.substring(0, tmpdir.length() - File.separator.length()); } } else if ("innodb_file_per_table".equals(this.rs.getString(1))) { if (!this.rs.getString(2).equals("ON")) { fail("You need to set innodb_file_per_table to ON before running this test!"); } } else if ("server_uuid".equals(this.rs.getString(1))) { uuid = this.rs.getString(2); } } if (uuid != null) { tmpdir = tmpdir + File.separator + uuid; } if (File.separatorChar == '\\') { tmpdir = StringUtils.escapeQuote(tmpdir, File.separator); } Properties props = new NonRegisteringDriver().parseURL(dbUrl, null); String dbname = props.getProperty(NonRegisteringDriver.DBNAME_PROPERTY_KEY); if (dbname == null) { assertTrue("No database selected", false); } File checkTableSpaceFile1 = new File( tmpdir + File.separator + dbname + File.separator + "testTransportableTablespaces1.ibd"); if (checkTableSpaceFile1.exists()) { checkTableSpaceFile1.delete(); } File checkTableSpaceFile2 = new File( tmpdir + File.separator + dbname + File.separator + "testTransportableTablespaces2.ibd"); if (checkTableSpaceFile2.exists()) { checkTableSpaceFile2.delete(); } createTable( "testTransportableTablespaces1", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'"); createTable( "testTransportableTablespaces2", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'"); this.stmt.executeUpdate( "FLUSH TABLES testTransportableTablespaces1, testTransportableTablespaces2 FOR EXPORT"); this.stmt.executeUpdate("UNLOCK TABLES"); File tempFile = File.createTempFile("testTransportableTablespaces1", "tmp"); tempFile.deleteOnExit(); String tableSpacePath = tmpdir + File.separator + dbname + File.separator + "testTransportableTablespaces1.ibd"; File tableSpaceFile = new File(tableSpacePath); copyFile(tableSpaceFile, tempFile); this.stmt.executeUpdate("ALTER TABLE testTransportableTablespaces1 DISCARD TABLESPACE"); tableSpaceFile = new File(tableSpacePath); copyFile(tempFile, tableSpaceFile); this.stmt.executeUpdate("ALTER TABLE testTransportableTablespaces1 IMPORT TABLESPACE"); this.pstmt = this.conn.prepareStatement( "FLUSH TABLES testTransportableTablespaces1, testTransportableTablespaces2 FOR EXPORT"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); this.pstmt = this.conn.prepareStatement( "ALTER TABLE testTransportableTablespaces1 DISCARD TABLESPACE"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); this.pstmt = this.conn.prepareStatement("ALTER TABLE testTransportableTablespaces1 IMPORT TABLESPACE"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); } }
/** * CREATE TABLE syntax changed in 5.6GA * * <p>InnoDB: Allow the location of file-per-table tablespaces to be chosen CREATE TABLE ... DATA * DIRECTORY = 'absolute/path/to/directory/' * * @throws SQLException */ public void testCreateTableDataDirectory() throws SQLException { if (versionMeetsMinimum(5, 6, 6)) { try { String tmpdir = null; String separator = File.separatorChar == '\\' ? File.separator + File.separator : File.separator; this.rs = this.stmt.executeQuery( "SHOW VARIABLES WHERE Variable_name='tmpdir' or Variable_name='innodb_file_per_table'"); while (this.rs.next()) { if ("tmpdir".equals(this.rs.getString(1))) { tmpdir = this.rs.getString(2); if (tmpdir.endsWith(File.separator)) { tmpdir = tmpdir.substring(0, tmpdir.length() - 1); } if (File.separatorChar == '\\') { tmpdir = StringUtils.escapeQuote(tmpdir, File.separator); } } else if ("innodb_file_per_table".equals(this.rs.getString(1))) { if (!this.rs.getString(2).equals("ON")) { fail("You need to set innodb_file_per_table to ON before running this test!"); } } } createTable( "testCreateTableDataDirectorya", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'"); createTable( "testCreateTableDataDirectoryb", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'"); this.stmt.executeUpdate( "CREATE TEMPORARY TABLE testCreateTableDataDirectoryc (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'"); createTable( "testCreateTableDataDirectoryd", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "' INDEX DIRECTORY = '" + tmpdir + "'"); this.stmt.executeUpdate("ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE"); this.pstmt = this.conn.prepareStatement( "CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); this.pstmt = this.conn.prepareStatement( "CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); this.pstmt = this.conn.prepareStatement( "CREATE TEMPORARY TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); this.pstmt = this.conn.prepareStatement( "CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "' INDEX DIRECTORY = '" + tmpdir + "'"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); this.pstmt = this.conn.prepareStatement( "ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE"); assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testCreateTableDataDirectoryc"); } } }
/** * 解析数据 * * @param rows 源数据集 * @param column 被解释数据所在列 * @return 节目数据 */ private static String[][] parseRows(Elements rows, int column) { List<List<Integer>> rowspan = new ArrayList<List<Integer>>(); List<List<String[]>> programsList = new ArrayList<List<String[]>>(); String[][] temp_programs = new String[rows.size()][2]; String[][] programs = temp_programs; int[] rowspan_rest = new int[8]; for (int i = 0; i < rows.size(); i++) { Element row = rows.get(i); try { Elements cells = row.children(); List<Integer> rowspanlist = new ArrayList<Integer>(); if (null != cells && cells.size() > 0) { List<String[]> data = new ArrayList<String[]>(); for (int m = 0; m < 8; m++) { if (rowspan_rest[m] > 1) { rowspanlist.add(Integer.valueOf(0)); String[] program = {"", ""}; data.add(program); rowspan_rest[m]--; } else { Element cell = cells.get(0); Integer span = Integer.valueOf(cell.attr("rowspan")); rowspanlist.add(span); String[] program = new String[2]; program[0] = DBclass.xmlFilte(cell.select("dt").text()); program[1] = DBclass.xmlFilte(cell.select("dd").text()); data.add(program); cells.remove(0); rowspan_rest[m] = span.intValue(); } } programsList.add(data); } else { List<String[]> data = new ArrayList<String[]>(); for (int r = 0; r < 8; r++) { rowspanlist.add(Integer.valueOf(0)); String[] program = {"", ""}; data.add(program); rowspan_rest[r]--; } programsList.add(data); } rowspan.add(rowspanlist); } catch (Exception e) { e.printStackTrace(System.out); } } int l = 0; for (int n = 0; n < programsList.size(); n++, l++) { List<String[]> data = programsList.get(n); String[] program = data.get(column); if (!StringUtils.isNullOrEmpty(program[0]) && !StringUtils.isNullOrEmpty(program[1])) { temp_programs[l][0] = program[0]; temp_programs[l][1] = program[1]; } else { l--; } } programs = new String[l][2]; for (int m = 0; m < l; m++) { programs[m][0] = temp_programs[m][0]; programs[m][1] = temp_programs[m][1]; } return programs; }