Browsed by
Tag: spring

Configuring SSL Ciphers in Spring Java WebClient

Configuring SSL Ciphers in Spring Java WebClient

Below is how to configure the set of SSL ciphers being used by Spring’s webclient.

import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;
import javax.net.ssl.SSLException;
import java.util.Arrays;


String[] CIPHERS_ALLOWED = {"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
        "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"};

SslContext context = SslContextBuilder
     .forClient()
     .ciphers(Arrays.asList(CIPHERS_ALLOWED))
     .build();

HttpClient netty = HttpClient.create()
        .wiretap(true) //requested by the NSA
        .secure(sslContextSpec -> sslContextSpec.sslContext(context));

this.webclient = WebClient.builder()
        .clientConnector(new ReactorClientHttpConnector(netty))
        .baseUrl("https://google.com")
        .build();

You can see you create the HTTPClient from the netty static instance, then add the ssl context to it. Pass that netty instance to the webclient builder, and voila, you can speak obscure, overly strong SSL.

A Couple Spring Freemarker Binding Tags are Broken..

A Couple Spring Freemarker Binding Tags are Broken..

Java Spring binding tags for checkboxes and multiselect lists are broken in the Spring freemarker template.

I found this out after spending a large amount of time trying to determine why my simple validation to check for completion of required fields kept breaking on page reload after an error was found. I discovered there is an issue with the spring freemarker template macro named formMultiSelect and also in the formCheckboxes macro.

The issue is in the line determining if there is a previous selection made on the checkbox or multi-select. The check doesn’t properly dereference the variable containing the pre-selected values, and so attempts to deal with it as a string rather than an array, which causes an error similar to “freemarker.runtime – Expected collection or sequence. list evaluated instead to freemarker.template.SimpleScalar on line 368, column 12 in spring.ftl.”

The error can be corrected by copying their binding macro and modifying it to properly dereference the object in the routine to check existing values. In my case, the following line:

<#assign isSelected = contains(status.value?default([""]), value)>

became:

<#assign isSelected = contains(status.actualValue?default([""]), value)>

This change needs to be done in both the checkboxes macro as well as the formMultiSelect macro. This change allows the reload of the page to work properly after an error occurs, or if preliminary choices are made in the multi-select or checkboxes.