org.springside.modules.utils.Encodes Java Examples
The following examples show how to use
org.springside.modules.utils.Encodes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Servlets.java From spring-boot-quickstart with Apache License 2.0 | 6 votes |
/** * 设置让浏览器弹出下载对话框的Header. * * @param fileName 下载后的文件名. */ public static void setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) { // 中文文件名支持 String encodedfileName = null; // 替换空格,否则firefox下有空格文件名会被截断,其他浏览器会将空格替换成+号 encodedfileName = fileName.trim().replaceAll(" ", "_"); String agent = request.getHeader("User-Agent"); boolean isMSIE = (agent != null && agent.toUpperCase().indexOf("MSIE") != -1); if (isMSIE) { encodedfileName = Encodes.urlEncode(fileName); } else { encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1); } response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\""); }
Example #2
Source File: ShiroDbRealm.java From Mario with Apache License 2.0 | 6 votes |
/** * 认证回调函数,登录时调用. */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; User user = accountService.findUserByLoginName(token.getUsername()); if (user != null) { if (user.getStatus().equals("0")) {//disable throw new DisabledAccountException(); } //用户对应的Menu信息 List<Menu> menus = accountService.findMenuByUserID(user.getId()); Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); session.setAttribute("menuList", menus); byte[] salt = Encodes.decodeHex(user.getSalt()); return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getLoginName(), user.getName()), user.getPassword(), ByteSource.Util.bytes(salt), getName()); } else { return null; } }
Example #3
Source File: ShiroDbRealm.java From dubai with MIT License | 6 votes |
/** * 认证回调函数,登录时调用. */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { try{ UsernamePasswordToken token = (UsernamePasswordToken) authcToken; User user = userService.findUserByLoginName(token.getUsername()); if (user != null && user.getStatusCode() == UserStatus.Active.code()) { byte[] salt = Encodes.decodeHex(user.getSalt()); return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getLoginName(), user.getNiceName()), user.getPassword(), ByteSource.Util.bytes(salt), getName()); } } catch (Exception e) { e.printStackTrace(); } return null; }
Example #4
Source File: Servlets.java From dubai with MIT License | 6 votes |
/** * 设置让浏览器弹出下载对话框的Header. * * @param fileName 下载后的文件名. */ public static void setFileDownloadHeader(HttpServletRequest request, HttpServletResponse response, String fileName) { // 中文文件名支持 String encodedfileName = null; // 替换空格,否则firefox下有空格文件名会被截断,其他浏览器会将空格替换成+号 encodedfileName = fileName.trim().replaceAll(" ", "_"); String agent = request.getHeader("User-Agent"); boolean isMSIE = (agent != null && agent.toUpperCase().indexOf("MSIE") != -1); if (isMSIE) { encodedfileName = Encodes.urlEncode(fileName); } else { encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1); } response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\""); }
Example #5
Source File: ShiroDbRealm.java From spring-boot-quickstart with Apache License 2.0 | 5 votes |
/** * 认证回调函数,登录时调用. */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; User user = accountService.findUserByLoginName(token.getUsername()); System.out.println("user name:"+user.getName()); if (user != null) { byte[] salt = Encodes.decodeHex(user.getSalt()); return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getLoginName(), user.getName()), user.getPassword(), ByteSource.Util.bytes(salt), getName()); } else { return null; } }
Example #6
Source File: AccountService.java From spring-boot-quickstart with Apache License 2.0 | 5 votes |
/** * 设定安全的密码,生成随机的salt并经过1024次 sha-1 hash */ private void entryptPassword(User user) { byte[] salt = Digests.generateSalt(SALT_SIZE); user.setSalt(Encodes.encodeHex(salt)); byte[] hashPassword = Digests.sha1(user.getPlainPassword().getBytes(), salt, HASH_INTERATIONS); user.setPassword(Encodes.encodeHex(hashPassword)); }
Example #7
Source File: AccountService.java From Mario with Apache License 2.0 | 5 votes |
/** * 设定安全的密码,生成随机的salt并经过1024次 sha-1 hash */ private void entryptPassword(User user) { byte[] salt = Digests.generateSalt(SALT_SIZE); user.setSalt(Encodes.encodeHex(salt)); byte[] hashPassword = Digests.sha1(user.getPlainPassword().getBytes(), salt, HASH_INTERATIONS); user.setPassword(Encodes.encodeHex(hashPassword)); }
Example #8
Source File: GeneratePasswordTest.java From Mario with Apache License 2.0 | 5 votes |
/** * 测试生成password * 规则如下, * 1、获得随机的SALT_SIZE位byte[]字符,然后使用decodeHex获取salt字符,保存salt字符到数据库中, * 2、使用sha1算法,生成密码,调用enecodeHex,生成最后的password,保存password到数据库中 */ @Test public void testSalt() { byte[] salt = Encodes.decodeHex(code); byte[] hashPassword = Digests.sha1(password.getBytes(), salt, HASH_INTERATIONS); String actualPassword = Encodes.encodeHex(hashPassword); Assert.assertEquals(exceptPassword, actualPassword); }
Example #9
Source File: UserService.java From dubai with MIT License | 5 votes |
/** * 设定安全的密码,生成随机的salt并经过1024次 sha-1 hash */ void entryptPassword(User user, String plainPassword) { byte[] salt = Digests.generateSalt(SALT_SIZE); user.setSalt(Encodes.encodeHex(salt)); byte[] hashPassword = Digests.sha1(plainPassword.getBytes(), salt, HASH_INTERATIONS); user.setPassword(Encodes.encodeHex(hashPassword)); }
Example #10
Source File: Servlets.java From spring-boot-quickstart with Apache License 2.0 | 4 votes |
/** * 客户端对Http Basic验证的 Header进行编码. */ public static String encodeHttpBasic(String userName, String password) { String encode = userName + ":" + password; return "Basic " + Encodes.encodeBase64(encode.getBytes()); }
Example #11
Source File: UserService.java From dubai with MIT License | 4 votes |
void generateActKey(User user) { user.setActKey(Encodes.encodeHex(Digests.sha1((user.getLoginName() + System.currentTimeMillis()).getBytes()))); user.setActKeyGenDate(Calendar.getInstance().getTime()); user.setActDate(user.getActKeyGenDate()); }
Example #12
Source File: Servlets.java From dubai with MIT License | 4 votes |
/** * 客户端对Http Basic验证的 Header进行编码. */ public static String encodeHttpBasic(String userName, String password) { String encode = userName + ":" + password; return "Basic " + Encodes.encodeBase64(encode.getBytes()); }