From: Roland Häder Date: Wed, 19 Jul 2017 09:16:27 +0000 (+0200) Subject: The security principal is a faces-only (web container) feature and not X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5d3308a2dea70bc9b6175df54a502e5c55b77092;p=jcoreee.git The security principal is a faces-only (web container) feature and not generally for beans. Signed-off-by: Roland Häder --- 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. - *

- * @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 *

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. + *

+ * @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. *