@Test (expectedExceptions = TokenStrategyFailedException.class) public void shouldThrowExceptionIfDecryptionFails() throws Exception { DecryptAction mockDecryptAction = mock(DecryptAction.class); EncryptionStrategy strategy = new EncryptionStrategy( mock(EncryptAction.class), mockDecryptAction, mock(Debug.class)); given(mockDecryptAction.run()).willThrow(new Exception()); strategy.reverse(mock(Token.class)); }
public void reverse(Token token) throws TokenStrategyFailedException { try { decyptAction.setBlob(token.getBlob()); byte[] decryptedBlob = AccessController.doPrivileged(decyptAction); token.setBlob(decryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Decrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to decrypt JSON Blob", e); } }
EncryptionStrategy implements BlobStrategy { public void reverse(Token token) throws TokenStrategyFailedException { try { decyptAction.setBlob(token.getBlob()); byte[] decryptedBlob = AccessController.doPrivileged(decyptAction); token.setBlob(decryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Decrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to decrypt JSON Blob", e); } } }
EncryptionStrategy implements BlobStrategy { public void reverse(Token token) throws TokenStrategyFailedException { try { decyptAction.setBlob(token.getBlob()); byte[] decryptedBlob = AccessController.doPrivileged(decyptAction); token.setBlob(decryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Decrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to decrypt JSON Blob", e); } } @Inject  EncryptionStrategy(EncryptAction encyptionAction, DecryptAction decyptAction,
                              @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); }
EncryptionStrategy implements BlobStrategy { public void reverse(Token token) throws TokenStrategyFailedException { try { decyptAction.setBlob(token.getBlob()); byte[] decryptedBlob = AccessController.doPrivileged(decyptAction); token.setBlob(decryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Decrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to decrypt JSON Blob", e); } } @Inject  EncryptionStrategy(EncryptAction encyptionAction, DecryptAction decyptAction,
                              @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); void perform(Token token); void reverse(Token token); }
EncryptionStrategy implements BlobStrategy { public void reverse(Token token) throws TokenStrategyFailedException { try { decyptAction.setBlob(token.getBlob()); byte[] decryptedBlob = AccessController.doPrivileged(decyptAction); token.setBlob(decryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Decrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to decrypt JSON Blob", e); } } @Inject  EncryptionStrategy(EncryptAction encyptionAction, DecryptAction decyptAction,
                              @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); void perform(Token token); void reverse(Token token);  }