Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.protocol.rest.ctl; |
| 18 | |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 20 | import org.apache.commons.io.IOUtils; |
| 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Service; |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 25 | import org.apache.http.client.methods.HttpPatch; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 26 | import org.apache.http.conn.ssl.AllowAllHostnameVerifier; |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 27 | import org.apache.http.entity.StringEntity; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 28 | import org.apache.http.impl.client.CloseableHttpClient; |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 29 | import org.apache.http.impl.client.HttpClients; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 30 | import org.apache.http.ssl.SSLContextBuilder; |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 31 | import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 32 | import org.onlab.packet.IpAddress; |
| 33 | import org.onosproject.net.DeviceId; |
| 34 | import org.onosproject.protocol.rest.RestSBController; |
| 35 | import org.onosproject.protocol.rest.RestSBDevice; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 36 | import org.slf4j.Logger; |
| 37 | import org.slf4j.LoggerFactory; |
| 38 | |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 39 | import javax.net.ssl.SSLContext; |
| 40 | import javax.net.ssl.TrustManager; |
| 41 | import javax.net.ssl.X509TrustManager; |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 42 | import javax.ws.rs.client.Client; |
| 43 | import javax.ws.rs.client.ClientBuilder; |
| 44 | import javax.ws.rs.client.Entity; |
| 45 | import javax.ws.rs.client.WebTarget; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 46 | import javax.ws.rs.core.MediaType; |
| 47 | import javax.ws.rs.core.Response; |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 48 | import java.io.ByteArrayInputStream; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 49 | import java.io.IOException; |
| 50 | import java.io.InputStream; |
| 51 | import java.nio.charset.StandardCharsets; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 52 | import java.security.KeyManagementException; |
| 53 | import java.security.KeyStoreException; |
| 54 | import java.security.NoSuchAlgorithmException; |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 55 | import java.security.cert.CertificateException; |
| 56 | import java.security.cert.X509Certificate; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 57 | import java.util.Base64; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 58 | import java.util.Map; |
| 59 | import java.util.concurrent.ConcurrentHashMap; |
| 60 | |
| 61 | /** |
| 62 | * The implementation of RestSBController. |
| 63 | */ |
| 64 | @Component(immediate = true) |
| 65 | @Service |
| 66 | public class RestSBControllerImpl implements RestSBController { |
| 67 | |
| 68 | private static final Logger log = |
| 69 | LoggerFactory.getLogger(RestSBControllerImpl.class); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 70 | private static final String XML = "xml"; |
| 71 | private static final String JSON = "json"; |
| 72 | private static final String DOUBLESLASH = "//"; |
| 73 | private static final String COLON = ":"; |
| 74 | private static final int STATUS_OK = Response.Status.OK.getStatusCode(); |
| 75 | private static final int STATUS_CREATED = Response.Status.CREATED.getStatusCode(); |
| 76 | private static final int STATUS_ACCEPTED = Response.Status.ACCEPTED.getStatusCode(); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 77 | private static final String HTTPS = "https"; |
| 78 | private static final String AUTHORIZATION_PROPERTY = "authorization"; |
| 79 | private static final String BASIC_AUTH_PREFIX = "Basic "; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 80 | |
| 81 | private final Map<DeviceId, RestSBDevice> deviceMap = new ConcurrentHashMap<>(); |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 82 | private final Map<DeviceId, Client> clientMap = new ConcurrentHashMap<>(); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 83 | |
| 84 | @Activate |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 85 | public void activate() { |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 86 | log.info("Started"); |
| 87 | } |
| 88 | |
| 89 | @Deactivate |
| 90 | public void deactivate() { |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 91 | clientMap.clear(); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 92 | deviceMap.clear(); |
| 93 | log.info("Stopped"); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public Map<DeviceId, RestSBDevice> getDevices() { |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 98 | return ImmutableMap.copyOf(deviceMap); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public RestSBDevice getDevice(DeviceId deviceInfo) { |
| 103 | return deviceMap.get(deviceInfo); |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public RestSBDevice getDevice(IpAddress ip, int port) { |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 108 | return deviceMap.values().stream().filter(v -> v.ip().equals(ip) |
| 109 | && v.port() == port).findFirst().get(); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public void addDevice(RestSBDevice device) { |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 114 | if (!deviceMap.containsKey(device.deviceId())) { |
| 115 | Client client = ignoreSslClient(); |
| 116 | if (device.username() != null) { |
| 117 | String username = device.username(); |
| 118 | String password = device.password() == null ? "" : device.password(); |
| 119 | authenticate(client, username, password); |
| 120 | } |
| 121 | clientMap.put(device.deviceId(), client); |
| 122 | deviceMap.put(device.deviceId(), device); |
| 123 | } else { |
| 124 | log.warn("Trying to add a device that is already existing {}", device.deviceId()); |
| 125 | } |
| 126 | |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 130 | public void removeDevice(DeviceId deviceId) { |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 131 | clientMap.remove(deviceId); |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 132 | deviceMap.remove(deviceId); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public boolean post(DeviceId device, String request, InputStream payload, String mediaType) { |
Andrea Campanella | c385126 | 2016-06-08 12:27:11 +0200 | [diff] [blame] | 137 | Response response = getResponse(device, request, payload, mediaType); |
| 138 | return checkReply(response); |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public <T> T post(DeviceId device, String request, InputStream payload, |
| 143 | String mediaType, Class<T> responseClass) { |
| 144 | Response response = getResponse(device, request, payload, mediaType); |
| 145 | if (response.hasEntity()) { |
| 146 | return response.readEntity(responseClass); |
| 147 | } |
| 148 | log.error("Response from device {} for request {} contains no entity", device, request); |
| 149 | return null; |
| 150 | } |
| 151 | |
| 152 | private Response getResponse(DeviceId device, String request, InputStream payload, String mediaType) { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 153 | WebTarget wt = getWebTarget(device, request); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 154 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 155 | Response response = null; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 156 | if (payload != null) { |
| 157 | try { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 158 | response = wt.request(mediaType) |
| 159 | .post(Entity.entity(IOUtils.toString(payload, StandardCharsets.UTF_8), mediaType)); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 160 | } catch (IOException e) { |
| 161 | log.error("Cannot do POST {} request on device {} because can't read payload", |
| 162 | request, device); |
| 163 | } |
| 164 | } else { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 165 | response = wt.request(mediaType).post(Entity.entity(null, mediaType)); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 166 | } |
Andrea Campanella | c385126 | 2016-06-08 12:27:11 +0200 | [diff] [blame] | 167 | return response; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public boolean put(DeviceId device, String request, InputStream payload, String mediaType) { |
Andrea Campanella | d8d92db | 2016-01-14 16:24:41 -0800 | [diff] [blame] | 172 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 173 | WebTarget wt = getWebTarget(device, request); |
| 174 | Response response = null; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 175 | if (payload != null) { |
| 176 | try { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 177 | response = wt.request(mediaType) |
| 178 | .put(Entity.entity(IOUtils.toString(payload, StandardCharsets.UTF_8), mediaType)); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 179 | } catch (IOException e) { |
| 180 | log.error("Cannot do PUT {} request on device {} because can't read payload", |
| 181 | request, device); |
| 182 | } |
| 183 | } else { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 184 | response = wt.request(mediaType).put(Entity.entity(null, mediaType)); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 185 | } |
| 186 | return checkReply(response); |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public InputStream get(DeviceId device, String request, String mediaType) { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 191 | WebTarget wt = getWebTarget(device, request); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 192 | String type; |
| 193 | switch (mediaType) { |
| 194 | case XML: |
| 195 | type = MediaType.APPLICATION_XML; |
| 196 | break; |
| 197 | case JSON: |
| 198 | type = MediaType.APPLICATION_JSON; |
| 199 | break; |
| 200 | default: |
| 201 | throw new IllegalArgumentException("Unsupported media type " + mediaType); |
| 202 | |
| 203 | } |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 204 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 205 | Response s = wt.request(type).get(); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 206 | if (checkReply(s)) { |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 207 | return new ByteArrayInputStream(wt.request(type) |
Andrea Campanella | c385126 | 2016-06-08 12:27:11 +0200 | [diff] [blame] | 208 | .get(String.class).getBytes(StandardCharsets.UTF_8)); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 209 | } |
| 210 | return null; |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | @Override |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 214 | public boolean patch(DeviceId device, String request, InputStream payload, String mediaType) { |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 215 | try { |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 216 | log.debug("Url request {} ", getUrlString(device, request)); |
| 217 | HttpPatch httprequest = new HttpPatch(getUrlString(device, request)); |
Andrea Campanella | 784ee0f | 2016-02-17 15:50:59 -0800 | [diff] [blame] | 218 | if (deviceMap.get(device).username() != null) { |
| 219 | String pwd = deviceMap.get(device).password() == null ? "" : COLON + deviceMap.get(device).password(); |
| 220 | String userPassword = deviceMap.get(device).username() + pwd; |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 221 | String base64string = Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8)); |
| 222 | httprequest.addHeader(AUTHORIZATION_PROPERTY, BASIC_AUTH_PREFIX + base64string); |
| 223 | } |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 224 | if (payload != null) { |
| 225 | StringEntity input = new StringEntity(IOUtils.toString(payload, StandardCharsets.UTF_8)); |
| 226 | input.setContentType(mediaType); |
| 227 | httprequest.setEntity(input); |
| 228 | } |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 229 | CloseableHttpClient httpClient; |
| 230 | if (deviceMap.containsKey(device) && deviceMap.get(device).protocol().equals(HTTPS)) { |
| 231 | httpClient = getApacheSslBypassClient(); |
| 232 | } else { |
| 233 | httpClient = HttpClients.createDefault(); |
| 234 | } |
| 235 | int responseStatusCode = httpClient |
| 236 | .execute(httprequest) |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 237 | .getStatusLine() |
| 238 | .getStatusCode(); |
| 239 | return checkStatusCode(responseStatusCode); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 240 | } catch (IOException | NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) { |
| 241 | log.error("Cannot do PATCH {} request on device {}", |
| 242 | request, device, e); |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | @Override |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 248 | public boolean delete(DeviceId device, String request, InputStream payload, String mediaType) { |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 249 | WebTarget wt = getWebTarget(device, request); |
| 250 | |
| 251 | // FIXME: do we need to delete an entry by enclosing data in DELETE request? |
| 252 | // wouldn't it be nice to use PUT to implement the similar concept? |
| 253 | Response response = wt.request(mediaType).delete(); |
| 254 | |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 255 | return checkReply(response); |
| 256 | } |
| 257 | |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 258 | private void authenticate(Client client, String username, String password) { |
| 259 | client.register(HttpAuthenticationFeature.basic(username, password)); |
| 260 | } |
| 261 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 262 | private WebTarget getWebTarget(DeviceId device, String request) { |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 263 | log.debug("Sending request to URL {} ", getUrlString(device, request)); |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 264 | return clientMap.get(device).target(getUrlString(device, request)); |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | //FIXME security issue: this trusts every SSL certificate, even if is self-signed. Also deprecated methods. |
| 268 | private CloseableHttpClient getApacheSslBypassClient() throws NoSuchAlgorithmException, |
| 269 | KeyManagementException, KeyStoreException { |
| 270 | return HttpClients.custom(). |
| 271 | setHostnameVerifier(new AllowAllHostnameVerifier()). |
| 272 | setSslcontext(new SSLContextBuilder() |
| 273 | .loadTrustMaterial(null, (arg0, arg1) -> true) |
| 274 | .build()).build(); |
| 275 | } |
| 276 | |
| 277 | private String getUrlString(DeviceId device, String request) { |
| 278 | if (deviceMap.get(device).url() != null) { |
| 279 | return deviceMap.get(device).protocol() + COLON + DOUBLESLASH |
| 280 | + deviceMap.get(device).url() + request; |
| 281 | } else { |
| 282 | return deviceMap.get(device).protocol() + COLON + |
| 283 | DOUBLESLASH + |
| 284 | deviceMap.get(device).ip().toString() + |
| 285 | COLON + deviceMap.get(device).port() + request; |
| 286 | } |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 287 | } |
| 288 | |
Jian Li | 9d61649 | 2016-03-09 10:52:49 -0800 | [diff] [blame] | 289 | private boolean checkReply(Response response) { |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 290 | if (response != null) { |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 291 | return checkStatusCode(response.getStatus()); |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 292 | } |
| 293 | log.error("Null reply from device"); |
| 294 | return false; |
| 295 | } |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 296 | |
| 297 | private boolean checkStatusCode(int statusCode) { |
| 298 | if (statusCode == STATUS_OK || |
| 299 | statusCode == STATUS_CREATED || |
| 300 | statusCode == STATUS_ACCEPTED) { |
| 301 | return true; |
| 302 | } else { |
Andrea Campanella | 2947e62 | 2016-01-27 09:23:46 -0800 | [diff] [blame] | 303 | log.error("Failed request, HTTP error code : " |
Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame] | 304 | + statusCode); |
| 305 | return false; |
| 306 | } |
| 307 | } |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 308 | |
| 309 | private Client ignoreSslClient() { |
| 310 | SSLContext sslcontext = null; |
| 311 | |
| 312 | try { |
| 313 | sslcontext = SSLContext.getInstance("TLS"); |
| 314 | sslcontext.init(null, new TrustManager[]{new X509TrustManager() { |
| 315 | public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { |
| 316 | } |
| 317 | |
| 318 | public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { |
| 319 | } |
| 320 | |
| 321 | public X509Certificate[] getAcceptedIssuers() { |
| 322 | return new X509Certificate[0]; |
| 323 | } |
Andrea Campanella | c6ecc63 | 2016-03-10 17:57:06 -0800 | [diff] [blame] | 324 | } }, new java.security.SecureRandom()); |
| 325 | } catch (NoSuchAlgorithmException | KeyManagementException e) { |
| 326 | e.printStackTrace(); |
| 327 | } |
| 328 | |
| 329 | return ClientBuilder.newBuilder().sslContext(sslcontext).hostnameVerifier((s1, s2) -> true).build(); |
| 330 | } |
Andrea Campanella | 945ded2 | 2016-01-07 13:17:43 -0800 | [diff] [blame] | 331 | } |