From f3ea1fcdbea6c0530bf95dcb154b32ee5324e600 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 26 Aug 2016 15:36:12 +0200 Subject: [PATCH] Please cherry-pick: - introduced determinePrincipalName() - added logging of principal's name - activity log also shows it - added missing i18n string --- .../jjobs/beans/BaseJobsController.java | 24 +++++++++++++++++++ .../JobsUserActivityWebApplicationBean.java | 6 ++--- .../localization/bundle_de_DE.properties | 1 + .../localization/bundle_en_US.properties | 1 + web/admin/user/admin_user_activity_log.xhtml | 8 +++++++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/BaseJobsController.java b/src/java/org/mxchange/jjobs/beans/BaseJobsController.java index de5289f4..a9f461ab 100644 --- a/src/java/org/mxchange/jjobs/beans/BaseJobsController.java +++ b/src/java/org/mxchange/jjobs/beans/BaseJobsController.java @@ -17,6 +17,7 @@ package org.mxchange.jjobs.beans; import java.io.Serializable; +import java.security.Principal; import java.text.MessageFormat; import java.util.Locale; import java.util.MissingResourceException; @@ -36,6 +37,29 @@ public abstract class BaseJobsController implements Serializable { */ private static final long serialVersionUID = 50_837_597_127_567_140L; + /** + * Determines principal's name or returns null if no principal (security) is + * set. + *

+ * @return Principal's name or null + */ + protected String determinePrincipalName () { + // Get principal + Principal userPrincipal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); + + // Init with null + String principalName = null; + + // Is the principal set? + if (userPrincipal instanceof Principal) { + // Get principal's name + principalName = userPrincipal.getName(); + } + + // Return it + return principalName; + } + /** * Returns given property key or throws an exception if not found. *

diff --git a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java index 7c387ad7..607ec59c 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java @@ -124,7 +124,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple } // Create new activity object - LogableUserActivity userActivity = new UserActivityLog(activityType, user, new GregorianCalendar()); + LogableUserActivity userActivity = new UserActivityLog(activityType, user, new GregorianCalendar(), this.determinePrincipalName()); // Call bean to add it this.userActivityBean.addUserActivityLog(userActivity); @@ -160,7 +160,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple } // Create new activity object - LogableUserActivity userActivity = new UserActivityLog(message, activityType, user, new GregorianCalendar()); + LogableUserActivity userActivity = new UserActivityLog(message, activityType, user, new GregorianCalendar(), this.determinePrincipalName()); // Call bean to add it this.userActivityBean.addUserActivityLog(userActivity); @@ -322,7 +322,7 @@ public class JobsUserActivityWebApplicationBean extends BaseJobsController imple if (null == event) { // Throw NPE throw new NullPointerException("event is null"); //NOI18N - } else if (event.getLoggedOutUser()== null) { + } else if (event.getLoggedOutUser() == null) { // Throw NPE again throw new NullPointerException("event.loggedOutUser is null"); //NOI18N } else if (event.getLoggedOutUser().getUserId() == null) { diff --git a/src/java/org/mxchange/localization/bundle_de_DE.properties b/src/java/org/mxchange/localization/bundle_de_DE.properties index 63532d5e..dacc22aa 100644 --- a/src/java/org/mxchange/localization/bundle_de_DE.properties +++ b/src/java/org/mxchange/localization/bundle_de_DE.properties @@ -768,3 +768,4 @@ USER_ACTIVITY_ADMIN_ADDED_USER_ACCOUNT=Ein Administrator hat Ihren Benutzeracciu ADMIN_ACTIVITY_USER_LOGGED_OUT=Benutzer hat sich ausgeloggt. USER_ACTIVITY_USER_LOGGED_OUT=Sie haben sich ausgeloggt. ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Fehler: Die Anwendung verwendet keine Benutzernamen, dennoch wurde dieses Template geladen. +ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login: diff --git a/src/java/org/mxchange/localization/bundle_en_US.properties b/src/java/org/mxchange/localization/bundle_en_US.properties index 01ae184e..1f38285f 100644 --- a/src/java/org/mxchange/localization/bundle_en_US.properties +++ b/src/java/org/mxchange/localization/bundle_en_US.properties @@ -769,3 +769,4 @@ USER_ACTIVITY_ADMIN_ADDED_USER_ACCOUNT=An aministrator has created your new user ADMIN_ACTIVITY_USER_LOGGED_OUT=User has logged out. USER_ACTIVITY_USER_LOGGED_OUT=You have logged out. ERROR_GUEST_USER_NAME_REQUIRED_DISABLED=Error: This application requires no user name, still this template has been loaded. +ADMIN_SHOW_PRINCIPAL_NAME=Admin-Login: diff --git a/web/admin/user/admin_user_activity_log.xhtml b/web/admin/user/admin_user_activity_log.xhtml index 8ef87ad6..56289add 100644 --- a/web/admin/user/admin_user_activity_log.xhtml +++ b/web/admin/user/admin_user_activity_log.xhtml @@ -52,6 +52,14 @@ + + + + + + + + -- 2.39.5