Example usage for org.springframework.util DigestUtils md5DigestAsHex

List of usage examples for org.springframework.util DigestUtils md5DigestAsHex

Introduction

In this page you can find the example usage for org.springframework.util DigestUtils md5DigestAsHex.

Prototype

public static String md5DigestAsHex(InputStream inputStream) throws IOException 

Source Link

Document

Return a hexadecimal string representation of the MD5 digest of the given stream.

Usage

From source file:edu.utah.further.core.xml.xquery.basex.BaseXServerBean.java

/**
 * Set the default admin/admin password to a random 130 bit String
 * // w  w  w.j a v a2s. c  om
 * @return
 */
private String changeAdminPassword() {
    final StringBuilder sb = new StringBuilder();
    // Set the admin password to a random 130 bit String
    sb.append("ALTER USER admin "
            + DigestUtils.md5DigestAsHex((new BigInteger(130, new SecureRandom()).toString(32)).getBytes()));
    return sb.toString();
}

From source file:edu.utah.further.core.xml.xquery.basex.BaseXServerBean.java

/**
 * Create a new user to login with based off of {@link #defaultUsername} and
 * {@link #defaultPassword}//from   www .ja  v  a  2 s .com
 * 
 * @return
 */
private String createUser() {
    final StringBuilder sb = new StringBuilder();
    sb.append("CREATE USER ");
    sb.append(defaultUsername);
    sb.append(" ");
    sb.append(DigestUtils.md5DigestAsHex(defaultPassword.getBytes()));
    sb.append(";");
    final String output = sb.toString();
    return output;
}

From source file:Implement.DAO.CommonDAOImpl.java

@Override
public AccountSession loginToYouTripper(String username, String password) {
    password = DigestUtils.md5DigestAsHex(password.getBytes());
    simpleJdbcCall = new SimpleJdbcCall(dataSource).withProcedureName("loginToYouTripper");
    SqlParameterSource in = new MapSqlParameterSource().addValue("username", username).addValue("password",
            password);/*from w w  w  . j a  v  a 2s  .  c  om*/
    Map<String, Object> record = simpleJdbcCall.execute(in);
    int id = (int) record.get("id");
    String name = (String) record.get("name");
    int type = (int) record.get("type");
    String image = (String) record.get("image");
    return new AccountSession(id, name, type, image);
}

From source file:net.firejack.platform.core.utils.FileUtils.java

public static String md5(File file) {
    if (!file.exists())
        return null;
    String md5 = null;//from w w w  . jav  a 2  s . com
    try {
        FileInputStream fis = new FileInputStream(file);
        md5 = DigestUtils.md5DigestAsHex(IOUtils.toByteArray(fis));
        IOUtils.closeQuietly(fis);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return md5;
}

From source file:org.drugis.addis.config.controller.IndexController.java

@RequestMapping("/")
public String index(Principal currentUser, Model model, HttpServletRequest request) {
    model.addAttribute("connectionsToProviders", getConnectionRepository().findAllConnections());
    try {//  www  .j  a  v  a 2  s . c  om
        if (currentUser == null) {
            return "redirect:/signin";
        } else {
            Account account = accountRepository.findAccountByUsername(currentUser.getName());
            model.addAttribute(account);
            if (StringUtils.isNotEmpty(account.getEmail())) {
                String md5String = DigestUtils.md5DigestAsHex(account.getEmail().getBytes());
                model.addAttribute("userMD5", md5String); // user email MD5 hash needed to retrieve gravatar image
            }

            model.addAttribute("pataviMcdaWsUri", ADDIS_CORE_PATAVI_MCDA_WS_URI);
        }
    } catch (org.springframework.dao.EmptyResultDataAccessException e) {
        request.getSession().invalidate();
        return "redirect:/signin";
    }
    return "index";
}

From source file:org.springframework.boot.context.config.RandomValuePropertySource.java

private Object getRandomBytes() {
    byte[] bytes = new byte[32];
    getSource().nextBytes(bytes);//w  ww .  j  ava 2s .co m
    return DigestUtils.md5DigestAsHex(bytes);
}

From source file:org.springframework.cloud.deployer.thin.ThinJarAppWrapper.java

public ThinJarAppWrapper(Resource resource, String name, String[] profiles) {
    this.resource = resource;
    this.name = name;
    this.profiles = profiles;
    try {/*from   w w  w . j  a v  a 2 s  .  c o  m*/
        this.id = DigestUtils
                .md5DigestAsHex(resource.getFile().getAbsolutePath().getBytes(Charset.forName("UTF-8")));
    } catch (IOException e) {
        throw new IllegalArgumentException("Not a valid file resource");
    }
}

From source file:org.springframework.web.reactive.resource.AppCacheManifestTransformer.java

private Mono<? extends Resource> transform(String content, Resource resource, ResourceTransformerChain chain,
        ServerWebExchange exchange) {// w ww  .ja v  a  2 s .c  om

    if (!content.startsWith(MANIFEST_HEADER)) {
        if (logger.isTraceEnabled()) {
            logger.trace("Manifest should start with 'CACHE MANIFEST', skip: " + resource);
        }
        return Mono.just(resource);
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Transforming resource: " + resource);
    }
    return Flux.generate(new LineInfoGenerator(content))
            .concatMap(info -> processLine(info, exchange, resource, chain))
            .reduce(new ByteArrayOutputStream(), (out, line) -> {
                writeToByteArrayOutputStream(out, line + "\n");
                return out;
            }).map(out -> {
                String hash = DigestUtils.md5DigestAsHex(out.toByteArray());
                writeToByteArrayOutputStream(out, "\n" + "# Hash: " + hash);
                if (logger.isTraceEnabled()) {
                    logger.trace("AppCache file: [" + resource.getFilename() + "] hash: [" + hash + "]");
                }
                return new TransformedResource(resource, out.toByteArray());
            });
}

From source file:org.springframework.web.servlet.resource.FingerprintResourceResolver.java

private String calculateHash(Resource resource) {
    try {//  w  ww  .j  a v a 2s. co m
        byte[] content = FileCopyUtils.copyToByteArray(resource.getInputStream());
        return DigestUtils.md5DigestAsHex(content);
    } catch (IOException e) {
        logger.error("Failed to calculate hash on resource [" + resource.toString() + "]");
        return "";
    }
}

From source file:org.thingsboard.demo.loader.data.DemoData.java

private void readData(String email, byte[] pluginsContent, byte[] rulesContent, byte[] customersContent,
        byte[] devicesContent, List<byte[]> dashboardsContent) throws Exception {
    Map<String, String> pluginTokenMap = new HashMap<>();
    if (pluginsContent != null) {
        JsonNode pluginsJson = objectMapper.readTree(pluginsContent);
        JsonNode pluginsArray = pluginsJson.get("plugins");
        String hash = DigestUtils.md5DigestAsHex(email.getBytes()).substring(0, 10);
        pluginsArray.forEach(jsonNode -> {
            try {
                PluginMetaData plugin = objectMapper.treeToValue(jsonNode, PluginMetaData.class);
                String pluginToken = plugin.getApiToken();
                String newPluginToken = pluginToken + "_" + hash;
                pluginTokenMap.put(pluginToken, newPluginToken);
                plugin.setApiToken(newPluginToken);
                if (plugin.getState() == ComponentLifecycleState.ACTIVE) {
                    plugin.setState(ComponentLifecycleState.SUSPENDED);
                }//from   www  . ja  v  a2  s.co  m
                this.plugins.add(plugin);
            } catch (Exception e) {
                log.error("Unable to load plugins from json!");
                log.error("Cause:", e);
                System.exit(-1);
            }
        });
    }

    if (rulesContent != null) {
        JsonNode rulesJson = objectMapper.readTree(rulesContent);
        JsonNode rulesArray = rulesJson.get("rules");
        rulesArray.forEach(jsonNode -> {
            try {
                String jsonBody = objectMapper.writeValueAsString(jsonNode);
                jsonBody = jsonBody.replaceAll("\\$EMAIL", email);
                RuleMetaData rule = objectMapper.treeToValue(objectMapper.readTree(jsonBody),
                        RuleMetaData.class);
                String newPluginToken;
                // Need to be able to reference system plugins.
                if (pluginTokenMap.containsKey(rule.getPluginToken())) {
                    newPluginToken = pluginTokenMap.get(rule.getPluginToken());
                } else {
                    newPluginToken = rule.getPluginToken();
                }
                if (newPluginToken != null) {
                    rule.setPluginToken(newPluginToken);
                }
                if (rule.getState() == ComponentLifecycleState.ACTIVE) {
                    rule.setState(ComponentLifecycleState.SUSPENDED);
                }
                this.rules.add(rule);
            } catch (Exception e) {
                log.error("Unable to load rule from json!");
                log.error("Cause:", e);
            }
        });
    }

    if (customersContent != null) {
        JsonNode customersJson = objectMapper.readTree(customersContent);
        JsonNode customersArray = customersJson.get("customers");
        Map<String, CustomerId> customerIdMap = new HashMap<>();
        customersArray.forEach(jsonNode -> {
            try {
                Customer customer = objectMapper.treeToValue(jsonNode, Customer.class);
                this.customers.add(customer);
            } catch (Exception e) {
                log.error("Unable to load customer from json!");
                log.error("Cause:", e);
            }
        });
    }

    if (devicesContent != null) {
        JsonNode devicesJson = objectMapper.readTree(devicesContent);
        JsonNode devicesArray = devicesJson.get("devices");
        devicesArray.forEach(jsonNode -> {
            try {
                Device device = objectMapper.treeToValue(jsonNode, Device.class);
                this.devices.add(device);
            } catch (Exception e) {
                log.error("Unable to load device from json!");
                log.error("Cause:", e);
            }
        });
        JsonNode customerDevicesJson = devicesJson.get("customerDevices");
        customerDevicesJson.forEach(jsonNode -> {
            String deviceName = jsonNode.get("deviceName").asText();
            String customerTitle = jsonNode.get("customerTitle").asText();
            customerDevices.put(deviceName, customerTitle);
        });

        JsonNode deviceAttributesJson = devicesJson.get("deviceAttributes");
        deviceAttributesJson.forEach(jsonNode -> {
            String deviceName = jsonNode.get("deviceName").asText();
            Map<String, JsonNode> attributesMap = new HashMap<>();
            if (jsonNode.has("server")) {
                JsonNode serverAttributes = jsonNode.get("server");
                attributesMap.put(DataConstants.SERVER_SCOPE, serverAttributes);
            }
            if (jsonNode.has("shared")) {
                JsonNode sharedAttributes = jsonNode.get("shared");
                attributesMap.put(DataConstants.SHARED_SCOPE, sharedAttributes);
            }
            devicesAttributes.put(deviceName, attributesMap);
        });

    }
    dashboardsContent.forEach(dashboardContent -> {
        try {
            JsonNode dashboardJson = objectMapper.readTree(dashboardContent);
            Dashboard dashboard = objectMapper.treeToValue(dashboardJson, Dashboard.class);
            this.dashboards.add(dashboard);
        } catch (Exception e) {
            log.error("Unable to load dashboard from json!");
            log.error("Cause:", e);
        }
    });
}