@Test (expectedExceptions = TokenStrategyFailedException.class) public void shouldThrowExceptionIfEncryptionFails() throws Exception { EncryptAction mockEncryptAction = mock(EncryptAction.class); EncryptionStrategy strategy = new EncryptionStrategy( mockEncryptAction, mock(DecryptAction.class), mock(Debug.class)); given(mockEncryptAction.run()).willThrow(new Exception()); strategy.perform(mock(Token.class)); }
public void perform(Token token) throws TokenStrategyFailedException { try { encyptionAction.setBlob(token.getBlob()); byte[] encryptedBlob = AccessController.doPrivileged(encyptionAction); token.setBlob(encryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Encrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to encrypt JSON Blob", e); } }
EncryptionStrategy implements BlobStrategy { public void perform(Token token) throws TokenStrategyFailedException { try { encyptionAction.setBlob(token.getBlob()); byte[] encryptedBlob = AccessController.doPrivileged(encyptionAction); token.setBlob(encryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Encrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to encrypt JSON Blob", e); } } }
EncryptionStrategy implements BlobStrategy { public void perform(Token token) throws TokenStrategyFailedException { try { encyptionAction.setBlob(token.getBlob()); byte[] encryptedBlob = AccessController.doPrivileged(encyptionAction); token.setBlob(encryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Encrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to encrypt JSON Blob", e); } } @Inject  EncryptionStrategy(EncryptAction encyptionAction, DecryptAction decyptAction,
                              @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); }
EncryptionStrategy implements BlobStrategy { public void perform(Token token) throws TokenStrategyFailedException { try { encyptionAction.setBlob(token.getBlob()); byte[] encryptedBlob = AccessController.doPrivileged(encyptionAction); token.setBlob(encryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Encrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to encrypt 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 perform(Token token) throws TokenStrategyFailedException { try { encyptionAction.setBlob(token.getBlob()); byte[] encryptedBlob = AccessController.doPrivileged(encyptionAction); token.setBlob(encryptedBlob); if (debug.messageEnabled()) { debug.message(CoreTokenConstants.DEBUG_HEADER + "Encrypted Token"); } } catch (PrivilegedActionException e) { throw new TokenStrategyFailedException("Failed to encrypt JSON Blob", e); } } @Inject  EncryptionStrategy(EncryptAction encyptionAction, DecryptAction decyptAction,
                              @Named(CoreTokenConstants.CTS_DEBUG) Debug debug); void perform(Token token); void reverse(Token token);  }