Search in sources :

Example 1 with BytesFullResponseHandler

use of org.apache.druid.java.util.http.client.response.BytesFullResponseHandler in project druid by druid-io.

the class AbstractQueryResourceTestClient method query.

public List<Map<String, Object>> query(String url, QueryType query) {
    try {
        String expectedResponseType = this.contentTypeHeader;
        Request request = new Request(HttpMethod.POST, new URL(url));
        request.setContent(this.contentTypeHeader, encoderDecoderMap.get(this.contentTypeHeader).encode(query));
        if (this.acceptHeader != null) {
            expectedResponseType = this.acceptHeader;
            request.addHeader(HttpHeaders.Names.ACCEPT, this.acceptHeader);
        }
        BytesFullResponseHolder response = httpClient.go(request, new BytesFullResponseHandler()).get();
        if (!response.getStatus().equals(HttpResponseStatus.OK)) {
            throw new ISE("Error while querying[%s] status[%s] content[%s]", url, response.getStatus(), new String(response.getContent(), StandardCharsets.UTF_8));
        }
        String responseType = response.getResponse().headers().get(HttpHeaders.Names.CONTENT_TYPE);
        if (!expectedResponseType.equals(responseType)) {
            throw new ISE("Content-Type[%s] in HTTP response does not match the expected[%s]", responseType, expectedResponseType);
        }
        return this.encoderDecoderMap.get(responseType).decode(response.getContent());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BytesFullResponseHolder(org.apache.druid.java.util.http.client.response.BytesFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) ISE(org.apache.druid.java.util.common.ISE) URL(java.net.URL) IOException(java.io.IOException) BytesFullResponseHandler(org.apache.druid.java.util.http.client.response.BytesFullResponseHandler)

Example 2 with BytesFullResponseHandler

use of org.apache.druid.java.util.http.client.response.BytesFullResponseHandler in project druid by druid-io.

the class CoordinatorPollingBasicAuthorizerCacheManager method tryFetchGroupMappingMapsFromCoordinator.

private GroupMappingAndRoleMap tryFetchGroupMappingMapsFromCoordinator(String prefix) throws Exception {
    Request req = druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format("/druid-ext/basic-security/authorization/db/%s/cachedSerializedGroupMappingMap", prefix));
    BytesFullResponseHolder responseHolder = druidLeaderClient.go(req, new BytesFullResponseHandler());
    // running 0.17.0+ tries to access this endpoint on an older coordinator.
    if (responseHolder.getStatus().equals(HttpResponseStatus.NOT_FOUND)) {
        LOG.warn("cachedSerializedGroupMappingMap is not available from the coordinator, skipping fetch of group mappings for now.");
        return null;
    }
    byte[] groupRoleMapBytes = responseHolder.getContent();
    GroupMappingAndRoleMap groupMappingAndRoleMap = objectMapper.readValue(groupRoleMapBytes, BasicAuthUtils.AUTHORIZER_GROUP_MAPPING_AND_ROLE_MAP_TYPE_REFERENCE);
    if (groupMappingAndRoleMap != null && commonCacheConfig.getCacheDirectory() != null) {
        writeGroupMappingMapToDisk(prefix, groupRoleMapBytes);
    }
    return groupMappingAndRoleMap;
}
Also used : BytesFullResponseHolder(org.apache.druid.java.util.http.client.response.BytesFullResponseHolder) GroupMappingAndRoleMap(org.apache.druid.security.basic.authorization.entity.GroupMappingAndRoleMap) Request(org.apache.druid.java.util.http.client.Request) BytesFullResponseHandler(org.apache.druid.java.util.http.client.response.BytesFullResponseHandler)

Example 3 with BytesFullResponseHandler

use of org.apache.druid.java.util.http.client.response.BytesFullResponseHandler in project druid by druid-io.

the class CoordinatorPollingBasicAuthorizerCacheManager method tryFetchUserMapsFromCoordinator.

private UserAndRoleMap tryFetchUserMapsFromCoordinator(String prefix) throws Exception {
    Request req = druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format("/druid-ext/basic-security/authorization/db/%s/cachedSerializedUserMap", prefix));
    BytesFullResponseHolder responseHolder = druidLeaderClient.go(req, new BytesFullResponseHandler());
    byte[] userRoleMapBytes = responseHolder.getContent();
    UserAndRoleMap userAndRoleMap = objectMapper.readValue(userRoleMapBytes, BasicAuthUtils.AUTHORIZER_USER_AND_ROLE_MAP_TYPE_REFERENCE);
    if (userAndRoleMap != null && commonCacheConfig.getCacheDirectory() != null) {
        writeUserMapToDisk(prefix, userRoleMapBytes);
    }
    return userAndRoleMap;
}
Also used : UserAndRoleMap(org.apache.druid.security.basic.authorization.entity.UserAndRoleMap) BytesFullResponseHolder(org.apache.druid.java.util.http.client.response.BytesFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) BytesFullResponseHandler(org.apache.druid.java.util.http.client.response.BytesFullResponseHandler)

Example 4 with BytesFullResponseHandler

use of org.apache.druid.java.util.http.client.response.BytesFullResponseHandler in project druid by druid-io.

the class CoordinatorPollingBasicAuthenticatorCacheManager method tryFetchUserMapFromCoordinator.

private Map<String, BasicAuthenticatorUser> tryFetchUserMapFromCoordinator(String prefix) throws Exception {
    Map<String, BasicAuthenticatorUser> userMap = null;
    Request req = druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format("/druid-ext/basic-security/authentication/db/%s/cachedSerializedUserMap", prefix));
    BytesFullResponseHolder responseHolder = druidLeaderClient.go(req, new BytesFullResponseHandler());
    byte[] userMapBytes = responseHolder.getContent();
    if (ArrayUtils.isNotEmpty(userMapBytes)) {
        userMap = objectMapper.readValue(userMapBytes, BasicAuthUtils.AUTHENTICATOR_USER_MAP_TYPE_REFERENCE);
        if (userMap != null && commonCacheConfig.getCacheDirectory() != null) {
            writeUserMapToDisk(prefix, userMapBytes);
        }
    } else {
        LOG.info("Empty cached serialized user map retrieved, authenticator - %s", prefix);
    }
    return userMap;
}
Also used : BytesFullResponseHolder(org.apache.druid.java.util.http.client.response.BytesFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) BasicAuthenticatorUser(org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorUser) BytesFullResponseHandler(org.apache.druid.java.util.http.client.response.BytesFullResponseHandler)

Aggregations

Request (org.apache.druid.java.util.http.client.Request)4 BytesFullResponseHandler (org.apache.druid.java.util.http.client.response.BytesFullResponseHandler)4 BytesFullResponseHolder (org.apache.druid.java.util.http.client.response.BytesFullResponseHolder)4 IOException (java.io.IOException)1 URL (java.net.URL)1 ISE (org.apache.druid.java.util.common.ISE)1 BasicAuthenticatorUser (org.apache.druid.security.basic.authentication.entity.BasicAuthenticatorUser)1 GroupMappingAndRoleMap (org.apache.druid.security.basic.authorization.entity.GroupMappingAndRoleMap)1 UserAndRoleMap (org.apache.druid.security.basic.authorization.entity.UserAndRoleMap)1