Example usage for org.apache.commons.codec.digest DigestUtils md5Hex

List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils md5Hex.

Prototype

public static String md5Hex(String data) 

Source Link

Usage

From source file:net.shopxx.entity.Admin.java

@PrePersist
public void prePersist() {
    setUsername(StringUtils.lowerCase(getUsername()));
    setEmail(StringUtils.lowerCase(getEmail()));
    setLockKey(DigestUtils.md5Hex(UUID.randomUUID() + RandomStringUtils.randomAlphabetic(30)));
}

From source file:io.vertx.tempmail.impl.TempMailClientImpl.java

@Override
public void getSources(String email, Handler<AsyncResult<JsonObject>> handler) {
    log.debug("getSources::" + email);
    doGenericRequest(String.format(getSourcesURL, DigestUtils.md5Hex(email)), handler);
}

From source file:com.dianping.lion.service.impl.UserServiceImpl.java

/**
 * No need to authenticate in LDAP in three conditions:
 * <ul>//from  w  w w  . j  a v  a2  s  .  com
 * <li>User is locked.
 * <li>System user.
 * <li>User authenticated last time.
 * </ul>
 * then go to ldap for authentication, if authenticated and mysql doesn't contains it or with wrong password, inserting or updating
 * the right authenticated account into <br>mysql for authorization and returning it, otherwise, 
 * returning null.
 */
@Override
public User login(String loginName, String passwd) {
    User dbUser = userDao.findByName(loginName);
    boolean isUpdateNeeded = false;
    if (dbUser != null) {
        if (dbUser.isLocked()) {
            throw new UserLockedException();
        } else if (dbUser.isSystem()) {
            throw new SystemUserForbidLoginException();
        } else if (dbUser.getPassword() != null) {
            //mysql?
            if (dbUser.getPassword().equals(DigestUtils.md5Hex(passwd).toUpperCase())) {
                return dbUser;
            } else {
                isUpdateNeeded = true;
                //                throw new IncorrectPasswdException();
            }
        }
    }
    //
    User user = null;
    try {
        user = ldapAuthenticationService.authenticate(loginName, passwd);
    } catch (Exception e) {
        throw new IncorrectPasswdException();
    }
    if (user != null) {
        user.setPassword(DigestUtils.md5Hex(passwd).toUpperCase());
        if (dbUser == null) {
            //insert the user
            userDao.insertUser(user);
        } else if (isUpdateNeeded) {
            user.setId(dbUser.getId());
            userDao.updatePassword(user);
            cacheClient.remove(ServiceConstants.CACHE_USER_PREFIX + dbUser.getId());
        }
        return user;
    } else {
        throw new UserNotFoundException(loginName);
    }
}

From source file:cn.wanghaomiao.seimi.utils.GenericUtils.java

public static String signRequest(Request request) {
    return DigestUtils.md5Hex(request.getUrl() + sortParams(request.getParams()));
}

From source file:co.kuali.rice.krad.service.impl.RiceAttachmentDataToS3ConversionImpl.java

@Override
public void execute() {
    LOG.info("Starting attachment conversion job for file_data to S3");

    if (!processRecords()) {
        return;//from   ww w . j a  va  2s . com
    }

    final Collection<Attachment> attachments = dataObjectService.findAll(Attachment.class).getResults();
    attachments.forEach(attachment -> {
        try {
            final File file = new File(getDocumentDirectory(attachment.getNote().getRemoteObjectIdentifier())
                    + File.separator + attachment.getAttachmentIdentifier());
            if (file.isFile() && file.exists()) {
                final byte[] fsBytes = FileUtils.readFileToByteArray(file);
                String fileDataId = attachment.getAttachmentIdentifier();
                final Object s3File = riceS3FileService.retrieveFile(fileDataId);

                final byte[] s3Bytes;
                if (s3File == null) {
                    final Class<?> s3FileClass = Class.forName(RiceAttachmentDataS3Constants.S3_FILE_CLASS);
                    final Object newS3File = s3FileClass.newInstance();

                    final Method setId = s3FileClass.getMethod(RiceAttachmentDataS3Constants.SET_ID_METHOD,
                            String.class);
                    setId.invoke(newS3File, fileDataId);

                    final Method setFileContents = s3FileClass.getMethod(
                            RiceAttachmentDataS3Constants.SET_FILE_CONTENTS_METHOD, InputStream.class);
                    try (InputStream stream = new BufferedInputStream(new ByteArrayInputStream(fsBytes))) {
                        setFileContents.invoke(newS3File, stream);
                        riceS3FileService.createFile(newS3File);
                    }

                    s3Bytes = getBytesFromS3File(riceS3FileService.retrieveFile(fileDataId));
                } else {
                    if (LOG.isDebugEnabled()) {
                        final Method getFileMetaData = s3File.getClass()
                                .getMethod(RiceAttachmentDataS3Constants.GET_FILE_META_DATA_METHOD);
                        LOG.debug("data found in S3, existing id: " + fileDataId + " note id "
                                + attachment.getNoteIdentifier() + " metadata: "
                                + getFileMetaData.invoke(s3File));
                    }
                    s3Bytes = getBytesFromS3File(s3File);
                }

                if (s3Bytes != null && fsBytes != null) {
                    final String s3MD5 = DigestUtils.md5Hex(s3Bytes);
                    final String dbMD5 = DigestUtils.md5Hex(fsBytes);
                    if (!Objects.equals(s3MD5, dbMD5)) {
                        LOG.error("S3 data MD5: " + s3MD5 + " does not equal DB data MD5: " + dbMD5
                                + " for id: " + fileDataId + " note id " + attachment.getNoteIdentifier());
                    } else {
                        if (isDeleteFromFileSystem()) {
                            file.delete();
                        }
                    }
                }
            }
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | IOException
                | ClassNotFoundException | InstantiationException e) {
            throw new RuntimeException(e);
        }
    });
    LOG.info("Finishing attachment conversion job for file_data to S3");
}

From source file:com.sammyun.controller.shop.LoginController.java

/**
 * ??// w  w w .j  a va 2s .c om
 */
@RequestMapping(value = "/submit", method = RequestMethod.POST)
public @ResponseBody Message submit(String captchaId, String captcha, String username,
        HttpServletRequest request, HttpServletResponse response, HttpSession session) {
    String password = rsaService.decryptParameter("enPassword", request);
    rsaService.removePrivateKey(request);

    if (!captchaService.isValid(CaptchaType.memberLogin, captchaId, captcha)) {
        return Message.error("shop.captcha.invalid");
    }
    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
        return Message.error("shop.common.invalid");
    }
    Member member;
    Setting setting = SettingUtils.get();
    if (setting.getIsEmailLogin() && username.contains("@")) {
        List<Member> members = memberService.findListByEmail(username);
        if (members.isEmpty()) {
            member = null;
        } else if (members.size() == 1) {
            member = members.get(0);
        } else {
            return Message.error("shop.login.unsupportedAccount");
        }
    } else {
        member = memberService.findByUsername(username);
    }
    if (member == null) {
        return Message.error("shop.login.unknownAccount");
    }
    if (!member.getIsEnabled()) {
        return Message.error("shop.login.disabledAccount");
    }
    checkLockedStatus(member, setting);

    if (!DigestUtils.md5Hex(password).equals(member.getPassword())) {
        int loginFailureCount = member.getLoginFailureCount() + 1;
        if (loginFailureCount >= setting.getAccountLockCount()) {
            member.setIsLocked(true);
            member.setLockedDate(new Date());
        }
        member.setLoginFailureCount(loginFailureCount);
        memberService.update(member);
        if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.member)) {
            return Message.error("shop.login.accountLockCount", setting.getAccountLockCount());
        } else {
            return Message.error("shop.login.incorrectCredentials");
        }
    }
    updateLoginStatus(request, member);

    Map<String, Object> attributes = new HashMap<String, Object>();
    Enumeration<?> keys = session.getAttributeNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        attributes.put(key, session.getAttribute(key));
    }
    session.invalidate();
    session = request.getSession();
    for (Entry<String, Object> entry : attributes.entrySet()) {
        session.setAttribute(entry.getKey(), entry.getValue());
    }

    session.setAttribute(Member.PRINCIPAL_ATTRIBUTE_NAME, new Principal(member.getId(), username));
    WebUtils.addCookie(request, response, Member.USERNAME_COOKIE_NAME, member.getUsername());

    return SUCCESS_MESSAGE;
}

From source file:com.vaushell.superpipes.transforms.done.T_Done.java

private String buildID(final Message message, final Collection<String> keys) {
    if (message.getPropertyCount() == 0) {
        return null;
    }//from  www .  j  av  a 2 s.com

    final StringBuilder sb = new StringBuilder();

    for (final String key : keys) {
        final Serializable value = message.getProperty(key);
        if (value != null) {
            sb.append('$').append(key).append('#').append(value);
        }
    }

    if (sb.length() <= 0) {
        return buildID(message, message.getKeys());
    } else {
        return DigestUtils.md5Hex(sb.toString());
    }
}

From source file:net.osxx.AuthenticationRealm.java

/**
 * ???/*w  w w  . jav  a 2 s. c  om*/
 * 
 * @param token
 *            
 * @return ??
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) {
    AuthenticationToken authenticationToken = (AuthenticationToken) token;
    String username = authenticationToken.getUsername();
    String password = new String(authenticationToken.getPassword());
    String captchaId = authenticationToken.getCaptchaId();
    String captcha = authenticationToken.getCaptcha();
    String ip = authenticationToken.getHost();
    if (!captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) {
        throw new UnsupportedTokenException();
    }
    if (username != null && password != null) {
        Admin admin = adminService.findByUsername(username);
        Member member = memberService.findByUsername(username);
        if (admin == null && member == null) {
            throw new UnknownAccountException();
        }
        if (admin != null) {
            if (!admin.getIsEnabled()) {
                throw new DisabledAccountException();
            }
            Setting setting = SettingUtils.get();
            if (admin.getIsLocked()) {
                if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) {
                    int loginFailureLockTime = setting.getAccountLockTime();
                    if (loginFailureLockTime == 0) {
                        throw new LockedAccountException();
                    }
                    Date lockedDate = admin.getLockedDate();
                    Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime);
                    if (new Date().after(unlockDate)) {
                        admin.setLoginFailureCount(0);
                        admin.setIsLocked(false);
                        admin.setLockedDate(null);
                        adminService.update(admin);
                    } else {
                        throw new LockedAccountException();
                    }
                } else {
                    admin.setLoginFailureCount(0);
                    admin.setIsLocked(false);
                    admin.setLockedDate(null);
                    adminService.update(admin);
                }
            }
            if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) {
                int loginFailureCount = admin.getLoginFailureCount() + 1;
                if (loginFailureCount >= setting.getAccountLockCount()) {
                    admin.setIsLocked(true);
                    admin.setLockedDate(new Date());
                }
                admin.setLoginFailureCount(loginFailureCount);
                adminService.update(admin);
                throw new IncorrectCredentialsException();
            }
            admin.setLoginIp(ip);
            admin.setLoginDate(new Date());
            admin.setLoginFailureCount(0);
            adminService.update(admin);
            return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName());
        } else {
            if (!member.getIsEnabled()) {
                throw new DisabledAccountException();
            }
            Setting setting = SettingUtils.get();
            if (member.getIsLocked()) {
                if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.member)) {
                    int loginFailureLockTime = setting.getAccountLockTime();
                    if (loginFailureLockTime == 0) {
                        throw new LockedAccountException();
                    }
                    Date lockedDate = member.getLockedDate();
                    Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime);
                    if (new Date().after(unlockDate)) {
                        member.setLoginFailureCount(0);
                        member.setIsLocked(false);
                        member.setLockedDate(null);
                        memberService.update(member);
                    } else {
                        throw new LockedAccountException();
                    }
                } else {
                    member.setLoginFailureCount(0);
                    member.setIsLocked(false);
                    member.setLockedDate(null);
                    memberService.update(member);
                }
            }
            if (!DigestUtils.md5Hex(password).equals(member.getPassword())) {
                int loginFailureCount = member.getLoginFailureCount() + 1;
                if (loginFailureCount >= setting.getAccountLockCount()) {
                    member.setIsLocked(true);
                    member.setLockedDate(new Date());
                }
                member.setLoginFailureCount(loginFailureCount);
                memberService.update(member);
                throw new IncorrectCredentialsException();
            }
            member.setLoginIp(ip);
            member.setLoginDate(new Date());
            member.setLoginFailureCount(0);
            memberService.update(member);

            return new SimpleAuthenticationInfo(new Principal(member.getId(), username), password, getName());
        }

    }
    throw new UnknownAccountException();
}

From source file:TmpContent.java

/**
 * get md5sum of buffer content//from   ww w .  j av  a  2  s  .  c o  m
 *
 * @return
 * @throws IOException
 */
public String getMd5Sum() throws IOException {
    String sumMd5;
    InputStream fis = getInputStream();
    sumMd5 = DigestUtils.md5Hex(fis);
    fis.close();
    return sumMd5;
}

From source file:ar.com.init.agros.license.LicenseVerifier.java

public String generateUniqueKey() {
    String result = "";
    try {//  w  w w  .  ja v  a 2 s .  com
        File file = File.createTempFile("realhowto", ".vbs");
        file.deleteOnExit();
        FileWriter fw = new java.io.FileWriter(file);

        String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
                + "Set colDrives = objFSO.Drives\n" + "Set objDrive = colDrives.item(\"" + "C" + "\")\n"
                + "Wscript.Echo objDrive.SerialNumber"; // see note
        fw.write(vbs);
        fw.close();
        Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = input.readLine()) != null) {
            result += line;
        }
        input.close();
    } catch (Exception e) {
        Logger.getLogger(LicenseVerifier.class.getName()).log(Level.SEVERE, e.getMessage(), e);

    }

    result = DigestUtils.md5Hex(result);
    result = result.toUpperCase();

    StringBuilder buff = new StringBuilder(result);

    for (int i = buff.length() - 4; i > 0; i = i - 4) {
        buff.insert(i, "-");
    }

    return buff.toString();
}