Author: remy.maucherat(a)jboss.com
Date: 2010-02-16 20:28:24 -0500 (Tue, 16 Feb 2010)
New Revision: 1387
Modified:
trunk/java/org/apache/catalina/connector/Request.java
Log:
- Add optional code to expose the principal associated with the session (without any auth
or login, obviously).
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2010-02-10 17:25:53 UTC (rev
1386)
+++ trunk/java/org/apache/catalina/connector/Request.java 2010-02-17 01:28:24 UTC (rev
1387)
@@ -147,7 +147,11 @@
Globals.STRICT_SERVLET_COMPLIANCE
||
Boolean.valueOf(System.getProperty("org.apache.catalina.connector.Request.CHECK_ASYNC",
"true")).booleanValue();
-
+
+ protected static final boolean USE_PRINCIPAL_FROM_SESSION =
+
Boolean.valueOf(System.getProperty("org.apache.catalina.connector.Request.USE_PRINCIPAL_FROM_SESSION",
"false")).booleanValue();
+
+
// ----------------------------------------------------------- Constructors
@@ -2379,7 +2383,8 @@
public boolean isUserInRole(String role) {
// Have we got an authenticated principal at all?
- if (userPrincipal == null)
+ Principal principal = doGetUserPrincipal();
+ if (principal == null)
return (false);
// Identify the Realm we will use for checking role assignmenets
@@ -2393,12 +2398,12 @@
if (wrapper != null) {
String realRole = wrapper.findSecurityReference(role);
if ((realRole != null) &&
- realm.hasRole(userPrincipal, realRole))
+ realm.hasRole(principal, realRole))
return (true);
}
// Check for a role defined directly as a <security-role>
- return (realm.hasRole(userPrincipal, role));
+ return (realm.hasRole(principal, role));
}
@@ -2415,15 +2420,30 @@
* Return the principal that has been authenticated for this Request.
*/
public Principal getUserPrincipal() {
- if (userPrincipal instanceof GenericPrincipal) {
- return ((GenericPrincipal) userPrincipal).getUserPrincipal();
+ Principal principal = doGetUserPrincipal();
+ if (principal instanceof GenericPrincipal) {
+ return ((GenericPrincipal) principal).getUserPrincipal();
} else {
- return (userPrincipal);
+ return (principal);
}
}
/**
+ * Return the principal that has been authenticated for this Request.
+ */
+ protected Principal doGetUserPrincipal() {
+ if (USE_PRINCIPAL_FROM_SESSION && userPrincipal == null) {
+ Session session = doGetSession(false);
+ Principal principal = session.getPrincipal();
+ if (principal != null)
+ return principal;
+ }
+ return userPrincipal;
+ }
+
+
+ /**
* Return the session associated with this Request, creating one
* if necessary.
*/
Show replies by date