protected static boolean sendAuthenticationEvent(UserIdentificationInfo userInfo, String eventId, String comment) {
LoginContext loginContext = null;
try {
try {
loginContext = Framework.login();
} catch (LoginException e) {
log.error("Unable to log in in order to log Login event" + e.getMessage());
return false;
}
EventProducer evtProducer = Framework.getService(EventProducer.class);
NuxeoPrincipal principal = new UserPrincipal(userInfo.getUserName(), null, false, false);
Map<String, Serializable> props = new HashMap<>();
props.put("AuthenticationPlugin", userInfo.getAuthPluginName());
props.put("LoginPlugin", userInfo.getLoginPluginName());
props.put("category", LOGIN_CATEGORY);
props.put("comment", comment);
EventContext ctx = new UnboundEventContext(principal, props);
evtProducer.fireEvent(ctx.newEvent(eventId));
return true;
} finally {
if (loginContext != null) {
try {
loginContext.logout();
} catch (LoginException e) {
log.error("Unable to logout: " + e.getMessage());
}
}
}
}