use of org.apache.http.message.BasicHeader in project uPortal by Jasig.
the class PreferencesHeaderProvider method createHeader.
@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
// Username
final String username = getUsername(renderRequest);
// PreferencesMap
final Map<String, List<String>> preferencesMap = new HashMap<>();
final PortletPreferences prefs = renderRequest.getPreferences();
for (Map.Entry<String, String[]> y : prefs.getMap().entrySet()) {
final String name = y.getKey();
/*
* We ignore (skip) preferences that exist for the benefit of the
* SoffitConnectorController.
*/
if (name.startsWith(SoffitConnectorController.CONNECTOR_PREFERENCE_PREFIX)) {
continue;
}
List<String> values = Arrays.asList(prefs.getValues(name, new String[0]));
if (!values.isEmpty()) {
preferencesMap.put(name, values);
}
}
// Preferences header
final Preferences preferences = preferencesService.createPreferences(preferencesMap, username, getExpiration(renderRequest));
final Header rslt = new BasicHeader(Headers.PREFERECES.getName(), preferences.getEncryptedToken());
logger.debug("Produced the following Preferences header for username='{}': {}", username, rslt);
return rslt;
}
use of org.apache.http.message.BasicHeader in project uPortal by Jasig.
the class PortalRequestHeaderProvider method createHeader.
@Override
public Header createHeader(RenderRequest renderRequest, RenderResponse renderResponse) {
// Username
final String username = getUsername(renderRequest);
// Properties
final Map<String, String> properties = new HashMap<>();
final Enumeration<String> names = renderRequest.getPropertyNames();
for (String propertyName = names.nextElement(); names.hasMoreElements(); propertyName = names.nextElement()) {
properties.put(propertyName, renderRequest.getProperty(propertyName));
}
// Attributes
final Map<String, List<String>> attributes = new HashMap<>();
attributes.put(Attributes.NAMESPACE.getName(), Collections.singletonList(NAMESPACE_PREFIX + renderRequest.getWindowID()));
attributes.put(Attributes.MODE.getName(), Collections.singletonList(renderRequest.getPortletMode().toString()));
attributes.put(Attributes.WINDOW_STATE.getName(), Collections.singletonList(renderRequest.getWindowState().toString()));
attributes.put(Attributes.PORTAL_INFO.getName(), Collections.singletonList(renderRequest.getPortalContext().getPortalInfo()));
attributes.put(Attributes.SCHEME.getName(), Collections.singletonList(renderRequest.getScheme()));
attributes.put(Attributes.SERVER_NAME.getName(), Collections.singletonList(renderRequest.getServerName()));
attributes.put(Attributes.SERVER_PORT.getName(), Collections.singletonList(Integer.valueOf(renderRequest.getServerPort()).toString()));
attributes.put(Attributes.SECURE.getName(), Collections.singletonList(Boolean.valueOf(renderRequest.isSecure()).toString()));
// Parameters
final Map<String, List<String>> parameters = new HashMap<>();
for (Map.Entry<String, String[]> y : renderRequest.getParameterMap().entrySet()) {
parameters.put(y.getKey(), Arrays.asList(y.getValue()));
}
// Preferences header
final PortalRequest portalRequest = portalRequestService.createPortalRequest(properties, attributes, parameters, username, getExpiration(renderRequest));
final Header rslt = new BasicHeader(Headers.PORTAL_REQUEST.getName(), portalRequest.getEncryptedToken());
logger.debug("Produced the following PortalRequest header for username='{}': {}", username, rslt);
return rslt;
}
use of org.apache.http.message.BasicHeader in project api-manager by cehome-com.
the class HttpUtils method execute.
public HttpEntity execute(String url, JSONObject headers, String requestBody) {
HttpClient httpclient = HttpClientBuilder.create().build();
try {
HttpPost httpPost = new HttpPost(url);
if (headers != null && !headers.isEmpty()) {
for (String key : headers.keySet()) {
Header header = new BasicHeader(key, headers.getString(key));
httpPost.addHeader(header);
}
}
StringEntity stringEntity = new StringEntity(requestBody, CHARSET);
stringEntity.setContentType(APPLICATION_JSON);
httpPost.setEntity(stringEntity);
HttpResponse response = httpclient.execute(httpPost);
return response.getEntity();
} catch (Exception e) {
logger.error("sendRequest error!", e);
}
return null;
}
use of org.apache.http.message.BasicHeader in project warn-report by saaavsaaa.
the class WebRequestClient method buildHeaders.
private static Header[] buildHeaders(String cookieStr) throws IOException {
Header[] headers = headerHolder.get();
if (headers == null) {
headers = new Header[1];
headers[0] = new BasicHeader("Cookie", cookieStr);
}
return headers;
}
use of org.apache.http.message.BasicHeader in project hive by apache.
the class TestThriftHttpCLIServiceFeatures method verifyForwardedHeaders.
private void verifyForwardedHeaders(ArrayList<String> headerIPs, String cmd) throws Exception {
TTransport transport;
DefaultHttpClient hClient = new DefaultHttpClient();
String httpUrl = getHttpUrl();
// add an interceptor that adds the X-Forwarded-For header with given ips
if (!headerIPs.isEmpty()) {
Header xForwardHeader = new BasicHeader("X-Forwarded-For", Joiner.on(",").join(headerIPs));
RequestDefaultHeaders headerInterceptor = new RequestDefaultHeaders(Arrays.asList(xForwardHeader));
hClient.addRequestInterceptor(headerInterceptor);
}
// interceptor for adding username, pwd
HttpBasicAuthInterceptor authInt = new HttpBasicAuthInterceptor(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, null, null);
hClient.addRequestInterceptor(authInt);
transport = new THttpClient(httpUrl, hClient);
TCLIService.Client httpClient = getClient(transport);
// Create a new open session request object
TOpenSessionReq openReq = new TOpenSessionReq();
TOpenSessionResp openResp = httpClient.OpenSession(openReq);
// execute a query
TExecuteStatementReq execReq = new TExecuteStatementReq(openResp.getSessionHandle(), "show tables");
httpClient.ExecuteStatement(execReq);
// capture arguments to authorizer impl call and verify ip addresses passed
ArgumentCaptor<HiveAuthzContext> contextCapturer = ArgumentCaptor.forClass(HiveAuthzContext.class);
verify(mockedAuthorizer).checkPrivileges(any(HiveOperationType.class), Matchers.anyListOf(HivePrivilegeObject.class), Matchers.anyListOf(HivePrivilegeObject.class), contextCapturer.capture());
HiveAuthzContext context = contextCapturer.getValue();
System.err.println("Forwarded IP Addresses " + context.getForwardedAddresses());
List<String> auditIPAddresses = new ArrayList<String>(context.getForwardedAddresses());
Collections.sort(auditIPAddresses);
Collections.sort(headerIPs);
Assert.assertEquals("Checking forwarded IP Address", headerIPs, auditIPAddresses);
}
Aggregations