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

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

Introduction

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

Prototype

String decrypt(String encryptedText);

Source Link

Document

Decrypt the encrypted text string.

Usage

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

@Test
public void createClient() {
    Account account = new Account();
    Role role = new Role();
    CreateClientDTO createClientDTO = new CreateClientDTO();
    createClientDTO.setName("new app's name");
    createClientDTO.setDescription("new app's description");
    createClientDTO.setHomepage("http://example.com");
    createClientDTO.setRedirectUri("http://example.com/redirect");

    when(mockAccountDao.findById(anyLong())).thenReturn(account);
    when(mockAccountDao.findByUsernameOrEmail(anyString())).thenReturn(account);
    when(mockRoleDao.findByName(anyString())).thenReturn(role);

    accountService.setMapper(mapper);/*from  ww  w  .  j  a v a2 s. c o  m*/
    GetClientDTO getClientDTO = accountService.createClient(1L, createClientDTO, "admin");

    ArgumentCaptor<Client> argument = ArgumentCaptor.forClass(Client.class);
    verify(mockClientDao).create(argument.capture());
    Client client = argument.getValue();
    assertEquals("new app's name", client.getName());
    assertEquals("new app's description", client.getDescription());
    assertEquals("http://example.com", client.getHomepage());
    assertEquals("http://example.com/redirect", client.getRedirectUri());
    assertTrue(client.getActive());
    assertTrue(client.getRoles().contains(role));
    assertNotNull(client.getClientId());
    assertNotNull(client.getClientSecret());

    TextEncryptor encryptor = Encryptors.text(TextUtil.convertStringToHex(accountService.getEncryptionKey()),
            TextUtil.convertStringToHex(client.getClientId()));
    assertEquals(getClientDTO.getClientSecret(), encryptor.decrypt(client.getClientSecret()));
}

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

/**
 * Get the plain text client_secret for the given client.
 * //from w w w .j  a v a 2s  .c om
 * @param client
 * @return
 */
private String decryptClientSecret(Client client) {
    TextEncryptor encryptor = Encryptors.text(TextUtil.convertStringToHex(encryptionKey),
            TextUtil.convertStringToHex(client.getClientId()));
    return encryptor.decrypt(client.getClientSecret());
}

From source file:org.springframework.cloud.config.server.encryption.EncryptionController.java

@RequestMapping(value = "/decrypt/{name}/{profiles}", method = RequestMethod.POST)
public String decrypt(@PathVariable String name, @PathVariable String profiles, @RequestBody String data,
        @RequestHeader("Content-Type") MediaType type) {
    checkEncryptorInstalled(name, profiles);
    try {/*from   w w w.ja  v a 2 s  .c  o m*/
        String input = stripFormData(data, type, true);
        Map<String, String> encryptorKeys = this.helper.getEncryptorKeys(name, profiles, input);
        TextEncryptor encryptor = this.encryptor.locate(encryptorKeys);
        String encryptedText = this.helper.stripPrefix(input);
        String decrypted = encryptor.decrypt(encryptedText);
        logger.info("Decrypted cipher data");
        return decrypted;
    } catch (IllegalArgumentException e) {
        throw new InvalidCipherException();
    }
}