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

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

Introduction

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

Prototype

public static String sha256Hex(String data) 

Source Link

Usage

From source file:ru.codeinside.adm.AdminServiceImpl.java

Employee createUser(String login, String password, String fio, Set<Role> roles, String creator,
        final Organization org) {
    Employee employee = new Employee();
    employee.setLogin(login);//  w  w w  . j  ava2  s .  co m
    employee.setPasswordHash(DigestUtils.sha256Hex(password));
    employee.setFio(fio);
    employee.getRoles().addAll(roles);
    employee.setCreator(creator);
    employee.setOrganization(org);
    employee.setLocked(false);
    org.getEmployees().add(employee);
    em.persist(employee);
    final Set<String> groups = new HashSet<String>();
    for (Group group : org.getGroups()) {
        groups.add(group.getName());
    }
    logger.log(Level.FINE, "GROUPS: " + groups);
    syncUser(employee, Collections.<Group>emptySet(), groups, processEngine.get().getIdentityService());
    return employee;
}

From source file:ru.codeinside.adm.AdminServiceImpl.java

Employee createUser(String login, String password, String fio, Set<Role> roles, String creator,
        final Organization org, TreeSet<String> groupExecutor, TreeSet<String> groupSupervisorEmp,
        TreeSet<String> groupSupervisorOrg) {
    Employee employee = new Employee();
    employee.setLogin(login);//from   ww w.j  a  v a2s  .c om
    employee.setPasswordHash(DigestUtils.sha256Hex(password));
    employee.setFio(fio);
    employee.getRoles().addAll(roles);
    employee.setCreator(creator);
    employee.setOrganization(org);
    employee.setLocked(false);
    Set<Group> organizationGroups = new HashSet<Group>();
    for (Group g : selectGroupsBySocial(false)) {
        if (groupSupervisorOrg.contains(g.getName())) {
            organizationGroups.add(g);
        }
    }
    employee.setOrganizationGroups(organizationGroups);

    Set<Group> employeeGroups = new HashSet<Group>();
    for (Group g : selectGroupsBySocial(true)) {
        if (groupSupervisorEmp.contains(g.getName())) {
            employeeGroups.add(g);
        }
    }
    employee.setEmployeeGroups(employeeGroups);
    org.getEmployees().add(employee);
    em.persist(employee);
    setUserGroups(employee, groupExecutor);
    final Set<String> groups = new HashSet<String>();
    for (Group group : org.getGroups()) {
        groups.add(group.getName());
    }
    logger.log(Level.FINE, "GROUPS: " + groups);
    syncUser(employee, Collections.<Group>emptySet(), groups, processEngine.get().getIdentityService());
    return employee;
}

From source file:ru.codeinside.adm.AdminServiceImpl.java

@Override
public void setUserItem(final String login, final UserItem userItem) {
    final Employee e = AdminServiceProvider.get().findEmployeeByLogin(login);
    e.setFio(userItem.getFio());//  w  w  w .j  a va2  s. c o m
    e.setLocked(userItem.isLocked());
    e.getRoles().clear();
    e.getRoles().addAll(userItem.getRoles());
    if (userItem.getPassword1() != null) {
        e.setPasswordHash(DigestUtils.sha256Hex(userItem.getPassword1()));
    }
    setUserGroups(e, userItem.getGroups());
    setAvailableGroups(e, userItem.getEmployeeGroups(), userItem.getOrganizationGroups());
    boolean canAllowCertificate = userItem.getRoles().contains(Role.Declarant)
            || userItem.getRoles().contains(Role.Executor) || userItem.getRoles().contains(Role.Supervisor)
            || userItem.getRoles().contains(Role.SuperSupervisor);
    if (userItem.getX509() == null || !canAllowCertificate) {
        e.setCertificate(null); // ?? ?  orphanRemoval = true
    }
    em.persist(e);
}

From source file:script.manager.Printer.java

private void printDiffer() {
    List<String> dbScriptPathes = Registor.fetchFileList();
    Map<Integer, String> candidate = new LinkedHashMap<>();
    int index = 1;
    for (String dbScriptPath : dbScriptPathes) {
        final File expectedScriptlFile = new File(dbScriptPath);
        if (expectedScriptlFile.exists()) {
            try {
                final String contentsLive = FileUtils.readFileToString(expectedScriptlFile,
                        StandardCharsets.UTF_8);
                final String shaLive = DigestUtils.sha256Hex(contentsLive);
                final String contentsDb = Registor.fetchContents(dbScriptPath);
                final String shaDb = Registor.fetchSha(dbScriptPath);
                if (!shaDb.equals(shaLive)) {
                    LOG.log(Level.INFO, "{0}| {1}",
                            new Object[] { StringUtils.leftPad(Integer.toString(index), 3), dbScriptPath });
                    LOG.log(Level.INFO, StringUtils
                            .join(DiffUtil.getUnifiedDiff(contentsDb, contentsLive).iterator(), "\n"));
                    candidate.put(index, dbScriptPath);
                    index++;/*w  w  w . java  2 s.c  om*/
                }
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, null, ex);
            }
        }
    }
    CandidateIO.saveCandidates(candidate);
}

From source file:script.manager.Registor.java

private void overrideRecords(JSONArray recordNumbers) {
    TreeMap<Integer, String> candidate = CandidateIO.readCandidate();
    Iterator iterator = recordNumbers.iterator();
    while (iterator.hasNext()) {
        final int candidateNo = Integer.parseInt((String) iterator.next());
        final File file = new File(candidate.get(candidateNo));
        try (final Connection con = ConnectionProvider.passConnection();
                final PreparedStatement pps = con.prepareStatement(
                        "UPDATE script_registry SET contents = ?, sha = ?, timestamp = ? WHERE file_path = ?;");) {
            final String contents = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
            final String sha = DigestUtils.sha256Hex(contents);
            final String timestamp = SDF.format(new Date());
            final String path = file.getCanonicalPath();
            pps.setString(4, path);//from  www.j  a v  a2 s.  co  m
            pps.setString(1, contents);
            pps.setString(2, sha);
            pps.setString(3, timestamp);
            pps.addBatch();
            pps.executeBatch();
            LOG.log(Level.INFO, "Overrided {0}", path);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    }
}

From source file:script.manager.Registor.java

private void registerRecordsAsRan(JSONArray recordNumbers) {
    TreeMap<Integer, String> candidate = CandidateIO.readCandidate();
    Iterator iterator = recordNumbers.iterator();
    while (iterator.hasNext()) {
        final int candidateNo = Integer.parseInt((String) iterator.next());
        final File file = new File(candidate.get(candidateNo));
        try (final Connection con = ConnectionProvider.passConnection();
                final PreparedStatement pps = con
                        .prepareStatement("INSERT INTO script_registry VALUES (?,?,?,?);");) {
            final String contents = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
            final String sha = DigestUtils.sha256Hex(contents);
            final String timestamp = SDF.format(new Date());
            final String path = file.getCanonicalPath();
            pps.setString(1, path);/* ww w  .j  ava2 s . co m*/
            pps.setString(2, contents);
            pps.setString(3, sha);
            pps.setString(4, timestamp);
            pps.addBatch();
            pps.executeBatch();
            LOG.log(Level.INFO, "Registered as ran {0}", path);
        } catch (Exception ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    }
}

From source file:script.manager.Registor.java

private void registerAllAsRan() {
    final String scriptHome = EnvSetter.fetchHomePath();
    LOG.log(Level.INFO, "SCRIPT_HOME_PATH: {0}", scriptHome);
    LOG.log(Level.INFO, "Starting registerAllMarkAsRan().");
    try {/*  ww w .j  a  va  2  s.c  o m*/
        List<File> files = (List<File>) FileUtils.listFiles(new File(scriptHome),
                new String[] { EnvSetter.fetchFileExtension() }, true);
        LOG.log(Level.INFO, "Number of scripts found: {0}", files.size());
        for (File file : files) {
            try (final Connection con = ConnectionProvider.passConnection();
                    final PreparedStatement pps = con
                            .prepareStatement("INSERT OR REPLACE INTO script_registry VALUES (?,?,?,?);");) {
                final String contents = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
                final String sha = DigestUtils.sha256Hex(contents);
                final String timestamp = SDF.format(new Date());
                final String path = file.getCanonicalPath();
                pps.setString(1, path);
                pps.setString(2, contents);
                pps.setString(3, sha);
                pps.setString(4, timestamp);
                pps.addBatch();
                pps.executeBatch();
                LOG.log(Level.INFO, "Registerd {0}", path);
            } catch (ClassNotFoundException | SQLException ex) {
                LOG.log(Level.SEVERE, null, ex);
            }
        }
        LOG.log(Level.INFO, "Finished registerAllMarkAsRan().");
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, null, ex);
        throw new IllegalStateException(ex);
    }
}

From source file:SecurityLayer.Encriptacion.java

/**
 * Mtodo usado para la encriptacin./*  w  w w. j a v  a2 s  .c o  m*/
 * @param cadena cadena que ser encriptada.
 * @param tipo tipo de encriptacin que se usar para encriptar la cadena.
 * @return cadena encriptada.
 */
public String encriptar(String cadena, Enumeraciones.Encriptacion tipo) {
    String cadenaEncriptada = null;
    switch (tipo) {
    case Normal:
        cadenaEncriptada = DigestUtils.md5Hex(cadena);
        break;
    case Fuerte:
        cadenaEncriptada = DigestUtils.sha256Hex(cadena);
        break;
    }
    return cadenaEncriptada;
}

From source file:SeprozoService.UserServiceImpl.java

private String versleutel(String tekst) {
    try {//from  w  w w .j  a  va 2s. c o m
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(tekst.getBytes("UTF-8"));
        String versleuteldeTekst = DigestUtils.sha256Hex(new String(md.digest()));
        return versleuteldeTekst;
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) {
        Logger.getLogger(UserServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}

From source file:spade.filter.AuditSanity.java

public boolean initialize(String arguments) {
    try {/* w  ww.  ja v a  2  s  . c o  m*/
        vertexMap = CommonFunctions.createExternalMemoryMapInstance(vertexMapId, "100000", "0.0001", "10000000",
                Settings.getProperty("spade_root") + File.separator + "tmp", "vertexhashes", "120",
                new Hasher<AbstractVertex>() {
                    @Override
                    public String getHash(AbstractVertex t) {
                        return DigestUtils.sha256Hex(String.valueOf(t));
                    }
                });
        return true;
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Failed to create external map", e);
        return false;
    }
}