List of usage examples for org.apache.shiro.crypto.hash SimpleHash toHex
public String toHex()
From source file:com.vsc.dayspring.security.ShiroDbRealm.java
License:Apache License
/** * ?,./*from w ww . ja va 2 s . co m*/ */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder .getRequestAttributes(); String serverName = attributes.getRequest().getHeader("Host"); if (StringUtils.isEmpty(serverName)) { serverName = attributes.getRequest().getServerName(); } if (this.getSubDomains(KEY_APP_DOMAIN).contains(serverName)) { throw new AuthenticationException(); } MyUsernamePasswordToken token = (MyUsernamePasswordToken) authcToken; List<Account> accountList = null; List<CompanyAccount> companyAccountList = null; if (token.getUsername() == null) { return null; } byte[] salt = null; //DEMO&&? if (CodeConstant.CODE_WHETHER_1.equals(CodeConstant.SYS_TYPE_FLAG) && CodeConstant.CODE_LOGIN_TYPE_SERIAL_NUMBER_USER.equals(token.getType())) { companyAccountList = compAccountService.getCompAccountBySerialNumber(token.getUsername()); if (CollectionUtils.isEmpty(companyAccountList)) { throw new AuthenticationException(); } CompanyAccount loginInfo = companyAccountList.get(0); Company company = companyMapper.selectByPrimaryKey(loginInfo.getCompUuid()); if (company == null || CodeConstant.CODE_DELETE_FLAG_YES.equals(company.getDeleteFlag())) { throw new AuthenticationException(); } loginInfo.setCompInitFlg(company.getInitFlag()); loginInfo.setCompName(company.getShortName()); salt = DigestUtils.generateSalt(AuthServer.SALT_SIZE); SimpleHash hash = new SimpleHash(HASH_ALGORITHM, token.getPassword(), ByteSource.Util.bytes(salt), HASH_INTERATIONS); return new SimpleAuthenticationInfo(loginInfo, hash.toHex(), ByteSource.Util.bytes(salt), getName()); } else { if (token.getUsername().toLowerCase().indexOf(ConditionConstant.CONDITION_AT_YOWITS_COM) > 0) { // TODO DEBUG try { accountList = authServer.getLoginInfo(token.getUsername()); } catch (Exception e) { e.printStackTrace(); } } else { // TODO DEBUG try { companyAccountList = compAccountService.getCompAccountCountNoOrgByLoginId(token.getUsername()); } catch (Exception e) { e.printStackTrace(); } } if (!CollectionUtils.isEmpty(companyAccountList)) { CompanyAccount loginInfo = companyAccountList.get(0); if ("1".equals(loginInfo.getDeleteFlag())) { throw new AuthenticationException(); } // ?wizard uuid???? if (StringUtils.isEmpty(loginInfo.getWizardUuid())) { Company company = companyMapper.selectByPrimaryKey(loginInfo.getCompUuid()); if (company == null || CodeConstant.CODE_DELETE_FLAG_YES.equals(company.getDeleteFlag())) { throw new AuthenticationException(); } loginInfo.setCompInitFlg(company.getInitFlag()); loginInfo.setCompName(company.getShortName()); } salt = EncodeUtils.decodeHex(loginInfo.getSalt()); return new SimpleAuthenticationInfo(loginInfo, loginInfo.getPassword(), ByteSource.Util.bytes(salt), getName()); } else if (!CollectionUtils.isEmpty(accountList)) { if (!this.getSubDomains(KEY_OFFIC_DOMAIN).contains(serverName)) { throw new AuthenticationException(); } Account loginInfo = accountList.get(0); if ("1".equals(loginInfo.getDeleteFlag())) { throw new AuthenticationException(); } salt = EncodeUtils.decodeHex(loginInfo.getSalt()); return new SimpleAuthenticationInfo(loginInfo, loginInfo.getPassword(), ByteSource.Util.bytes(salt), getName()); } else { throw new AuthenticationException(); } } }
From source file:org.fireflow.demo.misc.Utils.java
License:Open Source License
/** * ??123456?salt/*from w w w .ja v a 2 s. c om*/ * @param u * @param mustChangePwd ????? * @return ?? */ public static String initUserPassword(User u, boolean mustChangePwd) { String username = u.getLoginName(); String password = "123456"; String salt1 = username; String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex(); SimpleHash hash = new SimpleHash(algorithmName, password, salt1 + salt2, hashIterations); String encodedPassword = hash.toHex(); u.setPwd(encodedPassword); u.setSalt(salt2); u.setMustChangePwd(mustChangePwd); return password; }
From source file:org.fireflow.demo.misc.Utils.java
License:Open Source License
/** * ????/* w w w . ja va 2s .c o m*/ * @param u * @param newPwdPlainTxt ? * @return */ public static String encryptNewPassword(User u, String newPwdPlainTxt) { String username = u.getLoginName(); String password = newPwdPlainTxt; String salt1 = username; String salt2 = u.getSalt(); SimpleHash hash = new SimpleHash(algorithmName, password, salt1 + salt2, hashIterations); String encodedPassword = hash.toHex(); return encodedPassword; }