|
54 | 54 | import com.axway.apim.lib.errorHandling.ErrorState; |
55 | 55 | import com.axway.apim.lib.utils.TestIndicator; |
56 | 56 | import com.axway.apim.lib.utils.rest.APIMHttpClient; |
| 57 | +import com.axway.apim.lib.utils.rest.DELRequest; |
57 | 58 | import com.axway.apim.lib.utils.rest.GETRequest; |
58 | 59 | import com.axway.apim.lib.utils.rest.POSTRequest; |
59 | 60 | import com.axway.apim.lib.utils.rest.RestAPICall; |
@@ -143,7 +144,11 @@ public static synchronized void deleteInstance() throws AppException { |
143 | 144 | APIManagerAdapter.cacheManager.close(); |
144 | 145 | LOG.debug("Closing cache end"); |
145 | 146 | } |
146 | | - APIManagerAdapter.instance = null; |
| 147 | + if(APIManagerAdapter.instance!=null) { |
| 148 | + APIManagerAdapter.instance.logoutFromAPIManager(false); // Logout potentially logged in OrgAdmin |
| 149 | + APIManagerAdapter.instance.logoutFromAPIManager(true); // Logout potentially logged in Admin |
| 150 | + APIManagerAdapter.instance = null; |
| 151 | + } |
147 | 152 | } |
148 | 153 |
|
149 | 154 | private APIManagerAdapter() throws AppException { |
@@ -232,6 +237,29 @@ public void loginToAPIManager(boolean useAdminClient) throws AppException { |
232 | 237 | } |
233 | 238 | } |
234 | 239 |
|
| 240 | + public void logoutFromAPIManager(boolean useAdminClient) throws AppException { |
| 241 | + if(useAdminClient && !hasAdminAccount()) return; |
| 242 | + URI uri; |
| 243 | + HttpResponse httpResponse = null; |
| 244 | + try { |
| 245 | + uri = new URIBuilder(cmd.getAPIManagerURL()).setPath(RestAPICall.API_VERSION+"/login").build(); |
| 246 | + DELRequest logoutRequest = new DELRequest(uri, useAdminClient); |
| 247 | + httpResponse = logoutRequest.execute(); |
| 248 | + int statusCode = httpResponse.getStatusLine().getStatusCode(); |
| 249 | + if(statusCode != 204){ |
| 250 | + String response = EntityUtils.toString(httpResponse.getEntity()); |
| 251 | + LOG.warn("Logout failed with statusCode: " +statusCode+ ". Got response: '"+response+"'"); |
| 252 | + } |
| 253 | + } catch (Exception e) { |
| 254 | + throw new AppException("Can't logout from API-Manager", ErrorCode.API_MANAGER_COMMUNICATION, e); |
| 255 | + } finally { |
| 256 | + try { |
| 257 | + if(httpResponse!=null) |
| 258 | + ((CloseableHttpResponse)httpResponse).close(); |
| 259 | + } catch (Exception ignore) {} |
| 260 | + } |
| 261 | + } |
| 262 | + |
235 | 263 | private String[] getAdminUsernamePassword() throws AppException { |
236 | 264 | if(CommandParameters.getInstance().getAdminUsername()==null) return null; |
237 | 265 | String[] usernamePassword = {CommandParameters.getInstance().getAdminUsername(), CommandParameters.getInstance().getAdminPassword()}; |
|
0 commit comments