mod_auth_cas environment variables not accessible

74 views
Skip to first unread message

Brian Keifer

unread,
Oct 29, 2021, 3:59:04 PM10/29/21
to CAS Community
I've got an application that has one field for "Full Name" but our environment only releases GivenName and Surname.  I thought it would be trivial to use something like mod_headers or mod_rewrite to concatenate these two fields together, but it's proving more of a challenge than I expected.

I used a PHP script in my application's directory to verify that the variables were set by calling print_r($_SERVER); and get, among others, the following variables displayed:

[HTTP_CAS_SURNAME] => Keifer
[HTTP_CAS_GIVENNAME] => Brian

If I try to combine these using:

RequestHeader set MyHeader "%{HTTP_CAS_GIVENNAME}e %{HTTP_CAS_SURNAME}e"

I end up with this:

[HTTP_MYHEADER] => (null) (null)

I've tried this using mod_rewrite as well.  I used REMOTE_ADDR just to prove to myself that I could at least access some variables.

RewriteRule .* - [E=GIVENNAME:%{LA-U:REMOTE_ADDR}]
RewriteRule .* - [E=SURNAME:%{LA-U:HTTP_CAS_SURNAME}]

produces this:

[SURNAME] =>
[GIVENNAME] => 10.2.12.142

Interestingly, using mod_headers in a similar fashion with one CAS variable and REMOTE_ADDR behaves differently.  This:

RequestHeader set GIVENNAME1 "%{HTTP_CAS_GIVENNAME}e"
RequestHeader set SURNAME1 "%{REMOTE_ADDR}e"

Produces:

[HTTP_SURNAME1] => (null)
[HTTP_GIVENNAME1] => (null)

Can anyone shed some light on this?  Why can't I get at these variables?

Thanks,

-Brian

Jim Toth

unread,
Oct 30, 2021, 6:11:51 AM10/30/21
to cas-...@apereo.org
I believe headers are changed into environment variables much later: you’ll need to use a different syntax to get at thems. 

I’d guess “{CAS_SURNAME}i” from my memory of how one uses headers in log formats, but check the mod_rewrite docs at httpd.apache.org.

Also, I’d recommend being consistent with your case, even if the specific protocol is case insensitive. You set MyHeader but use MYHEADER.  I say this because I got confused, not because you were wrong. ;-)

--
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
---
You received this message because you are subscribed to the Google Groups "CAS Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cas-user+u...@apereo.org.
To view this discussion on the web visit https://groups.google.com/a/apereo.org/d/msgid/cas-user/1483014e-e004-4c68-bf22-46ec44fa9070n%40apereo.org.
--
Jim Toth
Lead Engineer, Middleware
Technology Services

David Hawes

unread,
Oct 30, 2021, 2:54:18 PM10/30/21
to CAS Community
The CAS attributes are stored as request headers and won't be
available in the apache environment.

You'd have to store them as apache environment variables to be able to
get at them with RequestHeader (I think). Something like this should
work for you:

diff --git a/src/mod_auth_cas.c b/src/mod_auth_cas.c
index 1791110..f2361ce 100644
--- a/src/mod_auth_cas.c
+++ b/src/mod_auth_cas.c
@@ -2146,6 +2146,7 @@ static void set_http_headers(request_rec *r,
cas_cfg *c, cas_dir_cfg *d, cas_sam
av = av->next;
}
apr_table_set(r->headers_in,
apr_psprintf(r->pool, "%s%s", c->CASAttributePrefix,
normalizeHeaderName(r, a->attr)), csvs);
+ apr_table_set(r->subprocess_env,
apr_psprintf(r->pool, "%s%s", c->CASAttributePrefix,
normalizeHeaderName(r, a->attr)), csvs);
a = a->next;
Reply all
Reply to author
Forward
0 new messages