@Test public void testGetBotUserAccountKeyInvalidKmSession() { String failMsg = "Should have thrown UnexpectedAuthException containing a RemoteApiException (400)."; try { relayApiClient.getUserAccountKeyManagerData(MOCK_SESSION_TOKEN, null); fail(failMsg); } catch (UnexpectedAuthException e) { assertTrue(e.getCause() instanceof RemoteApiException); RemoteApiException rae = (RemoteApiException) e.getCause(); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rae.getCode()); } catch (Exception e) { fail(failMsg); } }
public UserKeyManagerData getUserAccountKeyManagerData(String sessionToken, String kmSession) { try { checkAuthToken(sessionToken); checkKMAuthToken(kmSession); String path = "/relay/keys/me"; StringBuffer cookie = new StringBuffer(SESSION_KEY_HEADER_PARAM); cookie.append("=").append(sessionToken).append("; "); cookie.append(KM_SESSION_TOKEN_HEADER_PARAM).append("=").append(kmSession); Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); headerParams.put(COOKIE_HEADER_PARAM, cookie.toString()); Map<String, String> queryParams = new HashMap<>(); return apiClient.doGet(path, headerParams, queryParams, UserKeyManagerData.class); } catch (RemoteApiException e) { if (e.getCode() == Response.Status.UNAUTHORIZED.getStatusCode()) { String message = logMessage.getMessage(UNAUTHORIZED_MESSAGE); String solution = logMessage.getMessage(UNAUTHORIZED_MESSAGE_SOLUTION); throw new UnauthorizedUserException(message, solution); } if (e.getCode() == Response.Status.FORBIDDEN.getStatusCode()) { String message = logMessage.getMessage(FORBIDDEN_MESSAGE); String solution = logMessage.getMessage(FORBIDDEN_MESSAGE_SOLUTION); throw new ForbiddenAuthException(message, solution); } throw new UnexpectedAuthException(logMessage.getMessage(API_MSG), e, logMessage.getMessage(API_MSG_SOLUTION)); } }
RelayApiClient extends BasePodApiClient { public UserKeyManagerData getUserAccountKeyManagerData(String sessionToken, String kmSession) { try { checkAuthToken(sessionToken); checkKMAuthToken(kmSession); String path = "/relay/keys/me"; StringBuffer cookie = new StringBuffer(SESSION_KEY_HEADER_PARAM); cookie.append("=").append(sessionToken).append("; "); cookie.append(KM_SESSION_TOKEN_HEADER_PARAM).append("=").append(kmSession); Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); headerParams.put(COOKIE_HEADER_PARAM, cookie.toString()); Map<String, String> queryParams = new HashMap<>(); return apiClient.doGet(path, headerParams, queryParams, UserKeyManagerData.class); } catch (RemoteApiException e) { if (e.getCode() == Response.Status.UNAUTHORIZED.getStatusCode()) { String message = logMessage.getMessage(UNAUTHORIZED_MESSAGE); String solution = logMessage.getMessage(UNAUTHORIZED_MESSAGE_SOLUTION); throw new UnauthorizedUserException(message, solution); } if (e.getCode() == Response.Status.FORBIDDEN.getStatusCode()) { String message = logMessage.getMessage(FORBIDDEN_MESSAGE); String solution = logMessage.getMessage(FORBIDDEN_MESSAGE_SOLUTION); throw new ForbiddenAuthException(message, solution); } throw new UnexpectedAuthException(logMessage.getMessage(API_MSG), e, logMessage.getMessage(API_MSG_SOLUTION)); } } }
RelayApiClient extends BasePodApiClient { public UserKeyManagerData getUserAccountKeyManagerData(String sessionToken, String kmSession) { try { checkAuthToken(sessionToken); checkKMAuthToken(kmSession); String path = "/relay/keys/me"; StringBuffer cookie = new StringBuffer(SESSION_KEY_HEADER_PARAM); cookie.append("=").append(sessionToken).append("; "); cookie.append(KM_SESSION_TOKEN_HEADER_PARAM).append("=").append(kmSession); Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); headerParams.put(COOKIE_HEADER_PARAM, cookie.toString()); Map<String, String> queryParams = new HashMap<>(); return apiClient.doGet(path, headerParams, queryParams, UserKeyManagerData.class); } catch (RemoteApiException e) { if (e.getCode() == Response.Status.UNAUTHORIZED.getStatusCode()) { String message = logMessage.getMessage(UNAUTHORIZED_MESSAGE); String solution = logMessage.getMessage(UNAUTHORIZED_MESSAGE_SOLUTION); throw new UnauthorizedUserException(message, solution); } if (e.getCode() == Response.Status.FORBIDDEN.getStatusCode()) { String message = logMessage.getMessage(FORBIDDEN_MESSAGE); String solution = logMessage.getMessage(FORBIDDEN_MESSAGE_SOLUTION); throw new ForbiddenAuthException(message, solution); } throw new UnexpectedAuthException(logMessage.getMessage(API_MSG), e, logMessage.getMessage(API_MSG_SOLUTION)); } } RelayApiClient(HttpApiClient apiClient, LogMessageSource logMessage); }
RelayApiClient extends BasePodApiClient { public UserKeyManagerData getUserAccountKeyManagerData(String sessionToken, String kmSession) { try { checkAuthToken(sessionToken); checkKMAuthToken(kmSession); String path = "/relay/keys/me"; StringBuffer cookie = new StringBuffer(SESSION_KEY_HEADER_PARAM); cookie.append("=").append(sessionToken).append("; "); cookie.append(KM_SESSION_TOKEN_HEADER_PARAM).append("=").append(kmSession); Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); headerParams.put(COOKIE_HEADER_PARAM, cookie.toString()); Map<String, String> queryParams = new HashMap<>(); return apiClient.doGet(path, headerParams, queryParams, UserKeyManagerData.class); } catch (RemoteApiException e) { if (e.getCode() == Response.Status.UNAUTHORIZED.getStatusCode()) { String message = logMessage.getMessage(UNAUTHORIZED_MESSAGE); String solution = logMessage.getMessage(UNAUTHORIZED_MESSAGE_SOLUTION); throw new UnauthorizedUserException(message, solution); } if (e.getCode() == Response.Status.FORBIDDEN.getStatusCode()) { String message = logMessage.getMessage(FORBIDDEN_MESSAGE); String solution = logMessage.getMessage(FORBIDDEN_MESSAGE_SOLUTION); throw new ForbiddenAuthException(message, solution); } throw new UnexpectedAuthException(logMessage.getMessage(API_MSG), e, logMessage.getMessage(API_MSG_SOLUTION)); } } RelayApiClient(HttpApiClient apiClient, LogMessageSource logMessage); UserKeyManagerData getUserAccountKeyManagerData(String sessionToken, String kmSession); }
RelayApiClient extends BasePodApiClient { public UserKeyManagerData getUserAccountKeyManagerData(String sessionToken, String kmSession) { try { checkAuthToken(sessionToken); checkKMAuthToken(kmSession); String path = "/relay/keys/me"; StringBuffer cookie = new StringBuffer(SESSION_KEY_HEADER_PARAM); cookie.append("=").append(sessionToken).append("; "); cookie.append(KM_SESSION_TOKEN_HEADER_PARAM).append("=").append(kmSession); Map<String, String> headerParams = new HashMap<>(); headerParams.put(SESSION_TOKEN_HEADER_PARAM, sessionToken); headerParams.put(COOKIE_HEADER_PARAM, cookie.toString()); Map<String, String> queryParams = new HashMap<>(); return apiClient.doGet(path, headerParams, queryParams, UserKeyManagerData.class); } catch (RemoteApiException e) { if (e.getCode() == Response.Status.UNAUTHORIZED.getStatusCode()) { String message = logMessage.getMessage(UNAUTHORIZED_MESSAGE); String solution = logMessage.getMessage(UNAUTHORIZED_MESSAGE_SOLUTION); throw new UnauthorizedUserException(message, solution); } if (e.getCode() == Response.Status.FORBIDDEN.getStatusCode()) { String message = logMessage.getMessage(FORBIDDEN_MESSAGE); String solution = logMessage.getMessage(FORBIDDEN_MESSAGE_SOLUTION); throw new ForbiddenAuthException(message, solution); } throw new UnexpectedAuthException(logMessage.getMessage(API_MSG), e, logMessage.getMessage(API_MSG_SOLUTION)); } } RelayApiClient(HttpApiClient apiClient, LogMessageSource logMessage); UserKeyManagerData getUserAccountKeyManagerData(String sessionToken, String kmSession);  }