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

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

Introduction

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

Prototype

public static String sha1Hex(String data) 

Source Link

Usage

From source file:io.apiman.test.policies.EchoBackEndService.java

/**
 * @see io.apiman.test.policies.IPolicyTestBackEndService#invoke(io.apiman.gateway.engine.beans.ServiceRequest, byte[])
 *///  w w  w  .  j a va 2 s.  co  m
@Override
public PolicyTestBackEndServiceResponse invoke(ServiceRequest request, byte[] requestBody) {
    try {
        EchoResponse echoResponse = new EchoResponse();
        if (requestBody != null) {
            echoResponse.setBodyLength(new Long(requestBody.length));
            echoResponse.setBodySha1(DigestUtils.sha1Hex(requestBody));
        }
        echoResponse.setCounter(counter++);
        echoResponse.setHeaders(request.getHeaders());
        echoResponse.setMethod(request.getType());
        echoResponse.setResource(request.getDestination());
        echoResponse.setUri("urn:" + request.getDestination()); //$NON-NLS-1$

        ServiceResponse serviceResponse = new ServiceResponse();
        serviceResponse.setCode(200);
        serviceResponse.setMessage("OK"); //$NON-NLS-1$
        serviceResponse.getHeaders().put("Date", new Date().toString()); //$NON-NLS-1$
        serviceResponse.getHeaders().put("Server", "apiman.policy-test"); //$NON-NLS-1$ //$NON-NLS-2$
        serviceResponse.getHeaders().put("Content-Type", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$

        String responseBody = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(echoResponse);
        serviceResponse.getHeaders().put("Content-Length", String.valueOf(responseBody.length())); //$NON-NLS-1$

        PolicyTestBackEndServiceResponse response = new PolicyTestBackEndServiceResponse(serviceResponse,
                responseBody);
        return response;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.tikinou.schedulesdirect.core.domain.Credentials.java

public Credentials(String username, String password, String token, DateTime tokenDateTime) {
    this.username = username;
    this.clearPassword = password;
    this.token = token;
    this.tokenDateTime = tokenDateTime;
    if (clearPassword != null)
        this.password = DigestUtils.sha1Hex(clearPassword);
}

From source file:io.apiman.test.policies.EchoBackEndApi.java

/**
 * @see io.apiman.test.policies.IPolicyTestBackEndApi#invoke(io.apiman.gateway.engine.beans.ApiRequest, byte[])
 *///from   w  w  w.j  a v a  2 s  .c  o  m
@Override
public PolicyTestBackEndApiResponse invoke(ApiRequest request, byte[] requestBody) {
    try {
        EchoResponse echoResponse = new EchoResponse();
        if (requestBody != null) {
            echoResponse.setBodyLength(new Long(requestBody.length));
            echoResponse.setBodySha1(DigestUtils.sha1Hex(requestBody));
        }
        echoResponse.setCounter(counter++);
        echoResponse.setHeaders(request.getHeaders().toMap());
        echoResponse.setMethod(request.getType());
        echoResponse.setResource(request.getDestination());
        echoResponse.setUri("urn:" + request.getDestination());

        ApiResponse apiResponse = new ApiResponse();

        String errorCode = request.getHeaders().get("X-Echo-ErrorCode");
        if (errorCode != null) {
            int ec = new Integer(errorCode);
            String errorMsg = request.getHeaders().get("X-Echo-ErrorMessage");
            apiResponse.setCode(ec);
            apiResponse.setMessage(errorMsg);
        } else {
            apiResponse.setCode(200);
            apiResponse.setMessage("OK");
        }
        apiResponse.getHeaders().put("Date", new Date().toString());
        apiResponse.getHeaders().put("Server", "apiman.policy-test");
        apiResponse.getHeaders().put("Content-Type", "application/json");

        String responseBody = normalize(
                mapper.writerWithDefaultPrettyPrinter().writeValueAsString(echoResponse));
        apiResponse.getHeaders().put("Content-Length", String.valueOf(responseBody.length()));

        PolicyTestBackEndApiResponse response = new PolicyTestBackEndApiResponse(apiResponse, responseBody);
        return response;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.monitor.baseservice.utils.XCodeUtil.java

public static String getSHA1(InputStream is) throws IOException {
    try {// w  w w .j  a  v a2  s .c  om
        return DigestUtils.sha1Hex(is);
    } finally {
        is.close();
    }
}

From source file:net.exclaimindustries.paste.braket.server.LogInServiceImpl.java

@Override
public User logIn(String requestUri) throws NoSuchAlgorithmException {
    UserService userService = UserServiceFactory.getUserService();
    com.google.appengine.api.users.User user = userService.getCurrentUser();

    User braketUser;//from   ww w  .  j a v  a  2  s .com
    if (user != null) {
        // Look up the user's information

        // The user's ID should be protected
        String userId = DigestUtils.sha1Hex(user.getUserId() + "//braket-o-matic");

        // Load from the datastore
        Key<User> key = Key.create(User.class, userId);
        braketUser = OfyService.ofy().load().key(key).now();

        // If that returns null, then make a user and write it
        if (braketUser == null) {
            braketUser = new User(userId);
            braketUser.setEmail(user.getEmail());
            OfyService.ofy().save().entity(braketUser);
        }

        braketUser.setLogOutLink(userService.createLogoutURL(requestUri));
        braketUser.setLoggedIn(true);
        braketUser.setAdmin(userService.isUserAdmin());
    } else {
        // Not signed in, so don't do anything with the database.
        braketUser = new User();
        braketUser.setLogInLink(userService.createLoginURL(requestUri));
    }
    return braketUser;
}

From source file:com.yahoo.pulsar.client.impl.ReaderImpl.java

public ReaderImpl(PulsarClientImpl client, String topic, MessageId startMessageId,
        ReaderConfiguration readerConfiguration, ExecutorService listenerExecutor,
        CompletableFuture<Consumer> consumerFuture) {

    String subscription = "reader-" + DigestUtils.sha1Hex(UUID.randomUUID().toString()).substring(0, 10);

    ConsumerConfiguration consumerConfiguration = new ConsumerConfiguration();
    consumerConfiguration.setSubscriptionType(SubscriptionType.Exclusive);
    consumerConfiguration.setReceiverQueueSize(readerConfiguration.getReceiverQueueSize());
    if (readerConfiguration.getReaderName() != null) {
        consumerConfiguration.setConsumerName(readerConfiguration.getReaderName());
    }/*from   ww  w .ja  v a2 s.co m*/

    if (readerConfiguration.getReaderListener() != null) {
        ReaderListener readerListener = readerConfiguration.getReaderListener();
        consumerConfiguration.setMessageListener((consumer, msg) -> {
            readerListener.received(this, msg);
            consumer.acknowledgeCumulativeAsync(msg);
        });
    }

    consumer = new ConsumerImpl(client, topic, subscription, consumerConfiguration, listenerExecutor, -1,
            consumerFuture, SubscriptionMode.NonDurable, startMessageId);
}

From source file:io.github.sislivros.model.LoginBo.java

/**
 * Atraves do email e da senha criptografada, verifica se o usuario extiste
 * no banco de dados//w  w w .ja va 2s .  c  om
 * @param email
 * @param senha
 * @return Usuario correspondente
 */
public Usuario login(String email, String senha) {
    Usuario usuario;

    if (usuarioDao == null)
        usuarioDao = new UsuarioBdDao();

    usuario = usuarioDao.login(email, DigestUtils.sha1Hex(senha));

    return usuario;
}

From source file:br.com.bob.dashboard.model.User.java

public void setPassword(String password) {
    this.password = DigestUtils.sha1Hex(password);
}

From source file:com.monitor.baseservice.utils.XCodeUtil.java

public static String getSHA1(byte[] data) {
    return DigestUtils.sha1Hex(data);
}

From source file:com.nextdoor.bender.InternalEvent.java

/**
 * @param eventString the raw string data of the event.
 * @param context lambda context of the function.
 * @param arrivalTime epoch time in MS when the event arrived.
 *//*from ww  w. j  av a2s .c o m*/
public InternalEvent(String eventString, LambdaContext context, long arrivalTime) {
    this.eventString = eventString;
    this.context = context;
    this.eventSha1Hash = DigestUtils.sha1Hex(this.eventString);
    this.arrivalTime = arrivalTime;
    this.eventTime = arrivalTime;

    this.metadata.put("arrivalEpochMs", new Long(this.arrivalTime));
    this.metadata.put("eventSha1Hash", this.getEventSha1Hash());
}