]> git.mxchange.org Git - jjobs-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Fri, 26 Aug 2016 13:36:12 +0000 (15:36 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 28 Aug 2016 18:47:58 +0000 (20:47 +0200)
- introduced determinePrincipalName()
- added logging of principal's name
- activity log also shows it
- added missing i18n string

src/java/org/mxchange/jjobs/beans/BaseJobsController.java
src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebApplicationBean.java
src/java/org/mxchange/localization/bundle_de_DE.properties
src/java/org/mxchange/localization/bundle_en_US.properties
web/admin/user/admin_user_activity_log.xhtml

index de5289f47f88887857c4e31a6328a3473300a702..a9f461ab756ed5bbe2cb4c4b700634ff96dfe256 100644 (file)
@@ -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.
+        * <p>
+        * @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.
         * <p>
index 7c387ad75347de22b72b8db3de0f90c0d3bf8393..607ec59c38e1e272187d18145008564edabd531e 100644 (file)
@@ -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) {
index 63532d5e1477ddf3ce8b79f6497c30ee3714fc39..dacc22aab1f809f6ccfd9b016d59f8f1a7986255 100644 (file)
@@ -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:
index 01ae184ea6f5a7321c7da823c5c53fd7ce017b95..1f38285f29884f432a7669ca0d7d3fdb6a4164bc 100644 (file)
@@ -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:
index 8ef87ad64cf0477dc4dc4ed22034f55440a57bed..56289add0dc3d3adbd459080f9c534d3474b7eeb 100644 (file)
                                        </h:column>
                                </ui:fragment>
 
+                               <h:column>
+                                       <f:facet name="header">
+                                               <h:outputText value="#{msg.ADMIN_SHOW_PRINCIPAL_NAME}" />
+                                       </f:facet>
+
+                                       <h:outputText value="#{userActivity.activityPrincipalName}" />
+                               </h:column>
+
                                <h:column>
                                        <f:facet name="header">
                                                <h:outputText value="#{msg.ADMIN_LIST_USER_GENDER}" />