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:org.overlord.sramp.repository.jcr.JCRExtensions.java

/**
 * Generate the SHA-1 hash for the given {@link Binary} value.
 * //w  w  w . jav a  2 s .co m
 * @param binary The Binary value to hash
 * @return String the SHA-1 hash
 * @throws Exception
 */
public String getSha1Hash(Binary binary) throws Exception {
    InputStream inputStream = null;
    try {
        inputStream = binary.getStream();
        String shaHex = DigestUtils.shaHex(inputStream);
        return shaHex;
    } finally {
        if (inputStream != null) {
            IOUtils.closeQuietly(inputStream);
        }
    }
}

From source file:org.overlord.sramp.shell.commands.maven.DeployCommand.java

/**
 * Execute./* www.  j a  va2 s.  c  om*/
 *
 * @return true, if successful
 * @throws Exception
 *             the exception
 */
@Override
public boolean execute() throws Exception {
    String filePathArg = this.requiredArgument(0,
            Messages.i18n.format("DeployCommand.InvalidArgMsg.LocalFile")); //$NON-NLS-1$
    String gavArg = this.requiredArgument(1, Messages.i18n.format("DeployCommand.InvalidArgMsg.GAVInfo")); //$NON-NLS-1$
    String artifactTypeArg = this.optionalArgument(2);

    QName clientVarName = new QName("s-ramp", "client"); //$NON-NLS-1$ //$NON-NLS-2$
    SrampAtomApiClient client = (SrampAtomApiClient) getContext().getVariable(clientVarName);
    if (client == null) {
        print(Messages.i18n.format("MissingSRAMPConnection")); //$NON-NLS-1$
        return false;
    }

    // Validate the file
    File file = new File(filePathArg);
    if (!file.isFile()) {
        print(Messages.i18n.format("DeployCommand.FileNotFound", filePathArg)); //$NON-NLS-1$
        return false;
    }

    InputStream content = null;
    try {
        ArtifactType artifactType = null;
        if (artifactTypeArg != null) {
            artifactType = ArtifactType.valueOf(artifactTypeArg);
            if (artifactType.isExtendedType()) {
                artifactType = ArtifactType.ExtendedDocument(artifactType.getExtendedType());
            }
        }
        // Process GAV and other meta-data, then update the artifact
        MavenGavInfo mavenGavInfo = MavenGavInfo.fromCommandLine(gavArg, file);
        if (mavenGavInfo.getType() == null) {
            print(Messages.i18n.format("DeployCommand.TypeNotSet", file.getName())); //$NON-NLS-1$
            IOUtils.closeQuietly(content);
            return false;
        }
        if (!allowSnapshot && mavenGavInfo.isSnapshot()) {
            print(Messages.i18n.format("DeployCommand.SnapshotNotAllowed", gavArg)); //$NON-NLS-1$
            IOUtils.closeQuietly(content);
            return false;
        }
        BaseArtifactType artifact = findExistingArtifactByGAV(client, mavenGavInfo);
        if (artifact != null) {
            print(Messages.i18n.format("DeployCommand.Failure.ReleaseArtifact.Exist", gavArg)); //$NON-NLS-1$
            IOUtils.closeQuietly(content);
            return false;
        } else {
            content = FileUtils.openInputStream(file);
            artifact = client.uploadArtifact(artifactType, content, file.getName());
            IOUtils.closeQuietly(content);
        }

        // Process GAV and other meta-data, then update the artifact
        String artifactName = mavenGavInfo.getArtifactId() + '-' + mavenGavInfo.getVersion();
        String pomName = mavenGavInfo.getArtifactId() + '-' + mavenGavInfo.getVersion() + ".pom"; //$NON-NLS-1$
        SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_GROUP_ID, mavenGavInfo.getGroupId());
        SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_ARTIFACT_ID,
                mavenGavInfo.getArtifactId());
        SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_VERSION, mavenGavInfo.getVersion());
        SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_HASH_MD5, mavenGavInfo.getMd5());
        SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_HASH_SHA1, mavenGavInfo.getSha1());
        if (StringUtils.isNotBlank(mavenGavInfo.getSnapshotId())) {
            SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_SNAPSHOT_ID,
                    mavenGavInfo.getSnapshotId());
        } else if (mavenGavInfo.isSnapshot()) {
            SrampModelUtils.setCustomProperty(artifact, JavaModel.PROP_MAVEN_SNAPSHOT_ID,
                    generateSnapshotTimestamp());
        }
        if (mavenGavInfo.getClassifier() != null) {
            SrampModelUtils.setCustomProperty(artifact, "maven.classifier", mavenGavInfo.getClassifier()); //$NON-NLS-1$
            artifactName += '-' + mavenGavInfo.getClassifier();
        }
        if (mavenGavInfo.getType() != null) {
            SrampModelUtils.setCustomProperty(artifact, "maven.type", mavenGavInfo.getType()); //$NON-NLS-1$
            artifactName += '.' + mavenGavInfo.getType();
        }
        artifact.setName(artifactName);
        client.updateArtifactMetaData(artifact);

        // Generate and add a POM for the artifact
        String pom = generatePom(mavenGavInfo);
        InputStream pomContent = new ByteArrayInputStream(pom.getBytes("UTF-8")); //$NON-NLS-1$
        BaseArtifactType pomArtifact = ArtifactType.ExtendedDocument(JavaModel.TYPE_MAVEN_POM_XML)
                .newArtifactInstance();
        pomArtifact.setName(pomName);
        SrampModelUtils.setCustomProperty(pomArtifact, JavaModel.PROP_MAVEN_TYPE, "pom"); //$NON-NLS-1$
        SrampModelUtils.setCustomProperty(pomArtifact, JavaModel.PROP_MAVEN_HASH_MD5, DigestUtils.md5Hex(pom));
        SrampModelUtils.setCustomProperty(pomArtifact, JavaModel.PROP_MAVEN_HASH_SHA1, DigestUtils.shaHex(pom));

        BaseArtifactType returned = client.uploadArtifact(pomArtifact, pomContent);

        // Put the artifact in the session as the active artifact
        QName artifactVarName = new QName("s-ramp", "artifact"); //$NON-NLS-1$ //$NON-NLS-2$
        getContext().setVariable(artifactVarName, artifact);
        print(Messages.i18n.format("DeployCommand.Success")); //$NON-NLS-1$
        PrintArtifactMetaDataVisitor visitor = new PrintArtifactMetaDataVisitor();
        ArtifactVisitorHelper.visitArtifact(visitor, artifact);
    } catch (Exception e) {
        print(Messages.i18n.format("DeployCommand.Failure")); //$NON-NLS-1$
        print("\t" + e.getMessage()); //$NON-NLS-1$
        IOUtils.closeQuietly(content);
        return false;
    }
    return true;
}

From source file:org.ow2.clif.jenkins.chart.ChartId.java

public String getId() {
    return DigestUtils.shaHex(chartType + testplan + bladeId + event);
}

From source file:org.ralasafe.encrypt.ShaEncrypt.java

public String encrypt(String rawTxt) {
    if (rawTxt == null) {
        return null;
    }
    return DigestUtils.shaHex(rawTxt);
}

From source file:org.saadahmed.snowcrystal.SnowCrystal.java

public static String sha1Hex() {
    return DigestUtils.shaHex(SnowCrystal.newId().unwrap());
}

From source file:org.sakaiproject.bbb.impl.bbbapi.BaseBBBAPI.java

/** Compute the query string checksum based on the security salt */
protected String getCheckSumParameterForQuery(String apiCall, String queryString) {
    if (bbbSalt != null)
        return "&checksum=" + DigestUtils.shaHex(apiCall + queryString + bbbSalt);
    else/*  www  . j  a  v  a  2 s .  c  om*/
        return "";
}

From source file:org.sakaiproject.bbb.impl.bbbapi.BBBAPI_063.java

protected String getCheckSumParameterForQuery(String apiCall, String queryString) {
    if (bbbSalt != null)
        return "&checksum=" + DigestUtils.shaHex(queryString + bbbSalt);
    else/*from   w  w  w  . j  a  v a 2 s.c o m*/
        return "";
}

From source file:org.sakaiproject.kernel.auth.ldap.guards.Sha1PasswordGuard.java

/**
 * {@inheritDoc}/*from  w  w  w .  ja  v  a  2s . c o m*/
 *
 * @see org.sakaiproject.kernel.api.auth.ldap.PasswordGuard#guard(java.lang.String)
 */
public String guard(String password) {
    String guarded = DigestUtils.shaHex(password);
    return guarded;
}

From source file:org.schedulesdirect.api.NetworkEpgClient.java

/**
 * Perform user authorization with Schedules Direct
 * @throws InvalidCredentialsException Thrown if authorization failed
 * @throws IOException Thrown on any IO error communicating with the Schedules Direct servers
 * @throws ServiceOfflineException Thrown if the web service reports itself as offline/unavailable
 * @throws InvalidJsonObjectException Thrown if the response object is not in the expected format
 *//*from   w w w  .  j  ava2  s  .  co m*/
protected void authorize()
        throws InvalidJsonObjectException, InvalidCredentialsException, IOException, ServiceOfflineException {
    JSONObject creds = new JSONObject();
    creds.put("username", id);
    /*
     *  Using the deprecated shaHex() b/c some people still use very old
     *  version of commons-codec; SageTV being an example
     */
    creds.put("password", DigestUtils.shaHex(password));

    JSONObject resp;
    String input = factory
            .get(DefaultJsonRequest.Action.POST, RestNouns.LOGIN_TOKEN, hash, getUserAgent(), getBaseUrl())
            .submitForJson(creds);
    try {
        resp = Config.get().getObjectMapper().readValue(input, JSONObject.class);
    } catch (JsonParseException e) {
        throw new JsonEncodingException(String.format("Token: %s", e.getMessage()), e, input);
    }
    if (!JsonResponseUtils.isErrorResponse(resp)) {
        try {
            hash = resp.getString("token");
        } catch (JSONException e) {
            throw new InvalidJsonObjectException(String.format("Token: %s", e.getMessage()), e,
                    resp.toString(3));
        }
    } else if (resp.optInt("code", ApiResponse.NOT_PROVIDED) == ApiResponse.SERVICE_OFFLINE)
        throw new ServiceOfflineException(resp.optString("message"));
    else
        throw new InvalidCredentialsException(resp.optString("message"));
}

From source file:org.slc.sli.common.util.uuid.DeterministicUUIDGeneratorStrategy.java

@Override
public String generateId(NaturalKeyDescriptor naturalKeyDescriptor) {

    // if no natural keys exist, can't generate deterministic id
    if (naturalKeyDescriptor == null || naturalKeyDescriptor.getNaturalKeys() == null
            || naturalKeyDescriptor.getNaturalKeys().isEmpty()) {
        return generateId();
    }/*from  w w w  . j a  v a  2s. co m*/

    // Get values in alphabetical order
    Map<String, String> naturalKeys = naturalKeyDescriptor.getNaturalKeys();
    List<String> keyList = new ArrayList<String>(naturalKeys.keySet());
    Collections.sort(keyList);

    // Concatenate values together into one string
    StringBuffer keyValues = new StringBuffer();
    keyValues.append(escapeDelimiters(naturalKeyDescriptor.getEntityType())).append(DELIMITER);
    keyValues.append(escapeDelimiters(naturalKeyDescriptor.getTenantId())).append(DELIMITER);
    for (String key : keyList) {
        keyValues.append(escapeDelimiters(naturalKeys.get(key))).append(DELIMITER);
    }
    // Digest keyValue string into hash
    String hexHash = DigestUtils.shaHex(keyValues.toString().getBytes());
    if (naturalKeyDescriptor.getParentId() != null) {
        hexHash = naturalKeyDescriptor.getParentId() + hexHash;
    }
    return hexHash + "_id";
}