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

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

Introduction

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

Prototype

@Deprecated
    public static String shaHex(String data) 

Source Link

Usage

From source file:com.enonic.cms.core.xslt.lib.PortalFunctions.java

public static String sha(final Object value) {
    return DigestUtils.shaHex(toString(value));
}

From source file:be.fedict.eid.idp.webapp.ProtocolEntryServlet.java

private boolean isValid(RPEntity rp, IncomingRequest incomingRequest, HttpServletRequest request,
        HttpServletResponse response) throws IOException {

    LOG.debug("found RP: " + rp.getName());

    if (rp.isRequestSigningRequired()) {
        if (null == incomingRequest.getSpCertificate()) {
            request.getSession().setAttribute(this.protocolErrorMessageSessionAttributeInitParam,
                    "Request was not signed, which is required for this SP!");
            response.sendRedirect(request.getContextPath() + this.protocolErrorPageInitParam);
            return false;
        }/*from  ww  w  . ja v a 2s .c  o m*/
    }

    if (null != incomingRequest.getSpCertificate() && null != rp.getEncodedCertificate()) {

        // verify fingerprint
        try {
            String rpFingerprint = DigestUtils.shaHex(rp.getEncodedCertificate());
            String requestFingerPrint = DigestUtils.shaHex(incomingRequest.getSpCertificate().getEncoded());

            if (!rpFingerprint.equals(requestFingerPrint)) {
                request.getSession().setAttribute(this.protocolErrorMessageSessionAttributeInitParam,
                        "Request was not signed with the correct keystore!");
                response.sendRedirect(request.getContextPath() + this.protocolErrorPageInitParam);
                return false;
            }
        } catch (CertificateEncodingException e) {
            return false;
        }

    }

    // check whether relying party has been blocked
    Boolean blocked = this.rpService.getBlocked(rp);
    if (null != blocked) {
        if (blocked) {
            LOG.warn("blocked relying party: " + rp.getName());
            String blockedMessage = this.rpService.getBlockedMessage(rp);
            if (null == blockedMessage) {
                blockedMessage = "Unknown reason.";
            }
            HttpSession httpSession = request.getSession();
            httpSession.setAttribute(this.blockedMessageSessionAttributeInitParam, blockedMessage);
            response.sendRedirect(request.getContextPath() + this.blockedPageInitParam);
            return false;
        }
    }

    request.getSession().setAttribute(Constants.RP_SESSION_ATTRIBUTE, rp);
    return true;
}

From source file:jp.primecloud.auto.process.lb.PuppetLoadBalancerProcess.java

protected String getFileDigest(File file, String encoding) {
    if (!file.exists()) {
        return null;
    }//ww  w .jav  a 2  s  .  c o m
    try {
        String content = FileUtils.readFileToString(file, encoding);
        return DigestUtils.shaHex(content);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.ebay.pulsar.analytics.metricstore.druid.query.QueryTest.java

public void testTopNQuery() {
    String dataSource = "TopNQueryTest";
    String dimension = "Dimensions1";
    List<String> intervals = getIntervals();
    List<BaseAggregator> aggregations = getAggregators();
    BaseGranularity granularity = BaseGranularity.ALL;
    int threshold = 10;
    BaseMetric metric = getMetric();//from   w w w .j  a  v a 2 s.  c om

    TopNQuery topNQuery = new TopNQuery(dataSource, intervals, granularity, aggregations, dimension, threshold,
            metric);

    String dataSourceGot = topNQuery.getDataSource();
    String dimensionGot = topNQuery.getDimension();
    List<String> intervalsGot = topNQuery.getIntervals();
    topNQuery.getAggregations();
    BaseGranularity granularityGot = topNQuery.getGranularity();
    assertEquals("DataSource NOT Equals", dataSource, dataSourceGot);
    assertEquals("Intervals NOT Equals", intervals.get(0), intervalsGot.get(0));
    assertEquals("Dimensions NOT Equals", dimension, dimensionGot);
    assertEquals("Granularity NOT Equals", granularity, granularityGot);

    byte[] cacheKey = topNQuery.cacheKey();

    String hashCacheKeyExpected = "0492640363784ebece072be41b958ae170710b80";
    String hashCacheKeyGot = DigestUtils.shaHex(cacheKey);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot);

    topNQuery.toString();

    // TopNQuery with DurationGranularity
    DurationGranularity granularityDuration = new DurationGranularity("7200000");

    TopNQuery topNQuery1 = new TopNQuery(dataSource, intervals, granularityDuration, aggregations, dimension,
            threshold, metric);

    byte[] cacheKey1 = topNQuery1.cacheKey();

    String hashCacheKeyExpected1 = "6694ce551af03bef2b655a55f73e978cec53c05c";
    String hashCacheKeyGot1 = DigestUtils.shaHex(cacheKey1);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected1, hashCacheKeyGot1);

    List<BasePostAggregator> postAggregations = getPostAggregators();
    topNQuery1.setPostAggregations(postAggregations);

    cacheKey1 = topNQuery1.cacheKey();

    hashCacheKeyExpected1 = "303a95fb1ad9991c77b8efffab88d0ecb8628350";
    hashCacheKeyGot1 = DigestUtils.shaHex(cacheKey1);
    assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected1, hashCacheKeyGot1);

    QueryType type = topNQuery.getQueryType();
    assertEquals("Type NOT Equals", QueryType.topN, type);
}

From source file:com.alfaariss.oa.authentication.remote.saml2.SAML2AuthenticationMethod.java

/**
 * Establish the SAML2IDP using the PROXY_URLPATH_CONTEXT from the session<br/>
 * Also puts the SAML2IDP's EntityId in the Session as PROXY_SHADOWED_ENTITYID<br/>
 * <br/>//from   w  w w  . j  av  a 2s  .com
 * When no SAML2IDP match could be made, there will be no PROXY_SHADOWED_ENTITYID attribute
 * written in the session, and null is returned. 
 * 
 * @param oAttributes Session Attributes
 * @param oURLPathContext non-null initialized URLPathContext instance to process
 * @return SAML2IDP organization as established, or null when no match could be made
 */
protected SAML2IDP processURLPathContext(ISessionAttributes oAttributes, URLPathContext oURLPathContext)
        throws OAException {
    // Did we try to find a match before?
    if (oAttributes.contains(com.alfaariss.oa.util.session.ProxyAttributes.class,
            com.alfaariss.oa.util.session.ProxyAttributes.PROXY_SHADOWED_IDPID)) {
        String sShadowedEntityId = (String) oAttributes.get(com.alfaariss.oa.util.session.ProxyAttributes.class,
                com.alfaariss.oa.util.session.ProxyAttributes.PROXY_SHADOWED_IDPID);

        // Re-use this intelligence, and return the SAML2IDP instance
        IIDP oIDP = _organizationStorage.getIDP(sShadowedEntityId);
        if (oIDP instanceof SAML2IDP) {
            _logger.info("Found IDP '" + sShadowedEntityId + "' from previous URLPath Context match");
            return (SAML2IDP) oIDP;
        } else {
            _logger.warn("Non-SAML2IDP found in IDP Storage - inform developers of this condition! (1)");
            return null;
        }
    }

    String sIValue = oURLPathContext.getParams().get("i");
    if (sIValue == null) {
        _logger.info("No 'i' value found in URLPath Context path ('" + oURLPathContext + "')");
        return null;
    }

    List<IIDP> lAllIDPs = _organizationStorage.getAll();
    for (IIDP oIDP : lAllIDPs) {
        String sIDPEntityIdHash = DigestUtils.shaHex(oIDP.getID());
        if (sIDPEntityIdHash.equalsIgnoreCase(sIValue)) {
            _logger.info("Found IDP '" + oIDP.getID() + "' in matching URLPath Context");
            if (oIDP instanceof SAML2IDP) {
                // Store the IDP that was found on the map
                oAttributes.put(com.alfaariss.oa.util.session.ProxyAttributes.class,
                        com.alfaariss.oa.util.session.ProxyAttributes.PROXY_SHADOWED_IDPID, oIDP.getID());

                // Return result
                return (SAML2IDP) oIDP;
            } else {
                _logger.warn("Non-SAML2IDP found in IDP Storage - inform developers of this condition! (2)");
                return null;
            }
        }
    }

    _logger.info("No IDP found for provided i");
    return null;
}

From source file:com.google.appraise.eclipse.core.client.git.AppraiseGitReviewClient.java

/**
 * Gets all the comments for a specific review hash, by comment id.
 * The comment id is conventionally the SHA-1 hash of its JSON string.
 *//* w  w  w.jav  a  2 s  . c om*/
private Map<String, ReviewComment> listCommentsForReview(Git git, String requestCommitHash)
        throws GitClientException {
    // Get the most up-to-date list of comments.
    syncCommentsAndReviews();

    Map<String, ReviewComment> comments = new LinkedHashMap<>();
    try {
        String noteDataStr = readOneNote(git, COMMENTS_REF, requestCommitHash);
        if (noteDataStr != null) {
            for (String commentStr : noteDataStr.split("\n")) {
                try {
                    String commentId = DigestUtils.shaHex(commentStr);
                    ReviewComment comment = new Gson().fromJson(commentStr, ReviewComment.class);
                    if (comment != null) {
                        comments.put(commentId, comment);
                    }
                } catch (JsonSyntaxException jse) {
                    logger.warning("Failed to parse comment " + noteDataStr);
                }
            }
        }
    } catch (Exception e) {
        throw new GitClientException(e);
    }
    return comments;
}

From source file:io.milton.mini.services.CalendarService.java

public String getCalendarInvitationsCTag(Profile user) {
    try {/*from www  .  jav a  2 s  .com*/
        // combine and hash names and mod dates for AR's
        List<AttendeeRequest> list = getAttendeeRequests(user, true);
        MessageDigest cout = MessageDigest.getInstance("SHA");
        Charset charset = Charset.forName("UTF-8");
        for (AttendeeRequest ar : list) {
            String s = ar.getName() + "-" + ar.getOrganiserEvent().getModifiedDate() + "-"
                    + ar.getParticipationStatus();
            cout.update(s.getBytes(charset));
        }
        byte[] arr = cout.digest();
        String hash = DigestUtils.shaHex(arr);
        return hash;
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:com.alu.e3.data.DataManager.java

/**
 * Uses SHA1 algorithm to hash authId./* w w  w. j  av a 2 s.  co  m*/
 * @param auth
 * @return The hexa conversion of SHA-1(auth)
 */
private String hashAuthId(String auth) {
    return DigestUtils.shaHex(auth);
}

From source file:com.buddycloud.mediaserver.business.dao.MediaDAO.java

protected String getFileShaChecksum(File file) {
    try {/*from  ww  w  .  j  a va2 s  . c  o m*/
        return DigestUtils.shaHex(FileUtils.openInputStream(file));
    } catch (IOException e) {
        LOGGER.error("Error during media SHA1 checksum generation.", e);
    }

    return null;
}

From source file:be.fedict.eid.tsl.TrustServiceList.java

public String getSha1Fingerprint() {
    String fingerprint = DigestUtils.shaHex(toByteArray());
    return fingerprint;
}