Skip to content

Commit

Permalink
Merge pull request #50 from ulfsauer0815/custom-encryption-listener-b…
Browse files Browse the repository at this point in the history
…ean-registration-fails

Fix custom EncryptionEventListener bean registration
  • Loading branch information
agoston authored Jul 9, 2021
2 parents 2863a01 + 2244dbd commit 58cb836
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/bol/config/EncryptAutoConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CryptVault cryptVault(EncryptConfigurationProperties properties) {
}

@Bean
@ConditionalOnMissingBean({ReflectionEncryptionEventListener.class, CachedEncryptionEventListener.class})
@ConditionalOnMissingBean({AbstractEncryptionEventListener.class})
@ConditionalOnBean(CryptVault.class)
AbstractEncryptionEventListener encryptionEventListener(CryptVault cryptVault, EncryptConfigurationProperties properties) {
AbstractEncryptionEventListener eventListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.bol.system.autoconfig;

import com.bol.config.EncryptAutoConfiguration;
import com.bol.crypt.CryptVault;
import com.bol.secure.AbstractEncryptionEventListener;
import com.bol.secure.CachedEncryptionEventListener;
import com.bol.secure.ReflectionEncryptionEventListener;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;

@ActiveProfiles("autoconfig-short")
@RunWith(SpringRunner.class)
@EnableAutoConfiguration
@SpringBootTest(classes = {EncryptionWithCustomAbstractEventListenerTest.class, EncryptionWithCustomAbstractEventListenerTest.AbstractEventListenerConfig.class, EncryptAutoConfiguration.class})
public class EncryptionWithCustomAbstractEventListenerTest {

@Autowired(required = false) CryptVault cryptVault;
@Autowired(required = false) AbstractEncryptionEventListener<?> eventListener;

@Test
public void sanityTest() {
assertThat(cryptVault).isNotNull();
assertThat(eventListener).isNotNull();
assertThat(eventListener).isInstanceOf(ReflectionEncryptionEventListener.class);
}


@TestConfiguration
static class AbstractEventListenerConfig {
@Bean
AbstractEncryptionEventListener<?> encryptionEventListener(CryptVault cryptVault) {
return new ReflectionEncryptionEventListener(cryptVault);
}
}
}

0 comments on commit 58cb836

Please sign in to comment.