无法根据Apache virtualhost中的路径位置编辑身份验证标头?

无法根据Apache virtualhost中的路径位置编辑身份验证标头?,apache,Apache,Apache作为反向代理的应用程序的行为如下: 它需要基本的身份验证头才能登录到它 对于从/api/*开始的路径,只需要承载令牌 如果报头中有基本令牌,应用程序将返回401,未经授权的http响应-它只需要承载令牌 除了/api/*路径之外,所有URL都配置了CAS身份验证,我正在vhost config文件中设置基本身份验证令牌-在用户使用CAS进行身份验证后,无需再次提交登录表单即可登录用户 Apache配置文件enterprisesearch.conf: <VirtualHost *

Apache作为反向代理的应用程序的行为如下:

  • 它需要基本的身份验证头才能登录到它
  • 对于从
    /api/*
    开始的路径,只需要承载令牌
  • 如果报头中有基本令牌,应用程序将返回401,未经授权的http响应-它只需要承载令牌
  • 除了
    /api/*
    路径之外,所有URL都配置了CAS身份验证,我正在vhost config文件中设置基本身份验证令牌-在用户使用CAS进行身份验证后,无需再次提交登录表单即可登录用户

    Apache配置文件
    enterprisesearch.conf

    <VirtualHost *:80>
            ServerName https://search.test.xyz
            ServerAdmin john@xyz
    
        RemoteIPHeader X-Client-IP
        RemoteIPInternalProxy 10.10.10.2
        LogFormat "%a %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"" combined-forwarded
    
        CustomLog ${APACHE_LOG_DIR}/enterprise-search-access.log combined-forwarded
        ErrorLog ${APACHE_LOG_DIR}/enterprise-search-error.log
    
        LogLevel debug
        
            CASRootProxiedAs https://search.xyz
        
        <Location />
            # authn type
            AuthType CAS
            CASScope /
            AuthName "KFUPM"
            # authz
            # Grant all groups access to the root
            AuthGroupFile "/etc/apache2/http-authz/enterprise-search"
            Require group all-enterpirse-search
            # Pass REMOTE_USER header to application
            RewriteEngine On
            RewriteCond %{LA-U:REMOTE_USER} (.+)$
            RewriteRule . - [E=RU:%1,NS]
            RequestHeader set REMOTE_USER %{RU}e
            RequestHeader set Authorization "Basic xxxxxxxxxx"
        </Location>
    
        # authz: local_groups
            <Location /all-enterpirse-search>
            AuthGroupFile "/etc/apache2/http-authz/enterprise-search"
            Require group all-enterprise-search all-enterpirse-search
        </Location>
            
        <Location /api/>
            # authn type
            AuthType none
            Allow from all
            Satisfy any
            
            # authz
            Require valid-user
            # Pass REMOTE_USER header to application
            RewriteEngine On
            RewriteCond %{LA-U:REMOTE_USER} (.+)$
            RewriteRule . - [E=RU:%1,NS]
            RequestHeader set REMOTE_USER %{RU}e
            RequestHeader edit Authorization "Basic[^,]+, " ""
    
            ProxyPass / http://localhost:3002/
        ProxyPassReverse / http://localhost:3002/
        </Location>    
        
    </VirtualHost>
    
    
    服务器名https://search.test.xyz
    服务器管理员john@xyz
    RemoteIPHeader X-Client-IP
    RemoteIPInternalProxy 10.10.10.2
    日志格式“%a%l%u%t\%r\%s%b\”%{Referer}i\“%{User agent}i\\”组合转发
    CustomLog${APACHE\u LOG\u DIR}/enterprise-search-access.LOG
    ErrorLog${APACHE_LOG_DIR}/enterprise-search-error.LOG
    日志级调试
    卡斯罗特普罗西达斯酒店https://search.xyz
    #作者类型
    认证类型CAS
    卡斯科镜/
    AuthName“KFUPM”
    #奥兹
    #授予所有组对根目录的访问权限
    AuthGroupFile“/etc/apache2/http authz/enterprisesearch”
    需要组所有企业搜索
    #将远程用户头传递给应用程序
    重新启动发动机
    RewriteCond%{LA-U:REMOTE_USER}(+)$
    重写规则[E=RU:%1,NS]
    RequestHeader设置远程用户%{RU}e
    RequestHeader设置授权“基本XXXXXXXXX”
    #authz:local_组
    AuthGroupFile“/etc/apache2/http authz/enterprisesearch”
    要求集团所有企业搜索所有企业搜索
    #作者类型
    AuthType无
    通融
    满足任何
    #奥兹
    需要有效用户
    #将远程用户头传递给应用程序
    重新启动发动机
    RewriteCond%{LA-U:REMOTE_USER}(+)$
    重写规则[E=RU:%1,NS]
    RequestHeader设置远程用户%{RU}e
    RequestHeader编辑授权“基本[^,]+,”
    ProxyPass/http://localhost:3002/
    ProxyPassReverse/http://localhost:3002/
    
    RequestHeader编辑授权“Basic[^,]+,”“”
    的行为是替换客户端传递的基本令牌头,它工作正常

    但我真正想要的是在
    中设置基本令牌,并在
    中删除它。在
    中使用
    RequestHeader编辑授权“Basic[^,]+,”“”
    不会删除基本令牌,应用程序将返回API调用和401响应

    我是Apache configs新手,可能是我实现目标的方法不正确。请建议是否有更好的方法来做到这一点


    谢谢。

    由于您需要授权和应用程序的代理路径,因此无法获取此路径。 但您可以在前端创建api,将CAS路径设置为/auth之类的路径,并通过api重定向到CAS