From 5d3308a2dea70bc9b6175df54a502e5c55b77092 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Wed, 19 Jul 2017 11:16:27 +0200
Subject: [PATCH] The security principal is a faces-only (web container)
 feature and not generally for beans.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

Signed-off-by: Roland Häder <roland@mxchange.org>
---
 src/org/mxchange/jcoreee/bean/BaseBean.java   | 29 ++-----------------
 .../jcoreee/bean/faces/BaseFacesBean.java     | 24 +++++++++++++++
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/src/org/mxchange/jcoreee/bean/BaseBean.java b/src/org/mxchange/jcoreee/bean/BaseBean.java
index 09e581e..8efd545 100644
--- a/src/org/mxchange/jcoreee/bean/BaseBean.java
+++ b/src/org/mxchange/jcoreee/bean/BaseBean.java
@@ -17,9 +17,7 @@
 package org.mxchange.jcoreee.bean;
 
 import java.io.Serializable;
-import java.security.Principal;
 import javax.faces.FacesException;
-import javax.faces.context.FacesContext;
 import javax.jms.Connection;
 import javax.jms.JMSException;
 import javax.jms.MessageProducer;
@@ -86,10 +84,10 @@ public abstract class BaseBean implements Serializable {
 			Context context = new InitialContext();
 
 			// Get factory from JMS resource
-			QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup(factoryJndi); //NOI18N
+			QueueConnectionFactory connectionFactory = (QueueConnectionFactory) context.lookup(factoryJndi);
 
 			// Lookup queue
-			this.queue = (Queue) context.lookup(queueJndi); //NOI18N
+			this.queue = (Queue) context.lookup(queueJndi);
 
 			// Create connection
 			this.connection = connectionFactory.createConnection();
@@ -105,29 +103,6 @@ public abstract class BaseBean implements Serializable {
 		}
 	}
 
-	/**
-	 * 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;
-	}
-
 	/**
 	 * Getter for configured message producer instance
 	 * <p>
diff --git a/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java b/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java
index 454b2a3..5496e29 100644
--- a/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java
+++ b/src/org/mxchange/jcoreee/bean/faces/BaseFacesBean.java
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jcoreee.bean.faces;
 
+import java.security.Principal;
 import java.text.MessageFormat;
 import java.util.Locale;
 import java.util.MissingResourceException;
@@ -44,6 +45,29 @@ public abstract class BaseFacesBean extends BaseBean {
 		super();
 	}
 
+	/**
+	 * 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>
-- 
2.39.5