Liferay上REST服务的Spring 基本授权不起作用



我在Liferay中为休息服务实施Spring Basic Authorization时遇到了一个非常尴尬的问题。实际上,当我在本地计算机上测试应用程序时,配置可以完美运行。

在测试服务器上部署应用程序后,问题就会出现。服务器始终返回 401 未授权访问,但从未访问到授权提供程序。

通过调试,我注意到在到达 BasicAuthenticationFilter 时,请求不包含带有凭据的标头(标头 = null):

if(header != null && header.startsWith("Basic "))

通过分析浏览器上的网络流量,授权标头就在那里。

这是我的安全配置:

 <http pattern="/*" security="none"/>
<!-- urls that need authentication and roles  -->
<http use-expressions="true" >
    <intercept-url pattern="/myrest/url/**" access="hasAnyRole('myrole')" />
    <http-basic/>
</http>
<!-- AuthenticationManager / Provider that checks the authentication against Liferay -->
<beans:bean id="myCustomAuthorizationProvider"
            class="myCustomAuthorizationProvider">
    <beans:constructor-arg ref="myUsersDao"/>
    <beans:constructor-arg ref="MyRolesDao"/>
</beans:bean>
<authentication-manager>
    <authentication-provider ref="myCustomAuthorizationProvider"/>
</authentication-manager>

我将不胜感激任何帮助。

在进入liferay tomcat之前,您需要检查过滤http标头之间是否有任何中间apache或Web服务器。在 apache Web 服务器或 nginx 中,您需要设置授权标头转发。

Apache Config

proxy_pass_header Authorization;

对于nginx

proxy_set_header X-Forwarded-User $http_authorization;
proxy_set_header X-Real-IP  $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header Accept;
proxy_pass_header Server;
proxy_http_version 1.1;
proxy_set_header Authorization $http_authorization;
#proxy_pass_header Authorization;
proxy_set_header ns_server-ui yes;

最新更新