use of org.forgerock.audit.AuditException in project OpenAM by OpenRock.
the class CsvAuditEventHandlerFactory method setFileRotationPolicies.
private void setFileRotationPolicies(CsvAuditEventHandlerConfiguration csvHandlerConfiguration, Map<String, Set<String>> attributes) throws AuditException {
boolean enabled = getBooleanMapAttr(attributes, "rotationEnabled", true);
csvHandlerConfiguration.getFileRotation().setRotationEnabled(enabled);
long maxFileSize = getLongMapAttr(attributes, "rotationMaxFileSize", 100000000L, DEBUG);
csvHandlerConfiguration.getFileRotation().setMaxFileSize(maxFileSize);
String filePrefix = getMapAttr(attributes, "rotationFilePrefix", "");
csvHandlerConfiguration.getFileRotation().setRotationFilePrefix(filePrefix);
String fileSuffix = getMapAttr(attributes, "rotationFileSuffix", "-MM.dd.yy-kk.mm");
csvHandlerConfiguration.getFileRotation().setRotationFileSuffix(fileSuffix);
String interval = getMapAttr(attributes, "rotationInterval", "-1");
try {
Long intervalAsLong = Long.valueOf(interval);
if (intervalAsLong <= 0) {
//If interval is 0 or a negative value, then this indicates that the feature is disabled. Change
//it to a value indicating disablement.
interval = "disabled";
} else {
//If interval is a positive number, add seconds to the end as the time unit.
interval = interval + " seconds";
}
} catch (NumberFormatException nfe) {
throw new AuditException("Attribute 'rotationInterval' is invalid: " + interval);
}
csvHandlerConfiguration.getFileRotation().setRotationInterval(interval);
List<String> times = new ArrayList<>();
Set<String> rotationTimesAttribute = attributes.get("rotationTimes");
if (rotationTimesAttribute != null && !rotationTimesAttribute.isEmpty()) {
for (String rotationTime : rotationTimesAttribute) {
times.add(rotationTime + " seconds");
}
csvHandlerConfiguration.getFileRotation().setRotationTimes(times);
}
}
use of org.forgerock.audit.AuditException in project OpenAM by OpenRock.
the class SyslogAuditEventHandlerFactory method create.
@Override
public AuditEventHandler create(AuditEventHandlerConfiguration configuration) throws AuditException {
Map<String, Set<String>> attributes = configuration.getAttributes();
SyslogAuditEventHandlerConfiguration syslogHandlerConfiguration = new SyslogAuditEventHandlerConfiguration();
syslogHandlerConfiguration.setEnabled(getBooleanMapAttr(attributes, "enabled", true));
syslogHandlerConfiguration.setName(configuration.getHandlerName());
syslogHandlerConfiguration.setTopics(attributes.get("topics"));
syslogHandlerConfiguration.setHost(getMapAttr(attributes, "host"));
setPort(syslogHandlerConfiguration, attributes);
String transportProtocol = getMapAttr(attributes, "transportProtocol");
try {
syslogHandlerConfiguration.setProtocol(TransportProtocol.valueOf(transportProtocol));
} catch (IllegalArgumentException iae) {
throw new AuditException("Attribute 'transportProtocol' is invalid: " + transportProtocol);
}
setConnectTimeout(syslogHandlerConfiguration, attributes);
EventBufferingConfiguration eventBufferingConfiguration = new EventBufferingConfiguration();
eventBufferingConfiguration.setEnabled(getBooleanMapAttr(attributes, "bufferingEnabled", true));
syslogHandlerConfiguration.setBufferingConfiguration(eventBufferingConfiguration);
String facility = getMapAttr(attributes, "facility");
try {
syslogHandlerConfiguration.setFacility(Facility.valueOf(facility));
} catch (IllegalArgumentException iae) {
throw new AuditException("Attribute 'facility' is invalid: " + facility);
}
return new SyslogAuditEventHandler(syslogHandlerConfiguration, configuration.getEventTopicsMetaData(), new ProductInfoProviderImpl(), new SyslogLocalHostNameProvider());
}
use of org.forgerock.audit.AuditException in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilter method beforeHandle.
@Override
protected int beforeHandle(Request request, Response response) {
try {
Representation representation = request.getEntity();
// buffer in order to read from it during the event logging and later during authentication
if (representation.isTransient()) {
request.setEntity(new BufferingRepresentation(request.getEntity()));
}
auditAccessAttempt(request);
} catch (AuditException e) {
debug.error("Unable to publish {} audit event '{}' due to error: {} [{}]", ACCESS_TOPIC, EventName.AM_ACCESS_ATTEMPT, e.getMessage(), e);
}
return CONTINUE;
}
use of org.forgerock.audit.AuditException in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilter method auditAccessSuccess.
private void auditAccessSuccess(Request request, Response response) {
String realm = getRealmFromRequest(request);
if (auditEventPublisher.isAuditing(realm, ACCESS_TOPIC, EventName.AM_ACCESS_OUTCOME)) {
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - request.getDate().getTime();
final Representation entity = response.getEntity();
AMAccessAuditEventBuilder builder = auditEventFactory.accessEvent(realm).timestamp(endTime).transactionId(AuditRequestContext.getTransactionIdValue()).eventName(EventName.AM_ACCESS_OUTCOME).component(component).userId(getUserIdForAccessOutcome(request, response)).trackingIds(getTrackingIdsForAccessOutcome(request, response));
JsonValue detail = null;
if (responseDetailCreator != null) {
try {
detail = responseDetailCreator.apply(entity);
} catch (AuditException e) {
debug.warning("An error occurred when fetching response body details for audit", e);
}
}
if (detail == null) {
builder.response(SUCCESSFUL, "", elapsedTime, MILLISECONDS);
} else {
builder.responseWithDetail(SUCCESSFUL, "", elapsedTime, MILLISECONDS, detail);
}
addHttpData(request, builder);
auditEventPublisher.tryPublish(ACCESS_TOPIC, builder.toEvent());
}
}
use of org.forgerock.audit.AuditException in project OpenAM by OpenRock.
the class RestletBodyAuditor method jsonAuditor.
/**
* Create a body auditor for JSON bodies.
* @param fields The fields that should be captured if they exist.
* @return The auditor object.
*/
public static RestletBodyAuditor jsonAuditor(String... fields) {
return new RestletBodyAuditor<JSONObject>(fields) {
@Override
public JsonValue apply(Representation representation) throws AuditException {
try {
boolean isBufferingRepresentation = (representation instanceof BufferingRepresentation);
boolean isEmptyBufferingRepresentation = isBufferingRepresentation && ((BufferingRepresentation) representation).getWrappedRepresentation().isEmpty();
if (isEmptyBufferingRepresentation || (!isBufferingRepresentation && representation.isEmpty())) {
return json(object());
}
return extractValues(new JsonRepresentation(representation).getJsonObject());
} catch (IOException | JSONException e) {
throw new AuditException("Could not parse body as JSON - wrong body auditor?", e);
}
}
@Override
Object getValue(String field, JSONObject object) throws AuditException {
return object.opt(field);
}
};
}
Aggregations