Search in sources :

Example 56 with BasicHeader

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;
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) HashMap(java.util.HashMap) List(java.util.List) PortletPreferences(javax.portlet.PortletPreferences) PortletPreferences(javax.portlet.PortletPreferences) Preferences(org.apereo.portal.soffit.model.v1_0.Preferences) HashMap(java.util.HashMap) Map(java.util.Map) BasicHeader(org.apache.http.message.BasicHeader)

Example 57 with BasicHeader

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;
}
Also used : BasicHeader(org.apache.http.message.BasicHeader) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) PortalRequest(org.apereo.portal.soffit.model.v1_0.PortalRequest)

Example 58 with BasicHeader

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;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) BasicHeader(org.apache.http.message.BasicHeader)

Example 59 with BasicHeader

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;
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader)

Example 60 with BasicHeader

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);
}
Also used : RequestDefaultHeaders(org.apache.http.client.protocol.RequestDefaultHeaders) HiveAuthzContext(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzContext) ArrayList(java.util.ArrayList) THttpClient(org.apache.thrift.transport.THttpClient) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) HiveOperationType(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) TCLIService(org.apache.hive.service.rpc.thrift.TCLIService) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) TTransport(org.apache.thrift.transport.TTransport) TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) TOpenSessionResp(org.apache.hive.service.rpc.thrift.TOpenSessionResp) BasicHeader(org.apache.http.message.BasicHeader) HttpBasicAuthInterceptor(org.apache.hive.jdbc.HttpBasicAuthInterceptor)

Aggregations

BasicHeader (org.apache.http.message.BasicHeader)128 Header (org.apache.http.Header)67 Test (org.junit.Test)29 List (java.util.List)21 HashMap (java.util.HashMap)19 HttpGet (org.apache.http.client.methods.HttpGet)18 BasicStatusLine (org.apache.http.message.BasicStatusLine)17 ProtocolVersion (org.apache.http.ProtocolVersion)16 StatusLine (org.apache.http.StatusLine)16 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)16 IOException (java.io.IOException)15 HttpURLConnection (java.net.HttpURLConnection)15 URL (java.net.URL)15 HttpResponse (org.apache.http.HttpResponse)15 Response (org.elasticsearch.client.Response)10 ArrayList (java.util.ArrayList)9 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 TestHttpResponse (org.robolectric.shadows.httpclient.TestHttpResponse)9 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)8 StringEntity (org.apache.http.entity.StringEntity)8