Java Code Examples for com.sun.jersey.api.client.ClientResponse#getCookies()
The following examples show how to use
com.sun.jersey.api.client.ClientResponse#getCookies() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Response.java From qaf with MIT License | 7 votes |
protected void init(ClientResponse clientResponse) { this.clientResponse = clientResponse; // messageBody = clientResponse.getEntity(type); setRawMessageBody(); headers = clientResponse.getHeaders(); status = clientResponse.getClientResponseStatus(); cookies = clientResponse.getCookies(); lastModified = clientResponse.getLastModified(); responseDate = clientResponse.getResponseDate(); language = clientResponse.getLanguage(); try { mediaType = clientResponse.getType(); } catch (Exception e) { System.err.println("Unable to parse media type. If want to access media type, you may try using 'Content-Type' from header."); e.printStackTrace(); } }
Example 2
Source File: GrafanaUserDetailsUtil.java From Insights with Apache License 2.0 | 6 votes |
/** * used to create new session with grafana (login with grafana) * * @param userName * @param password * @return * @throws InsightsCustomException */ private static List<NewCookie> getValidGrafanaSession(String userName, String password) throws InsightsCustomException { log.debug("Inside getValidGrafanaSession method call"); JsonObject loginRequestParams = new JsonObject(); loginRequestParams.addProperty("user", userName); loginRequestParams.addProperty("password", password); String loginApiUrl = ApplicationConfigProvider.getInstance().getGrafana().getGrafanaEndpoint() + "/login"; ClientResponse grafanaLoginResponse = RestHandler.doPost(loginApiUrl, loginRequestParams, null); log.debug("GrafanaUserDetailsUtil ==== status code {} loginApiUrl {} Grafana responce {} ", grafanaLoginResponse.getStatus(), loginApiUrl, grafanaLoginResponse.getEntity(String.class)); if (grafanaLoginResponse.getStatus() != 200) { String response = grafanaLoginResponse.getEntity(String.class); log.error("GrafanaUserDetailsUtil ==== unable to getValidGrafanaSession ==== {} response {}", grafanaLoginResponse.getStatus(), response); throw new InsightsCustomException(" user or password is incorrect ==== "); } return grafanaLoginResponse.getCookies(); }
Example 3
Source File: PlatformServiceUtil.java From Insights with Apache License 2.0 | 6 votes |
public static Map<String, String> getGrafanaCookies(HttpServletRequest httpRequest) throws UnsupportedEncodingException { Map<String, String> requestCookies = new HashMap<String, String>(0); String authHeader = ValidationUtils .decryptAutharizationToken(httpRequest.getHeader(AuthenticationUtils.AUTH_HEADER_KEY)); String decodedAuthHeader = new String(Base64.getDecoder().decode(authHeader.split(" ")[1]), "UTF-8"); String[] authTokens = decodedAuthHeader.split(":"); JsonObject loginRequestParams = new JsonObject(); loginRequestParams.addProperty("user", authTokens[0]); loginRequestParams.addProperty("password", authTokens[1]); String loginApiUrl = PlatformServiceUtil.getGrafanaURL("/login"); ClientResponse grafanaLoginResponse = RestHandler.doPost(loginApiUrl, loginRequestParams, null); log.debug("GrafanaUserDetailsUtil ==== status code {} loginApiUrl {} Grafana responce {} ", grafanaLoginResponse.getStatus(), loginApiUrl, grafanaLoginResponse.getEntity(String.class)); List<NewCookie> cookies2 = grafanaLoginResponse.getCookies(); for (NewCookie cookie : cookies2) { requestCookies.put(cookie.getName(), ValidationUtils.cleanXSS(cookie.getValue()).concat("; HttpOnly")); } return requestCookies; }
Example 4
Source File: TagAdminRESTSink.java From ranger with Apache License 2.0 | 5 votes |
private synchronized ClientResponse uploadTagsWithCred(ServiceTags serviceTags) { if (sessionId == null) { tagRESTClient.resetClient(); ClientResponse response = null; try { response = tagRESTClient.put(REST_URL_IMPORT_SERVICETAGS_RESOURCE, null, serviceTags); } catch (Exception e) { LOG.error("Failed to get response, Error is : "+e.getMessage()); } if (response != null) { if (!(response.toString().contains(REST_URL_IMPORT_SERVICETAGS_RESOURCE))) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (response.getStatus() == HttpServletResponse.SC_OK || response.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = response.getCookies(); // save cookie received from credentials session login for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerAdminCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; break; } else { isValidRangerCookie = false; } } } } return response; } else { ClientResponse clientResponsebySessionId = uploadTagsWithCookie(serviceTags); if (!(clientResponsebySessionId.toString().contains(REST_URL_IMPORT_SERVICETAGS_RESOURCE))) { clientResponsebySessionId.setStatus(HttpServletResponse.SC_NOT_FOUND); } return clientResponsebySessionId; } }
Example 5
Source File: TagAdminRESTSink.java From ranger with Apache License 2.0 | 5 votes |
private ClientResponse uploadTagsWithCookie(ServiceTags serviceTags) { if (LOG.isDebugEnabled()) { LOG.debug("==> uploadTagsWithCookie"); } ClientResponse response = null; try { response = tagRESTClient.put(REST_URL_IMPORT_SERVICETAGS_RESOURCE, serviceTags, sessionId); } catch (Exception e) { LOG.error("Failed to get response, Error is : "+e.getMessage()); } if (response != null) { if (!(response.toString().contains(REST_URL_IMPORT_SERVICETAGS_RESOURCE))) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_NO_CONTENT || response.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = response.getCookies(); for (NewCookie respCookie : respCookieList) { if (respCookie.getName().equalsIgnoreCase(rangerAdminCookieName)) { if (!(sessionId.getValue().equalsIgnoreCase(respCookie.toCookie().getValue()))) { sessionId = respCookie.toCookie(); } isValidRangerCookie = true; break; } } } } if (LOG.isDebugEnabled()) { LOG.debug("<== uploadTagsWithCookie"); } return response; }
Example 6
Source File: AuthenticationWsDelegate.java From roboconf-platform with Apache License 2.0 | 5 votes |
/** * Logs in with a user name and a password. * @param username a user name * @param password a password * @return a session ID, or null if login failed * @throws DebugWsException */ public String login( String username, String password ) throws DebugWsException { this.logger.finer( "Logging in as " + username ); WebResource path = this.resource.path( UrlConstants.AUTHENTICATION ).path( "e" ); ClientResponse response = path .header( "u", username ) .header( "p", password ) .post( ClientResponse.class ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new DebugWsException( response.getStatusInfo().getStatusCode(), value ); } // Get the session ID from the cookie that should have been returned String sessionId = null; List<NewCookie> cookies = response.getCookies(); if( cookies != null ) { for( NewCookie cookie : cookies ) { if( UrlConstants.SESSION_ID.equals( cookie.getName())) { sessionId = cookie.getValue(); break; } } } // Set the session ID this.wsClient.setSessionId( sessionId ); this.logger.finer( "Session ID: " + sessionId ); return sessionId; }
Example 7
Source File: CookiesHandlerFilter.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
@Override public ClientResponse handle( ClientRequest request ) throws ClientHandlerException { List<Object> authorizationHeader = request.getHeaders().get( "Authorization" ); String authToken = (String) authorizationHeader.get( 0 ); // If we have cookies, inject them. When session is expired, basic auth // header is not used instead of the expired cookies, so we just use // them as a token. List<Object> cookiesList = getCachedCookiesByAuthToken( authToken ); if ( cookiesList != null ) { request.getHeaders().put( "Cookie", cookiesList ); request.getHeaders().remove( "Authorization" ); } ClientResponse response = getNext().handle( request ); // If session has expired, remove cookies, put back basic auth header, // try one more time and save new cookies. if ( response.getStatus() == HttpStatus.SC_UNAUTHORIZED ) { logger.warn( "Request to" + request.getURI() + "returned Unauthorized." ); if ( logger.isDebugEnabled() ) { logger.debug( "http status=" + response.getStatus() + " response=" + response.getEntity( String.class ) ); } request.getHeaders().remove( "Cookie" ); request.getHeaders().put( "Authorization", authorizationHeader ); logger.warn( "Trying one more time" ); response = getNext().handle( request ); if ( response.getStatus() == HttpStatus.SC_UNAUTHORIZED ) { logger.error( "Request to" + request.getURI() + "returned Unauthorized 2nd time." ); logger.error( "http status=" + response.getStatus() + " response=" + response.getEntity( String.class ) ); } } // always use the new cookies. if ( response.getCookies() != null && response.getCookies().isEmpty() == false ) { cookiesList = new ArrayList<Object>(); cookiesList.addAll( response.getCookies() ); setCookiesByAuthToken( authToken, cookiesList ); } return response; }
Example 8
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private void delXGroupUserInfo(String groupName, String userName) { if (LOG.isDebugEnabled()) { LOG.debug("==> LdapPolicyMgrUserGroupBuilder.delXUserGroupInfo()"); } try { ClientResponse response = null; String relativeUrl = PM_DEL_USER_GROUP_LINK_URI.replaceAll(Pattern.quote("${groupName}"), URLEncoderUtil.encodeURIParam(groupName)).replaceAll(Pattern.quote("${userName}"), URLEncoderUtil.encodeURIParam(userName)); if (isRangerCookieEnabled) { if (sessionId != null && isValidRangerCookie) { response = ldapUgSyncClient.delete(relativeUrl, null, sessionId); if (response != null) { if (!(response.toString().contains(relativeUrl))) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("response from ranger is 401 unauthorized"); sessionId = null; isValidRangerCookie = false; } else if (response.getStatus() == HttpServletResponse.SC_NO_CONTENT || response.getStatus() == HttpServletResponse.SC_OK) { cookieList = response.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; break; } } } if (response.getStatus() != HttpServletResponse.SC_OK && response.getStatus() != HttpServletResponse.SC_NO_CONTENT && response.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } } } } else { response = ldapUgSyncClient.delete(relativeUrl, null); } if ( LOG.isDebugEnabled() ) { LOG.debug("RESPONSE: [" + response.toString() + "]"); } } catch (Exception e) { LOG.warn( "ERROR: Unable to delete GROUP: " + groupName + " from USER:" + userName , e); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.delXUserGroupInfo()"); } }
Example 9
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCookie(Object obj, String apiURL) { if (LOG.isDebugEnabled()) { LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; try { clientResp = ldapUgSyncClient.post(apiURL, null, obj, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } return response; }
Example 10
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCred(Object obj, String apiURL){ if(LOG.isDebugEnabled()){ LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } String response = null; ClientResponse clientResp = null; Gson gson = new GsonBuilder().create(); String jsonString = gson.toJson(obj); if ( LOG.isDebugEnabled() ) { LOG.debug("USER GROUP MAPPING" + jsonString); } try{ clientResp = ldapUgSyncClient.post(apiURL, null, obj); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } return response; }
Example 11
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCred(String apiURL, int retrievedCount) { if(LOG.isDebugEnabled()){ LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try{ clientResp = ldapUgSyncClient.get(apiURL, queryParams); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } return response; }
Example 12
Source File: LdapPolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCookie(String apiURL, int retrievedCount) { if (LOG.isDebugEnabled()) { LOG.debug("==> LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try { clientResp = ldapUgSyncClient.get(apiURL, queryParams, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(rangerCookieName)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== LdapPolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } return response; }
Example 13
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCookie(Object obj, String apiURL) { if (LOG.isDebugEnabled()) { LOG.debug("==> PolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; try{ clientResp = uGSyncClient.post(apiURL, null, obj, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryUploadEntityWithCookie()"); } return response; }
Example 14
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryUploadEntityWithCred(Object obj,String apiURL){ if(LOG.isDebugEnabled()){ LOG.debug("==> PolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } String response = null; ClientResponse clientResp = null; Gson gson = new GsonBuilder().create(); String jsonString = gson.toJson(obj); if ( LOG.isDebugEnabled() ) { LOG.debug("USER GROUP MAPPING" + jsonString); } try{ clientResp = uGSyncClient.post(apiURL, null, obj); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryUploadEntityInfoWithCred()"); } return response; }
Example 15
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCred(String apiURL, int retrievedCount) { if(LOG.isDebugEnabled()){ LOG.debug("==> PolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try{ clientResp = uGSyncClient.get(apiURL, queryParams); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { LOG.warn("Credentials response from ranger is 401."); } else if (clientResp.getStatus() == HttpServletResponse.SC_OK || clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT) { cookieList = clientResp.getCookies(); for (NewCookie cookie : cookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { sessionId = cookie.toCookie(); isValidRangerCookie = true; LOG.info("valid cookie saved "); break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryGetEntityWithCred()"); } return response; }
Example 16
Source File: PolicyMgrUserGroupBuilder.java From ranger with Apache License 2.0 | 4 votes |
private String tryGetEntityWithCookie(String apiURL, int retrievedCount) { if (LOG.isDebugEnabled()) { LOG.debug("==> PolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } String response = null; ClientResponse clientResp = null; Map<String, String> queryParams = new HashMap<String, String>(); queryParams.put("pageSize", recordsToPullPerCall); queryParams.put("startIndex", String.valueOf(retrievedCount)); try{ clientResp = uGSyncClient.get(apiURL, queryParams, sessionId); } catch(Throwable t){ LOG.error("Failed to get response, Error is : ", t); } if (clientResp != null) { if (!(clientResp.toString().contains(apiURL))) { clientResp.setStatus(HttpServletResponse.SC_NOT_FOUND); sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) { sessionId = null; isValidRangerCookie = false; } else if (clientResp.getStatus() == HttpServletResponse.SC_NO_CONTENT || clientResp.getStatus() == HttpServletResponse.SC_OK) { List<NewCookie> respCookieList = clientResp.getCookies(); for (NewCookie cookie : respCookieList) { if (cookie.getName().equalsIgnoreCase(RANGER_ADMIN_COOKIE_NAME)) { if (!(sessionId.getValue().equalsIgnoreCase(cookie.toCookie().getValue()))) { sessionId = cookie.toCookie(); } isValidRangerCookie = true; break; } } } if (clientResp.getStatus() != HttpServletResponse.SC_OK && clientResp.getStatus() != HttpServletResponse.SC_NO_CONTENT && clientResp.getStatus() != HttpServletResponse.SC_BAD_REQUEST) { sessionId = null; isValidRangerCookie = false; } clientResp.bufferEntity(); response = clientResp.getEntity(String.class); } if (LOG.isDebugEnabled()) { LOG.debug("<== PolicyMgrUserGroupBuilder.tryGetEntityWithCookie()"); } return response; }