Skip to content
Permalink
Browse files

Add login and logout automation events (#179)

* Add login and logout automation events

fix #178

* Add login and logout automation events

fix #178
  • Loading branch information...
darkman97i authored and monkiki committed Apr 22, 2019
1 parent 5a841d4 commit 9838d17f6ed57385a87bf05e2d43c4c95ab58fd1
@@ -66,6 +66,7 @@
public static final String PROPERTY_GROUP_NAME = "propGroupName";
public static final String PROPERTY_GROUP_PROPERTIES = "propGroupProperties";
public static final String EVENT = "event";
public static final String USER = "user";

/**
* getPath
@@ -190,6 +191,16 @@ public static String getParentPath(Map<String, Object> env) throws AccessDeniedE
return null;
}

/**
* getUser
*/
public static String getUser(Map<String, Object> env) {
if (env.containsKey(USER)) {
return (String) env.get(USER);
}
return "";
}

/**
* getTextExtracted
*/
@@ -426,6 +426,13 @@ public void createValidation(AutomationValidation av) throws DatabaseException {
* findValidationByClassName
*/
public Validation findValidationByClassName(String className) throws AutomationException {
if (validatorsList == null) {
try {
findValidations(true);
} catch (URISyntaxException e) {
throw new AutomationException(e);
}
}
for (Validation validation : validatorsList) {
if (validation.getClass().getName().equals(className)) {
return validation;
@@ -439,6 +446,13 @@ public Validation findValidationByClassName(String className) throws AutomationE
* findActionByClassName
*/
public Action findActionByClassName(String className) throws AutomationException {
if (actionsList == null) {
try {
findActions(true);
} catch (URISyntaxException e) {
throw new AutomationException(e);
}
}
for (Action action : actionsList) {
if (action.getClass().getName().equals(className)) {
return action;
@@ -57,6 +57,9 @@
public static final String EVENT_PROPERTY_GROUP_SET = "prop_group_set";
public static final String EVENT_PROPERTY_GROUP_REMOVE = "prop_group_remove";

public static final String EVENT_USER_LOGIN = "user_login";
public static final String EVENT_USER_LOGOUT = "user_logout";

public static final Map<String, String> EVENTS = new LinkedHashMap<String, String>() {
private static final long serialVersionUID = 1L;

@@ -79,6 +82,9 @@

put(AutomationRule.EVENT_CONVERSION_PDF, "Convert to PDF");
put(AutomationRule.EVENT_CONVERSION_SWF, "Convert to SWF");

put(AutomationRule.EVENT_USER_LOGIN, "User login");
put(AutomationRule.EVENT_USER_LOGOUT, "User logout");
}
};

@@ -22,13 +22,16 @@
package com.openkm.module.db;

import com.google.gson.Gson;
import com.openkm.automation.AutomationManager;
import com.openkm.automation.AutomationUtils;
import com.openkm.bean.ChangeSecurityParams;
import com.openkm.bean.Permission;
import com.openkm.bean.Repository;
import com.openkm.core.*;
import com.openkm.dao.NodeBaseDAO;
import com.openkm.dao.NodeFolderDAO;
import com.openkm.dao.PendingTaskDAO;
import com.openkm.dao.bean.AutomationRule;
import com.openkm.dao.bean.NodeFolder;
import com.openkm.dao.bean.PendingTask;
import com.openkm.module.AuthModule;
@@ -146,6 +149,15 @@ public void logout(String token) throws RepositoryException, DatabaseException {
if (!Config.SYSTEM_USER.equals(auth.getName())) {
DbSessionManager.getInstance().remove(token);

// AUTOMATION - PRE
Map<String, Object> env = new HashMap<>();
env.put(AutomationUtils.USER, PrincipalUtils.getUser());
try {
AutomationManager.getInstance().fireEvent(AutomationRule.EVENT_USER_LOGOUT, AutomationRule.AT_PRE, env);
} catch (Exception e) {
log.info("Automation ERROR: {}", e.getCause());
}

// Activity log
UserActivity.log(auth.getName(), "LOGOUT", token, null, null);
} else {
@@ -21,6 +21,9 @@

package com.openkm.spring;

import com.openkm.automation.AutomationManager;
import com.openkm.automation.AutomationUtils;
import com.openkm.dao.bean.AutomationRule;
import com.openkm.util.GenericHolder;
import com.openkm.util.UserActivity;
import org.slf4j.Logger;
@@ -31,6 +34,9 @@
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import java.util.HashMap;
import java.util.Map;

public class LoggerListener implements ApplicationListener<AbstractAuthenticationEvent> {
private static Logger log = LoggerFactory.getLogger(LoggerListener.class);

@@ -50,6 +56,15 @@ public void onApplicationEvent(AbstractAuthenticationEvent event) {
params = (String) GenericHolder.get();
}

// AUTOMATION - POST
Map<String, Object> env = new HashMap<>();
env.put(AutomationUtils.USER, event.getAuthentication().getName());
try {
AutomationManager.getInstance().fireEvent(AutomationRule.EVENT_USER_LOGIN, AutomationRule.AT_POST, env);
} catch (Exception e) {
log.info("Automation ERROR: {}", e.getCause());
}

UserActivity.log(event.getAuthentication().getName(), "LOGIN", null, null, params);
} else if (event instanceof AuthenticationFailureBadCredentialsEvent) {
log.info("Authentication ERROR: {}", event.getAuthentication().getName());

0 comments on commit 9838d17

Please sign in to comment.
You can’t perform that action at this time.