1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.rest;
20
21 import com.fasterxml.jackson.databind.json.JsonMapper;
22 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
23 import java.util.List;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import org.apache.cxf.jaxrs.client.WebClient;
27 import org.apache.syncope.client.console.SyncopeWebApplication;
28 import org.apache.syncope.client.ui.commons.rest.RestClient;
29 import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
30 import org.apache.syncope.common.lib.AMSession;
31 import org.apache.syncope.common.lib.SyncopeClientException;
32 import org.apache.syncope.common.lib.types.ClientExceptionType;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public abstract class AMSessionRestClient implements RestClient {
37
38 private static final long serialVersionUID = 17371816842780L;
39
40 protected static final Logger LOG = LoggerFactory.getLogger(AMSessionRestClient.class);
41
42 protected static final List<?> JAX_RS_PROVIDERS =
43 List.of(new JacksonJsonProvider(JsonMapper.builder().findAndAddModules().build()));
44
45 protected final List<NetworkService> instances;
46
47 protected AMSessionRestClient(final List<NetworkService> instances) {
48 this.instances = instances;
49 }
50
51 protected abstract String getActuatorEndpoint();
52
53 public abstract List<AMSession> list();
54
55 public void delete(final String key) {
56 SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown);
57
58 try {
59 Response response = WebClient.create(
60 getActuatorEndpoint(),
61 SyncopeWebApplication.get().getAnonymousUser(),
62 SyncopeWebApplication.get().getAnonymousKey(),
63 null).
64 path(key).
65 accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE).delete();
66 if (response.getStatus() != Response.Status.OK.getStatusCode()
67 && response.getStatus() != Response.Status.NO_CONTENT.getStatusCode()) {
68
69 LOG.error("Unexpected response when deleting SSO Session {} from {}: {}",
70 key, getActuatorEndpoint(), response.getStatus());
71 sce.getElements().add("Unexpected response code: " + response.getStatus());
72 }
73 } catch (Exception e) {
74 LOG.error("Could not delete SSO Session {} from {}",
75 key, getActuatorEndpoint(), e);
76 sce.getElements().add("Unexpected error: " + e.getMessage());
77 }
78
79 if (!sce.getElements().isEmpty()) {
80 throw sce;
81 }
82 }
83 }