How can I connect to bearer-only client with SSL?

Hi there,
I’m developing 2 services(keycloak clients). One for UI(credential) and another for REST API(bearer-only). I have tested without SSL and they’ve worked fine till now. But if I wanted to apply SSL on my REST API(using self-signed cert), what should I do? ‘KeycloakRestTemplate’ makes exception with message like this:

java.lang.IllegalStateException: Cannot set authorization header because Authentication is of type class but class org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken is required

Then I tried some code snippet that I used for non-OAuth2 REST API, but same result

SSLContext context;
try {
    TrustStrategy acceptingTrustStrategy = new TrustSelfSignedStrategy();
    context = SSLContexts.custom()
        .loadTrustMaterial(null, acceptingTrustStrategy)
        new TrustManager[] { new X509TrustManager() {
            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
            public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
} catch(Exception e) {
    return	null;
SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(context, NoopHostnameVerifier.INSTANCE);
KeycloakClientRequestFactory factory = new KeycloakClientRequestFactory();
CloseableHttpClient httpClient = HttpClientBuilder.create()
KeycloakRestTemplate restTemplate = new KeycloakRestTemplate(factory);
ResponseEntity<String[]> response = restTemplate.getForEntity(serviceUrl, String[].class);