Class AssemblylineClient
- java.lang.Object
-
- ca.gc.cyber.ops.assemblyline.java.client.clients.AssemblylineClient
-
- All Implemented Interfaces:
IAssemblylineClient
public class AssemblylineClient extends Object implements IAssemblylineClient
-
-
Field Summary
Fields Modifier and Type Field Description protected org.springframework.web.reactive.function.client.ExchangeFilterFunctionaddSessionprotected AssemblylineAuthenticationMethodassemblylineAuthenticationMethodprotected com.fasterxml.jackson.databind.ObjectMappermapperprotected Stringsessionprotected org.springframework.web.reactive.function.client.WebClientwebClient-
Fields inherited from interface ca.gc.cyber.ops.assemblyline.java.client.clients.IAssemblylineClient
BASE_URL, FILE_DOWNLOAD_URL, FILE_INFO_URL, FILE_RESULT_FOR_SERVICE_URL, FILE_RESULTS_URL, HASH_SEARCH, HASH_SEARCH_LIST_DATA_SOURCES, INGEST_GET_MESSAGE_LIST_URL, INGEST_URL, LOGIN_URL, RESULT_URL, SUBMISSION_COMPLETE_URL, SUBMISSION_FILE_RESULTS_URL, SUBMISSION_FULL_URL, SUBMISSION_TREE_URL, SUBMISSION_URL, SUBMIT_URL
-
-
Constructor Summary
Constructors Constructor Description AssemblylineClient(AssemblylineClientProperties assemblylineClientProperties, reactor.netty.http.client.HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper defaultMapper, AssemblylineAuthenticationMethod assemblylineAuthenticationMethod)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildWebClient(AssemblylineClientProperties assemblylineClientProperties, reactor.netty.http.client.HttpClient httpClient)protected <T> reactor.core.publisher.Mono<T>clientResponseToMono(org.springframework.web.reactive.function.client.ClientResponse clientResponse, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> type)Convert ClientResponse to AssemblylineApiResponse content mono.InputStreamdownloadFile(String sha256)InputStreamdownloadFile(String sha256, DownloadFileParams params)protected <T> reactor.core.publisher.Mono<T>get(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType)Helper method to perform a JSON GET request.reactor.core.publisher.Mono<FileInfo>getFileInfo(String sha256)reactor.core.publisher.Mono<FileResultForService>getFileResultForService(String sha256, String serviceName)reactor.core.publisher.Mono<FileResults>getFileResults(String sha256)reactor.core.publisher.Mono<List<String>>getHashSearchDataSources()reactor.core.publisher.Flux<IngestSubmissionResponse>getIngestMessageList(String notification)reactor.core.publisher.Mono<ResultBlock>getResult(String cacheKey)reactor.core.publisher.Mono<Submission>getSubmission(String sid)reactor.core.publisher.Mono<SubmissionFileResults>getSubmissionFileResults(String sid, String sha256)reactor.core.publisher.Mono<SubmissionFull>getSubmissionFull(String sid)reactor.core.publisher.Mono<SubmissionTree>getSubmissionTree(String sid)reactor.core.publisher.Mono<Map<String,HashSearchResult>>hashSearch(String fileHash)Search for a hash in multiple data sources, using default values for optional parameters.reactor.core.publisher.Mono<Map<String,HashSearchResult>>hashSearch(String fileHash, List<String> dataSources, Integer maxTimeout)Search for a hash in multiple data sources.reactor.core.publisher.Mono<IngestResponse>ingestBinary(BinaryFile<IngestBase> binaryIngest)reactor.core.publisher.Mono<IngestResponse>ingestUrlOrSha256(NonBinaryIngest ingest)reactor.core.publisher.Mono<Boolean>isSubmissionComplete(String sid)reactor.core.publisher.Mono<LoginResponse>login()protected <T> reactor.core.publisher.Mono<T>post(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType, org.springframework.web.reactive.function.BodyInserter<?,? super org.springframework.http.client.reactive.ClientHttpRequest> bodyInserter, org.springframework.http.MediaType contentType)Helper method to perform a JSON POST request.protected <T> reactor.core.publisher.Mono<T>retryWrapper(reactor.core.publisher.Mono<T> monoContent)protected voidsetSession(org.springframework.web.reactive.function.client.ClientResponse clientResponse)reactor.core.publisher.Mono<Submission>submitBinary(BinaryFile<SubmitMetadata> binaryIngest)reactor.core.publisher.Mono<Submission>submitUrlOrSha256(NonBinarySubmit submit)AssemblylineClientwithAuthBearerToken(String authBearerToken)Creates a copy of the current AssemblylineClient that will use the given authentication bearer token.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ca.gc.cyber.ops.assemblyline.java.client.clients.IAssemblylineClient
getSession
-
-
-
-
Field Detail
-
session
protected String session
-
webClient
protected org.springframework.web.reactive.function.client.WebClient webClient
-
mapper
protected com.fasterxml.jackson.databind.ObjectMapper mapper
-
assemblylineAuthenticationMethod
protected AssemblylineAuthenticationMethod assemblylineAuthenticationMethod
-
addSession
protected org.springframework.web.reactive.function.client.ExchangeFilterFunction addSession
-
-
Constructor Detail
-
AssemblylineClient
public AssemblylineClient(AssemblylineClientProperties assemblylineClientProperties, reactor.netty.http.client.HttpClient httpClient, com.fasterxml.jackson.databind.ObjectMapper defaultMapper, AssemblylineAuthenticationMethod assemblylineAuthenticationMethod)
-
-
Method Detail
-
withAuthBearerToken
public AssemblylineClient withAuthBearerToken(String authBearerToken)
Creates a copy of the current AssemblylineClient that will use the given authentication bearer token.- Specified by:
withAuthBearerTokenin interfaceIAssemblylineClient- Parameters:
authBearerToken- The authentication bearer token for the new client to use.- Returns:
- the new client.
-
buildWebClient
protected void buildWebClient(AssemblylineClientProperties assemblylineClientProperties, reactor.netty.http.client.HttpClient httpClient)
-
login
public reactor.core.publisher.Mono<LoginResponse> login()
- Specified by:
loginin interfaceIAssemblylineClient
-
isSubmissionComplete
public reactor.core.publisher.Mono<Boolean> isSubmissionComplete(String sid)
- Specified by:
isSubmissionCompletein interfaceIAssemblylineClient
-
getFileInfo
public reactor.core.publisher.Mono<FileInfo> getFileInfo(String sha256)
- Specified by:
getFileInfoin interfaceIAssemblylineClient
-
getFileResults
public reactor.core.publisher.Mono<FileResults> getFileResults(String sha256)
- Specified by:
getFileResultsin interfaceIAssemblylineClient
-
getFileResultForService
public reactor.core.publisher.Mono<FileResultForService> getFileResultForService(String sha256, String serviceName)
- Specified by:
getFileResultForServicein interfaceIAssemblylineClient
-
getResult
public reactor.core.publisher.Mono<ResultBlock> getResult(String cacheKey)
- Specified by:
getResultin interfaceIAssemblylineClient
-
getSubmissionFileResults
public reactor.core.publisher.Mono<SubmissionFileResults> getSubmissionFileResults(String sid, String sha256)
- Specified by:
getSubmissionFileResultsin interfaceIAssemblylineClient
-
getSubmissionTree
public reactor.core.publisher.Mono<SubmissionTree> getSubmissionTree(String sid)
- Specified by:
getSubmissionTreein interfaceIAssemblylineClient
-
getSubmission
public reactor.core.publisher.Mono<Submission> getSubmission(String sid)
- Specified by:
getSubmissionin interfaceIAssemblylineClient
-
getSubmissionFull
public reactor.core.publisher.Mono<SubmissionFull> getSubmissionFull(String sid)
- Specified by:
getSubmissionFullin interfaceIAssemblylineClient
-
ingestUrlOrSha256
public reactor.core.publisher.Mono<IngestResponse> ingestUrlOrSha256(NonBinaryIngest ingest)
- Specified by:
ingestUrlOrSha256in interfaceIAssemblylineClient
-
ingestBinary
public reactor.core.publisher.Mono<IngestResponse> ingestBinary(BinaryFile<IngestBase> binaryIngest)
- Specified by:
ingestBinaryin interfaceIAssemblylineClient
-
getIngestMessageList
public reactor.core.publisher.Flux<IngestSubmissionResponse> getIngestMessageList(String notification)
- Specified by:
getIngestMessageListin interfaceIAssemblylineClient
-
submitUrlOrSha256
public reactor.core.publisher.Mono<Submission> submitUrlOrSha256(NonBinarySubmit submit)
- Specified by:
submitUrlOrSha256in interfaceIAssemblylineClient
-
submitBinary
public reactor.core.publisher.Mono<Submission> submitBinary(BinaryFile<SubmitMetadata> binaryIngest)
- Specified by:
submitBinaryin interfaceIAssemblylineClient
-
downloadFile
public InputStream downloadFile(String sha256)
- Specified by:
downloadFilein interfaceIAssemblylineClient
-
downloadFile
public InputStream downloadFile(String sha256, DownloadFileParams params)
- Specified by:
downloadFilein interfaceIAssemblylineClient
-
getHashSearchDataSources
public reactor.core.publisher.Mono<List<String>> getHashSearchDataSources()
- Specified by:
getHashSearchDataSourcesin interfaceIAssemblylineClient
-
hashSearch
public reactor.core.publisher.Mono<Map<String,HashSearchResult>> hashSearch(String fileHash, List<String> dataSources, Integer maxTimeout)
Search for a hash in multiple data sources.- Specified by:
hashSearchin interfaceIAssemblylineClient- Parameters:
fileHash- Hash to search in the multiple data sources (MD5, SHA1 or SHA256)dataSources- list of data sources. Set to null to use server default.maxTimeout- Maximum execution time for the call in seconds. Set to null to use server default.- Returns:
- Search results
- See Also:
hashSearch(String)
-
hashSearch
public reactor.core.publisher.Mono<Map<String,HashSearchResult>> hashSearch(String fileHash)
Search for a hash in multiple data sources, using default values for optional parameters.- Specified by:
hashSearchin interfaceIAssemblylineClient- Parameters:
fileHash- Hash to search in the multiple data sources (MD5, SHA1 or SHA256)- Returns:
- Search results
- See Also:
hashSearch(String, List, Integer)
-
setSession
protected void setSession(org.springframework.web.reactive.function.client.ClientResponse clientResponse)
-
retryWrapper
protected <T> reactor.core.publisher.Mono<T> retryWrapper(reactor.core.publisher.Mono<T> monoContent)
-
get
protected <T> reactor.core.publisher.Mono<T> get(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType)
Helper method to perform a JSON GET request. This helper covers the most common GET requests. For more specialized requests, use webClient directly.- Type Parameters:
T- The type of data that will be in the response.- Parameters:
uriBuilder- UriBuilder that will generate the URI to GET.responseType- A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example,new ParameterizedTypeReference<ALApiResponse<Boolean>>is OK, butnew ParameterizedTypeReference<ALApiResponse<T>>(whereTis a type parameter on a method) is not OK.- Returns:
- The content of the "api_response" section of the response.
-
post
protected <T> reactor.core.publisher.Mono<T> post(Function<org.springframework.web.util.UriBuilder,URI> uriBuilder, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> responseType, org.springframework.web.reactive.function.BodyInserter<?,? super org.springframework.http.client.reactive.ClientHttpRequest> bodyInserter, org.springframework.http.MediaType contentType)
Helper method to perform a JSON POST request. This helper covers the most common POST requests. For more specialized requests, use webClient directly.- Type Parameters:
T- The type of data that will be in the response.- Parameters:
uriBuilder- UriBuilder that will generate the URI to POST.responseType- A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example,new ParameterizedTypeReference<ALApiResponse<Boolean>>is OK, butnew ParameterizedTypeReference<ALApiResponse<T>>(whereTis a type parameter on a method) is not OK.bodyInserter- BodyInserter to construct the body of the Post RequestcontentType- MediaType of the request body- Returns:
- The content of the "api_response" section of the response.
-
clientResponseToMono
protected <T> reactor.core.publisher.Mono<T> clientResponseToMono(org.springframework.web.reactive.function.client.ClientResponse clientResponse, org.springframework.core.ParameterizedTypeReference<AssemblylineApiResponse<T>> type)Convert ClientResponse to AssemblylineApiResponse content mono.- Type Parameters:
T- The type of data that will be in the response.- Parameters:
clientResponse- ClientResponse returned by calltype- A parameterized type reference representing the type of data that will be in the response. The declaration of this object must only include concrete type parameters. For example,new ParameterizedTypeReference<ALApiResponse<Boolean>>is OK, butnew ParameterizedTypeReference<ALApiResponse<T>>(whereTis a type parameter on a method) is not OK.- Returns:
- Mono
-
-