Does CommandBox support mocking Integrated Windows...
# box-products
j
Does CommandBox support mocking Integrated Windows Authentication? I plan to work around it by using dotenv and some logic based on environment, but don't want to if I'm missing something CommandBox already can do.
b
@John Liljegren What exactly are you using in the request to see the logged in user?
Something in the CGI scope?
j
yeah, cgi.auth_user
b
Honestly, you can just set that in CFML code
But let me check and see if CommandBox can set that
j
yeah i'm creating a new coldbox app so i plan to centralize the auth logic with cbSecurity
b
FWIW, Undertow does have a
GSSAPIAuthenticationMechanism
that CommandBox could tap into which supports kerberos and I THINK can provide actual windows auth
I've just never messed with it and no one has ever asked for it, lol
Hmm, looking in Lucee's cgi scope code,
remote_user
is set, but I don't see it setting
auth_user
unless it's part of the request attributes
remote user comes from
HTTPServletRequest.getRemoteUser()
j
this will be ACF 2021, btw
can
GSSAPIAuthenticationMechanism
be tapped into at runtime?
b
No, I'd need to add support for it in CommandBox proper
j
alright, well i'm not dying for this - like i said i can just do an env based approach
thanks for looking into it!
b
I'm still digging through some Undertow source code...
I'm not positive if Adobe gets auth_user from the same place Lucee gets cgi remote user
The undertow http servlet request impl gets it from the name of the actual authenticated Principle in the security context
Which, of course, when using basic auth or client cert auth, is set every request
Undertow's source code doesn't allow the
RemoteUserAttribute
to be written, only read so setting it in a server rule won't work
So you may need to override it at the CF level
Lucee allows the CGI scope to be written directly to, but I don't think Adobe is that cool
The typical method in CFML to override arbitrary keys in the CGI scope differs per engine but in Adobe, you can set request attributes
The question then becomes whether Adobe looks there before or after checking with the servlet.
j
right
b
I can answer that question for Lucee, since I can see the source code, but for Adobe you'd have to test it
IF it will work, it would work like so
Copy code
getPageContext().getRequest().setAttribute( 'AUTH_USER', 'my-value' ) );0
☝️ Note this is case sensitive on the key names
I know that will work for random strings that aren't common in the CGI scope, but when it comes to
AUTH_USER
, that's one that adobe has specific code for, so you'd have to test to see if Adobe checks the request attributes first or last
And the other way you can shoehorn stuff into the CGI scope which works for Adobe and Lucee is an HTTP request header, but again I doubt they are checked first as that would be a security issue
If that code above doesn't work, you'll likely just need to encapsulate your
getAuthUser()
method so the cgi scope is only touched there and then you can swap out the mechanism to get the value on dev inside that method to mock it.
Now, that said-- it is possible for CommandBox to force-override Undertow's behavior here, but it would take me writing some java code to override some stuff. Could be handy to add it in just for testing purposes, but not sure if it's worth it.
j
where should i add the
getPageContext().getRequest().setAttribute( 'AUTH_USER', 'my-value' ) );
? which lifecycle method in coldbox?
onrequeststart?
b
Anywhere in the request prior to where you access the CGI scope, lol
Just to do a quick test, add it on request start and then dump out the cgi variable right below it
j
don't think it's working
b
Ok, it was a long shot. I'm sure Adobe doesn't fall back to request attrs for that key
Also, related ticket. I guess I put this one in, lol https://luceeserver.atlassian.net/browse/LDEV-4126
Lucee is awesome some times, and then really easy stuff like this just rots in their backlog, lol
I put the code in the ticket. Someone literally just had to copy and paste it!! 😆
j
ha well it is easy enough to use a different variable
b
If doing actual win auth in CommandBox is something you would use, let me know
Would be interesting to poke at undertow's auth mechanism for it
I just don't know much about it
j
for this project, yeah i would, but it's really easy to work around
i'm trying to introduce commandbox to this client