Example usage for org.springframework.amqp.rabbit.connection RabbitConnectionFactoryBean setKeyStoreType

List of usage examples for org.springframework.amqp.rabbit.connection RabbitConnectionFactoryBean setKeyStoreType

Introduction

In this page you can find the example usage for org.springframework.amqp.rabbit.connection RabbitConnectionFactoryBean setKeyStoreType.

Prototype

public void setKeyStoreType(String keyStoreType) 

Source Link

Document

Set the key store type - overrides the property in #setSslPropertiesLocation(Resource) .

Usage

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testKSTS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);//from w ww  .  ja  v  a2  s  . c om
    fb.setKeyStoreType("JKS");
    fb.setKeyStoreResource(new ClassPathResource("test.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.setTrustStoreResource(new ClassPathResource("test.truststore.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.setSecureRandom(SecureRandom.getInstanceStrong());
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: ["), containsString("TM: ["), containsString("random: java.")));
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testNullTS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);/*w  w  w . j  a  v a2s. c  o  m*/
    fb.setKeyStoreType("JKS");
    fb.setKeyStoreResource(new ClassPathResource("test.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: ["), containsString("TM: null"), containsString("random: null")));
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testNullKS() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    Log logger = spy(TestUtils.getPropertyValue(fb, "logger", Log.class));
    given(logger.isDebugEnabled()).willReturn(true);
    new DirectFieldAccessor(fb).setPropertyValue("logger", logger);
    fb.setUseSSL(true);/* w  w w. j av  a 2  s . c  om*/
    fb.setKeyStoreType("JKS");
    fb.setTrustStoreResource(new ClassPathResource("test.truststore.ks"));
    fb.setKeyStorePassphrase("secret");
    fb.afterPropertiesSet();
    fb.getObject();
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(logger).debug(captor.capture());
    final String log = captor.getValue();
    assertThat(log, allOf(containsString("KM: null"), containsString("TM: ["), containsString("random: null")));
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testTypeSettersNoProps() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    fb.setKeyStoreType("alice");
    fb.setTrustStoreType("bob");
    assertEquals("alice", fb.getKeyStoreType());
    assertEquals("bob", fb.getTrustStoreType());
}

From source file:org.springframework.amqp.rabbit.connection.SSLConnectionTests.java

@Test
public void testTypeSettersOverrideProps() throws Exception {
    RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
    fb.setSslPropertiesLocation(new ClassPathResource("ssl.properties"));
    fb.afterPropertiesSet();//from  w w  w .j a  v a  2 s .c  o m
    fb.setKeyStoreType("alice");
    fb.setTrustStoreType("bob");
    try {
        fb.setUpSSL();
        // Here we make sure the exception is thrown because setUpSSL() will fail.
        //But we only care about having it load the props
        fail("setupSSL should fail");
    } catch (Exception e) {
        assertEquals("alice", fb.getKeyStoreType());
        assertEquals("bob", fb.getTrustStoreType());
    }
}