Example usage for org.springframework.security.crypto.encrypt TextEncryptor encrypt

List of usage examples for org.springframework.security.crypto.encrypt TextEncryptor encrypt

Introduction

In this page you can find the example usage for org.springframework.security.crypto.encrypt TextEncryptor encrypt.

Prototype

String encrypt(String text);

Source Link

Document

Encrypt the raw text string.

Usage

From source file:org.unidle.support.Functions.java

public static Function<? super UserConnection, ? extends ConnectionData> toConnectionData(
        final TextEncryptor textEncryptor) {
    return new Function<UserConnection, ConnectionData>() {
        @Override/*from  w w  w.jav  a2s. c  o m*/
        public ConnectionData apply(final UserConnection input) {

            if (input == null) {
                return null;
            }

            final String accessToken = input.getAccessToken() == null ? null
                    : textEncryptor.encrypt(input.getAccessToken());

            final String secret = input.getSecret() == null ? null : textEncryptor.encrypt(input.getSecret());

            final String refreshToken = input.getRefreshToken() == null ? null
                    : textEncryptor.encrypt(input.getRefreshToken());

            return new ConnectionData(input.getProviderId(), input.getProviderUserId(), input.getDisplayName(),
                    input.getProfileUrl(), input.getImageUrl(), accessToken, secret, refreshToken,
                    input.getExpireTime());
        }
    };
}

From source file:org.unidle.support.Functions.java

public static Function<? super ConnectionData, ? extends UserConnection> toUserConnection(
        final UserConnection userConnection, final TextEncryptor textEncryptor, final Integer rank,
        final User user) {
    return new Function<ConnectionData, UserConnection>() {
        @Override//from w ww  . j a  v  a  2 s  .c o m
        public UserConnection apply(final ConnectionData input) {

            if (input == null) {
                return null;
            }

            userConnection.setDisplayName(input.getDisplayName());
            userConnection.setExpireTime(input.getExpireTime());
            userConnection.setImageUrl(input.getImageUrl());
            userConnection.setProfileUrl(input.getProfileUrl());
            userConnection.setProviderId(input.getProviderId());
            userConnection.setProviderUserId(input.getProviderUserId());
            userConnection.setRank(rank);
            userConnection.setUser(user);

            if (input.getAccessToken() != null) {
                userConnection.setAccessToken(textEncryptor.encrypt(input.getAccessToken()));
            }

            if (input.getRefreshToken() != null) {
                userConnection.setRefreshToken(textEncryptor.encrypt(input.getRefreshToken()));
            }

            if (input.getSecret() != null) {
                userConnection.setSecret(textEncryptor.encrypt(input.getSecret()));
            }

            return userConnection;
        }
    };
}

From source file:com.ushahidi.swiftriver.core.api.service.AccountService.java

/**
 * Sets a random client_id and client_secret in the given Client object.
 * //from   www .  ja va 2s  . c  o m
 * @param client
 * @return The plain text secret.
 */
private String resetClientCredentials(Client client) {
    // Reset the client credentials
    String clientId = UUID.randomUUID().toString();
    String secret = UUID.randomUUID().toString();

    // Encrypt the secret
    TextEncryptor encryptor = Encryptors.text(TextUtil.convertStringToHex(encryptionKey),
            TextUtil.convertStringToHex(clientId));
    client.setClientSecret(encryptor.encrypt(secret));
    client.setClientId(clientId);

    return secret;
}