Java Code Examples for org.apache.http.HttpHeaders#AUTHORIZATION

The following examples show how to use org.apache.http.HttpHeaders#AUTHORIZATION . 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: LoggingHttpRequestExecutor.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected HttpResponse doSendRequest(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException {
    synchronized(listener) {
        listener.log(TranscriptListener.Type.request, request.getRequestLine().toString());
        for(Header header : request.getAllHeaders()) {
            switch(header.getName()) {
                case HttpHeaders.AUTHORIZATION:
                case HttpHeaders.PROXY_AUTHORIZATION:
                case "X-Auth-Key":
                case "X-Auth-Token":
                    listener.log(TranscriptListener.Type.request, String.format("%s: %s", header.getName(),
                            StringUtils.repeat("*", Integer.min(8, StringUtils.length(header.getValue())))));
                    break;
                default:
                    listener.log(TranscriptListener.Type.request, header.toString());
                    break;
            }
        }
    }
    final HttpResponse response = super.doSendRequest(request, conn, context);
    if(null != response) {
        // response received as part of an expect-continue handshake
        this.log(response);
    }
    return response;
}
 
Example 2
Source File: ESConfiguration.java    From SkaETL with Apache License 2.0 5 votes vote down vote up
@Bean
public RestHighLevelClient elasticsearchRestConnection(ESConfiguration esConfiguration) {
    String auth = esConfiguration.getServiceElasticsearchUsername() + ":" + esConfiguration.getServiceElasticsearchPassword();
    String authB64;
    try {
        authB64 = Base64.getEncoder().encodeToString(auth.getBytes("utf-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Impossible encoding for user " + esConfiguration.getServiceElasticsearchUsername() + " and password " + esConfiguration.getServiceElasticsearchPassword() + " msg " + e);
    }
    RestClientBuilder builder = RestClient.builder(
            new HttpHost(esConfiguration.getHost(), Integer.valueOf(esConfiguration.getPort()), "http"));
    Header[] defaultHeaders = new Header[]{
            new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json"),
            new BasicHeader("cluster.name", esConfiguration.getClusterName()),
            new BasicHeader(HttpHeaders.AUTHORIZATION, "Basic " + authB64)
    };
    builder.setDefaultHeaders(defaultHeaders);
    builder.setMaxRetryTimeoutMillis(esConfiguration.getSocketTimeout() * 1000);
    builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
        @Override
        public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
            return requestConfigBuilder
                    .setConnectionRequestTimeout(connectionRequestTimeout)
                    .setConnectTimeout(esConfiguration.getConnectionTimeout() * 1000)
                    .setSocketTimeout(esConfiguration.getSocketTimeout() * 1000);
        }
    });
    return new RestHighLevelClient(builder);
}
 
Example 3
Source File: FacadeResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * @param cookieAuthValue クッキー内の dc_cookieキーに指定された値
 * @param cookiePeer dc_cookie_peerクエリに指定された値
 * @param authzHeaderValue Authorization ヘッダ
 * @param host Host ヘッダ
 * @param uriInfo UriInfo
 * @param xDcUnitUser X-Dc-UnitUserヘッダ
 * @param httpServletRequest HttpServletRequest
 * @return CellResourceオブジェクトまたはResponseオブジェクト
 */
@Path("{path1}")
public final Object facade(
        @CookieParam(DC_COOKIE_KEY) final String cookieAuthValue,
        @QueryParam(COOKIE_PEER_QUERY_KEY) final String cookiePeer,
        @HeaderParam(HttpHeaders.AUTHORIZATION) final String authzHeaderValue,
        @HeaderParam(HttpHeaders.HOST) final String host,
        @HeaderParam(DcCoreUtils.HttpHeaders.X_DC_UNIT_USER) final String xDcUnitUser,
        @Context final UriInfo uriInfo,
        @Context HttpServletRequest httpServletRequest) {
    Cell cell = ModelFactory.cell(uriInfo);
    AccessContext ac = AccessContext.create(authzHeaderValue,
            uriInfo, cookiePeer, cookieAuthValue, cell, uriInfo.getBaseUri().toString(),
            host, xDcUnitUser);
    if (cell == null) {
        throw DcCoreException.Dav.CELL_NOT_FOUND;
    }

    long cellStatus = CellLockManager.getCellStatus(cell.getId());
    if (cellStatus == CellLockManager.CELL_STATUS_BULK_DELETION) {
        throw DcCoreException.Dav.CELL_NOT_FOUND;
    }

    CellLockManager.incrementReferenceCount(cell.getId());
    httpServletRequest.setAttribute("cellId", cell.getId());
    return new CellResource(ac);
}
 
Example 4
Source File: FacadeResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * @param cookieAuthValue クッキー内の dc_cookieキーに指定された値
 * @param cookiePeer dc_cookie_peerクエリに指定された値
 * @param authzHeaderValue Authorization ヘッダ
 * @param host Host ヘッダ
 * @param xDcUnitUser ヘッダ
 * @param uriInfo UriInfo
 * @return UnitCtlResourceオブジェクト
 */
@Path("__ctl")
public final UnitCtlResource ctl(
        @CookieParam(DC_COOKIE_KEY) final String cookieAuthValue,
        @QueryParam(COOKIE_PEER_QUERY_KEY) final String cookiePeer,
        @HeaderParam(HttpHeaders.AUTHORIZATION) final String authzHeaderValue,
        @HeaderParam(HttpHeaders.HOST) final String host,
        @HeaderParam(DcCoreUtils.HttpHeaders.X_DC_UNIT_USER) final String xDcUnitUser,
        @Context final UriInfo uriInfo) {
    AccessContext ac = AccessContext.create(authzHeaderValue,
            uriInfo, cookiePeer, cookieAuthValue, null, uriInfo.getBaseUri().toString(),
            host, xDcUnitUser);
    return new UnitCtlResource(ac, uriInfo);
}
 
Example 5
Source File: FacadeResource.java    From io with Apache License 2.0 5 votes vote down vote up
/**
 * @param authzHeaderValue Authorization ヘッダ
 * @param host Host ヘッダ
 * @param xDcUnitUser ヘッダ
 * @param uriInfo UriInfo
 * @return UnitCtlResourceオブジェクト
 */
@Path("__status")
public final StatusResource status(
        @HeaderParam(HttpHeaders.AUTHORIZATION) final String authzHeaderValue,
        @HeaderParam(HttpHeaders.HOST) final String host,
        @HeaderParam(DcCoreUtils.HttpHeaders.X_DC_UNIT_USER) final String xDcUnitUser,
        @Context final UriInfo uriInfo) {
    return new StatusResource();
}
 
Example 6
Source File: SAPIClient.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
public SAPIClient(Map<String, String> op) throws MalformedURLException {
    this(op.get("api.status.link"), "", "");
    auth = new BasicHeader(HttpHeaders.AUTHORIZATION,
            op.get("api.status.auth").replaceAll(",$", ""));
}
 
Example 7
Source File: APIAuthenticationHandler.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "LEST_LOST_EXCEPTION_STACK_TRACE", justification = "The exception needs to thrown for fault sequence invocation")
protected void initializeAuthenticators() {
    authenticators = new ArrayList<>();

    boolean isOAuthProtected = false;
    boolean isMutualSSLProtected = false;
    boolean isBasicAuthProtected = false;
    boolean isApiKeyProtected = false;
    boolean isMutualSSLMandatory = false;
    boolean isOAuthBasicAuthMandatory = false;

    // Set security conditions
    if (apiSecurity == null) {
        isOAuthProtected = true;
    } else {
        String[] apiSecurityLevels = apiSecurity.split(",");
        for (String apiSecurityLevel : apiSecurityLevels) {
            if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.DEFAULT_API_SECURITY_OAUTH2)) {
                isOAuthProtected = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_MUTUAL_SSL)) {
                isMutualSSLProtected = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_BASIC_AUTH)) {
                isBasicAuthProtected = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_MUTUAL_SSL_MANDATORY)) {
                isMutualSSLMandatory = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase(APIConstants.API_SECURITY_OAUTH_BASIC_AUTH_API_KEY_MANDATORY)) {
                isOAuthBasicAuthMandatory = true;
            } else if (apiSecurityLevel.trim().equalsIgnoreCase((APIConstants.API_SECURITY_API_KEY))) {
                isApiKeyProtected = true;
            }
        }
    }
    if (!isMutualSSLProtected && !isOAuthBasicAuthMandatory) {
        isOAuthBasicAuthMandatory = true;
    }
    if (!isBasicAuthProtected && !isOAuthProtected && !isMutualSSLMandatory && !isApiKeyProtected) {
        isMutualSSLMandatory = true;
    }

    // Retrieve authorization header name
    if (authorizationHeader == null) {
        try {
            authorizationHeader = APIUtil
                    .getOAuthConfigurationFromAPIMConfig(APIConstants.AUTHORIZATION_HEADER);
            if (authorizationHeader == null) {
                authorizationHeader = HttpHeaders.AUTHORIZATION;
            }
        } catch (APIManagementException e) {
            log.error("Error while reading authorization header from APIM configurations", e);
        }
    }

    // Set authenticators
    Authenticator authenticator;
    if (isMutualSSLProtected) {
        authenticator = new MutualSSLAuthenticator(apiLevelPolicy, isMutualSSLMandatory, certificateInformation);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }
    if (isOAuthProtected) {
        authenticator = new OAuthAuthenticator(authorizationHeader, isOAuthBasicAuthMandatory,
                removeOAuthHeadersFromOutMessage, apiLevelPolicy, keyManagersList);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }
    if (isBasicAuthProtected) {
        authenticator = new BasicAuthAuthenticator(authorizationHeader, isOAuthBasicAuthMandatory);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }
    if (isApiKeyProtected) {
        authenticator = new ApiKeyAuthenticator(APIConstants.API_KEY_HEADER_QUERY_PARAM, apiLevelPolicy, isOAuthBasicAuthMandatory);
        authenticator.init(synapseEnvironment);
        authenticators.add(authenticator);
    }

    authenticators.sort(new Comparator<Authenticator>() {
        @Override
        public int compare(Authenticator o1, Authenticator o2) {
            return (o1.getPriority() - o2.getPriority());
        }
    });
}