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

时间:2017-11-09 15:36:26

标签: rest spring-security liferay basic-authentication

通过在liferay中为休息服务实现Spring Basic Authorization,我面临着一个非常尴尬的问题。 实际上,当我在本地计算机上测试应用程序时,配置工作正常。

只要在测试服务器上部署应用程序,就会出现问题。 服务器始终返回401未经授权的访问权限,但永远不会访问授权提供程序。

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

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

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

这是我的安全配置:

 <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>

我将不胜感激任何帮助。

1 个答案:

答案 0 :(得分:0)

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

Apache配置

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;