Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/main/java/com/alienvault/otx/connect/OTXConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
Expand All @@ -48,7 +47,7 @@ public class OTXConnection {
private String otxHost = "otx.alienvault.com";
private String otxScheme = "https";
private Integer otxPort = null;
private static DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
private static DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
private Log log = LogFactory.getLog(OTXConnection.class);

/**
Expand Down Expand Up @@ -257,16 +256,24 @@ private List<Pulse> getPulses(Map<OTXEndpointParameters, ?> endpointParametersMa
}

private List<?> getPagedResults(Map<OTXEndpointParameters, ?> endpointParametersMap, Page<?> page, OTXEndpoints endpoint) throws MalformedURLException, URISyntaxException {
if (endpointParametersMap == null || !endpointParametersMap.containsKey(OTXEndpointParameters.LIMIT)){
Map newParams;
if (endpointParametersMap != null) {
newParams = new HashMap(endpointParametersMap);
}else{
newParams = new HashMap();
}
newParams.put(OTXEndpointParameters.LIMIT, 20);
endpointParametersMap = newParams;
}
Map newParams;

if (endpointParametersMap != null) {
newParams = new HashMap(endpointParametersMap);
} else {
newParams = new HashMap();
}

if (!endpointParametersMap.containsKey(OTXEndpointParameters.LIMIT)) {
newParams.put(OTXEndpointParameters.LIMIT, 20);
}

if (!endpointParametersMap.containsKey(OTXEndpointParameters.INDICATOR_LIMIT)) {
newParams.put(OTXEndpointParameters.INDICATOR_LIMIT, 10000);
}

endpointParametersMap = newParams;

List pulseList = new ArrayList<>();
Page<?> firstPage = executeGetRequest(endpoint, endpointParametersMap, page.getClass());
pulseList.addAll(firstPage.getResults());
Expand All @@ -275,15 +282,14 @@ private List<?> getPagedResults(Map<OTXEndpointParameters, ?> endpointParameters
String nextPage = getParameterFromQueryString(rawQuery, OTXEndpointParameters.PAGE);
// cskellie - passed in new parameter with page count to fetch next page of results.
Map parametersMap = new HashMap<>();
if (endpointParametersMap!=null) {
if (endpointParametersMap != null) {
parametersMap.putAll(endpointParametersMap);
}
parametersMap.putAll(Collections.singletonMap(OTXEndpointParameters.PAGE, nextPage));
firstPage = executeGetRequest(endpoint, parametersMap, page.getClass());
pulseList.addAll(firstPage.getResults());
}
return pulseList;

}

private String getParameterFromQueryString(String rawQuery, OTXEndpointParameters page) {
Expand Down Expand Up @@ -334,7 +340,7 @@ private URI buildURI(OTXEndpoints endpoint, Map<OTXEndpointParameters, ?> endpoi
String value = UriUtils.encodeQueryParam(otxEndpointParametersEntry.getValue().toString(), "UTF-8");
endpointString = endpointString + String.format("%s=%s&", parameterName, value);
} catch (UnsupportedEncodingException e) {
log.error("Unpossible");
log.error("Impossible");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public enum OTXEndpointParameters {
* Limit is used by any Paged endpoint to set the page size
*/
LIMIT("limit", OTXEndpointParameterTypes.INTEGER),
/**
* Limits number of indicators per pulse to passed in number
*/
INDICATOR_LIMIT("indicator_limit", OTXEndpointParameterTypes.INTEGER),
/**
* Modified since is used by the SUBSCRIBED endpoint to limit the Pulses return.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

public class OtxDateDeserializer extends JsonDeserializer<Date> {

private static final SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private static final SimpleDateFormat FORMAT_MILLIS = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");

@Override
public Date deserialize(JsonParser jsonparser,
DeserializationContext deserializationcontext) throws IOException, JsonProcessingException {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String date = jsonparser.getText();
try {
return format.parse(date);
return date.indexOf('.') > -1 ? FORMAT_MILLIS.parse(date) : FORMAT.parse(date);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down