Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal servlet attributes aren't always accessible #173

Closed
DanElbert opened this issue Mar 28, 2014 · 1 comment
Closed

Internal servlet attributes aren't always accessible #173

DanElbert opened this issue Mar 28, 2014 · 1 comment

Comments

@DanElbert
Copy link

I'm currently working to integrate a jruby/rails 3 app with Shibboleth, and I ran into an issue where I couldn't access the environment variables Apache was sending to the container (in my case tomcat7/trinidad).

I tracked it down to the way Rack::Handler::Servlet::DefaultEnv exposes those properties.

According to this: http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/connector/Request.html#getAttributeNames%28%29 some attribute names may not be returned from the java request.getAttributeNames.

There's no logic to specifically check for attributes not returned from getAttributeNames. In my case, the following patch fixed the problem for me, though I'm not sure if it's the best approach:

module Rack
  module Handler
    class Servlet
      class DefaultEnv
        def load_variable(env, key)
          return nil if @servlet_env.nil?
          case key
            when 'CONTENT_TYPE'
              content_type = @servlet_env.getContentType
              env[key] = content_type if content_type
            when 'CONTENT_LENGTH'
              content_length = @servlet_env.getContentLength
              env[key] = content_length.to_s if content_length >= 0
            when 'PATH_INFO'       then env[key] = @servlet_env.getPathInfo
            when 'QUERY_STRING'    then env[key] = @servlet_env.getQueryString || ''
            when 'REMOTE_ADDR'     then env[key] = @servlet_env.getRemoteAddr || ''
            when 'REMOTE_HOST'     then env[key] = @servlet_env.getRemoteHost || ''
            when 'REMOTE_USER'     then env[key] = @servlet_env.getRemoteUser || ''
            when 'REQUEST_METHOD'  then env[key] = @servlet_env.getMethod || 'GET'
            when 'REQUEST_URI'     then env[key] = @servlet_env.getRequestURI
            when 'SCRIPT_NAME'     then env[key] = @servlet_env.getScriptName
            when 'SERVER_NAME'     then env[key] = @servlet_env.getServerName || ''
            when 'SERVER_PORT'     then env[key] = @servlet_env.getServerPort.to_s
            when 'SERVER_SOFTWARE' then env[key] = rack_context.getServerInfo
            else
              hidden_attr = @servlet_env.getAttribute(key)
              if hidden_attr
                env[key] = hidden_attr
              else
                nil
              end
          end
        end
      end
    end
  end
end

Thanks,

Dan

@kares
Copy link
Member

kares commented Mar 31, 2014

Nice catch Dan, thank you ... will make sure this is fixed in 1.1.15 (should be out in a few weeks) ...

kares added a commit that referenced this issue Jun 20, 2014
@kares kares closed this as completed Jun 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants