Search in sources :

Example 1 with SSLClientAuthentication

use of jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication in project jaxrs-api by eclipse-ee4j.

the class ExplicitJavaSeBootstrapExample method main.

/**
 * Runs this example.
 *
 * @param args configuration to be used in exact this order: {@code PROTOCOL HOST PORT ROOT_PATH CLIENT_AUTH} where the
 * protocol can be either {@code HTTP} or {@code HTTPS} and the client authentication is one of
 * {@code NONE, OPTIONAL, MANDATORY}.
 * @throws InterruptedException when process is killed
 */
public static void main(final String[] args) throws InterruptedException {
    final Application application = new HelloWorld();
    final String protocol = args[0];
    final String host = args[1];
    final int port = Integer.parseInt(args[2]);
    final String rootPath = args[3];
    final SSLClientAuthentication clientAuth = SSLClientAuthentication.valueOf(args[4]);
    final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().protocol(protocol).host(host).port(port).rootPath(rootPath).sslClientAuthentication(clientAuth).build();
    SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
        instance.stopOnShutdown(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n", stopResult, stopResult.unwrap(Object.class)));
        final URI uri = instance.configuration().baseUri();
        System.out.printf("Instance %s running at %s [Native handle: %s].%n", instance, uri, instance.unwrap(Object.class));
        System.out.println("Send SIGKILL to shutdown.");
    });
    Thread.currentThread().join();
}
Also used : SSLClientAuthentication(jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication) SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) URI(java.net.URI)

Example 2 with SSLClientAuthentication

use of jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication in project jaxrs-api by eclipse-ee4j.

the class SeBootstrapTest method shouldPushCorrespondingPropertiesIntoConfigurationBuilder.

/**
 * Assert that {@code Configuration.Builder}'s convenience methods delegate to its generic {@code property(name, value)}
 * method using the <em>right</em> property name.
 *
 * @since 3.1
 */
@Test
public void shouldPushCorrespondingPropertiesIntoConfigurationBuilder() {
    // given
    final String someProtocolValue = mockString();
    final String someHostValue = mockString();
    final int somePortValue = mockInt();
    final String someRootPathValue = mockString();
    final SSLContext someSSLContextValue = mock(SSLContext.class);
    final SSLClientAuthentication someSSLClientAuthenticationValue = SSLClientAuthentication.MANDATORY;
    final SeBootstrap.Configuration.Builder configurationBuilder = spy(SeBootstrap.Configuration.Builder.class);
    // when
    configurationBuilder.protocol(someProtocolValue);
    configurationBuilder.host(someHostValue);
    configurationBuilder.port(somePortValue);
    configurationBuilder.rootPath(someRootPathValue);
    configurationBuilder.sslContext(someSSLContextValue);
    configurationBuilder.sslClientAuthentication(someSSLClientAuthenticationValue);
    // then
    verify(configurationBuilder).property(SeBootstrap.Configuration.PROTOCOL, someProtocolValue);
    verify(configurationBuilder).property(SeBootstrap.Configuration.HOST, someHostValue);
    verify(configurationBuilder).property(SeBootstrap.Configuration.PORT, somePortValue);
    verify(configurationBuilder).property(SeBootstrap.Configuration.ROOT_PATH, someRootPathValue);
    verify(configurationBuilder).property(SeBootstrap.Configuration.SSL_CONTEXT, someSSLContextValue);
    verify(configurationBuilder).property(SeBootstrap.Configuration.SSL_CLIENT_AUTHENTICATION, someSSLClientAuthenticationValue);
}
Also used : Configuration(jakarta.ws.rs.SeBootstrap.Configuration) SSLClientAuthentication(jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.jupiter.api.Test)

Example 3 with SSLClientAuthentication

use of jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication in project jaxrs-api by eclipse-ee4j.

the class SeBootstrapTest method shouldPullCorrespondingPropertiesFromConfiguration.

/**
 * Assert that {@code Configuration}'s convenience methods delegate to its generic {@code property(name)} method using
 * the <em>right</em> property name.
 *
 * @since 3.1
 */
@Test
public void shouldPullCorrespondingPropertiesFromConfiguration() {
    // given
    final String someProtocolValue = mockString();
    final String someHostValue = mockString();
    final int somePortValue = mockInt();
    final String someRootPathValue = mockString();
    final SSLContext someSSLContextValue = mock(SSLContext.class);
    final SSLClientAuthentication someSSLClientAuthenticationValue = SSLClientAuthentication.MANDATORY;
    final SeBootstrap.Configuration configuration = spy(SeBootstrap.Configuration.class);
    given(configuration.property(SeBootstrap.Configuration.PROTOCOL)).willReturn(someProtocolValue);
    given(configuration.property(SeBootstrap.Configuration.HOST)).willReturn(someHostValue);
    given(configuration.property(SeBootstrap.Configuration.PORT)).willReturn(somePortValue);
    given(configuration.property(SeBootstrap.Configuration.ROOT_PATH)).willReturn(someRootPathValue);
    given(configuration.property(SeBootstrap.Configuration.SSL_CONTEXT)).willReturn(someSSLContextValue);
    given(configuration.property(SeBootstrap.Configuration.SSL_CLIENT_AUTHENTICATION)).willReturn(someSSLClientAuthenticationValue);
    // when
    final String actualProtocolValue = configuration.protocol();
    final String actualHostValue = configuration.host();
    final int actualPortValue = configuration.port();
    final String actualRootPathValue = configuration.rootPath();
    final SSLContext actualSSLContextValue = configuration.sslContext();
    final SSLClientAuthentication actualSSLClientAuthenticationValue = configuration.sslClientAuthentication();
    // then
    assertThat(actualProtocolValue, is(sameInstance(someProtocolValue)));
    assertThat(actualHostValue, is(sameInstance(someHostValue)));
    assertThat(actualPortValue, is(somePortValue));
    assertThat(actualRootPathValue, is(sameInstance(someRootPathValue)));
    assertThat(actualSSLContextValue, is(sameInstance(someSSLContextValue)));
    assertThat(actualSSLClientAuthenticationValue, is(sameInstance(someSSLClientAuthenticationValue)));
}
Also used : SSLClientAuthentication(jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication) Configuration(jakarta.ws.rs.SeBootstrap.Configuration) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.jupiter.api.Test)

Aggregations

SSLClientAuthentication (jakarta.ws.rs.SeBootstrap.Configuration.SSLClientAuthentication)3 Configuration (jakarta.ws.rs.SeBootstrap.Configuration)2 SSLContext (javax.net.ssl.SSLContext)2 Test (org.junit.jupiter.api.Test)2 SeBootstrap (jakarta.ws.rs.SeBootstrap)1 Application (jakarta.ws.rs.core.Application)1 URI (java.net.URI)1