【发布时间】:2018-06-13 09:38:45
【问题描述】:
我使用 Angular 5 作为 Spring Boot REST 服务器的前端。如果不使用 SSL,一切正常。当我切换到 SSL 时,最终我得到了一切工作。它适用于 GET 请求,但到目前为止我无法通过 PUT 请求。
我的猜测是这是某种 CORS 问题,因为 GET 是一个简单的请求,而 PUT 显然不是 (CORS reference),但我不知道如何解决这个问题。
在我的 Spring Boot Rest Controller 上,我有注释 @CrossOrigin("*"),所以我认为这不是问题,但我不确定。
另一个难题是身份验证是通过 CAS 服务器处理的。我已将以下配置添加到 CAS 属性中。这些是允许 GET 请求工作的最后一块,但我不确定要对它们进行哪些更改(如果有的话)以处理 PUT 请求:
cas.httpWebRequest.cors.enabled=true
cas.httpWebRequest.cors.allowOrigins[0]=*
cas.httpWebRequest.cors.allowMethods[0]=*
cas.httpWebRequest.cors.allowHeaders[0]=*
这是我的请求标头和响应:
请求:
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.5
Connection: keep-alive
Content-Length: 1975
Content-Type: application/json
Cookie: JSESSIONID=117D9345E985D824E46…BF32; io=gLhCcBoZrfNcppioAAAB
Host: localhost:4200
Referer: https://localhost:4200/sales/proposals/dashboard
User-Agent: Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/57.0
响应(状态代码 - 403 禁止):
access-control-allow-origin: *
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-length: 56
content-type: application/json;charset=UTF-8
date: Wed, 03 Jan 2018 16:39:14 GMT
expires: 0
pragma: no-cache
strict-transport-security: max-age=31536000 ; includeSubDomains
x-content-type-options: nosniff
X-Firefox-Spdy: h2
x-frame-options: DENY
x-powered-by: Express
x-xss-protection: 1; mode=block
角度服务正在https://localhost:4200 上运行。
spring boot 服务正在https://localhost:8493上运行。
CAS 服务正在https://localhost:8443 上运行。
我在任何日志中都没有看到错误消息。我希望能够理解为什么禁止 PUT 请求,然后如何修复它以便 PUT 请求也可以工作。谢谢!
编辑:添加 Spring Boot 安全配置
<http pattern="/**" entry-point-ref="casEntryPoint">
<intercept-url pattern="/api/holidays" access="permitAll"/>
<intercept-url pattern="/api/unit**" access="permitAll"/>
<intercept-url pattern="/**" access="isAuthenticated()" />
<custom-filter ref="casAuthenticationFilter" before="CAS_FILTER"/>
<csrf/>
</http>
<global-method-security pre-post-annotations="enabled"/>
<!-- CAS Config -->
<beans:bean id="casEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
<beans:property name="loginUrl" value="${cas.server.host.login_url}"/>
<beans:property name="serviceProperties" ref="serviceProperties"/>
</beans:bean>
<beans:bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
<beans:property name="service" value="${app.server.host.url}login/cas"></beans:property>
</beans:bean>
<beans:bean id="casAuthenticationFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter">
<beans:property name="authenticationManager" ref="authenticationManager"/>
</beans:bean>
<beans:bean id="casAuthenticationProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
<beans:property name="ticketValidator" ref="ticketValidator"></beans:property>
<beans:property name="serviceProperties" ref="serviceProperties"></beans:property>
<beans:property name="key" value="Key"></beans:property>
<beans:property name="authenticationUserDetailsService" ref="userDetailsWrapper"/>
</beans:bean>
<beans:bean id="userDetailsWrapper" class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
<beans:property name="userDetailsService" ref="userDetails"></beans:property>
</beans:bean>
<ldap-user-service id="userDetails"
server-ref="ldapServer"
group-search-base="ou=ERPGroups,OU=MyBusiness"
group-search-filter="(member={0})"
user-search-base="ou=SBSUsers,OU=Users,OU=MyBusiness"
user-search-filter="(sAMAccountName={0})" />
<ldap-server id="ldapServer" url="${ldap.urls}/${ldap.base}" manager-dn="${ldap.username}" manager-password="${ldap.password}" />
<beans:bean id="ticketValidator" class="org.jasig.cas.client.validation.Cas30ServiceTicketValidator">
<beans:constructor-arg value="${cas.server.host.url}"></beans:constructor-arg>
</beans:bean>
<authentication-manager alias="authenticationManager">
<authentication-provider ref="casAuthenticationProvider" />
</authentication-manager>
编辑:添加 Angular 代理配置
{
"/api": {
"target" : "https://localhost:8493",
"changeOrigin": true,
"secure" : false
}
}
【问题讨论】:
-
403 表示禁止,例如用户未经过身份验证/允许访问方法服务器端。我对CAS不太了解,但是PUT请求中发送的是CAS cookie吗? (我看到一个会话 cookie 和 'io' cookie)。如果这是一个 cors 问题,它将是客户端,如果您启动浏览器的开发工具/调试器,您应该会看到一些东西
-
能否提供您在spring boot server应用上使用的安全配置?
-
我刚刚发现 x-powered-by: Express x-xss-protection: 1; mode=block 你在使用 NodeJS Express 代理吗?
-
如果有CORS问题,参考这个链接stackoverflow.com/questions/46788969/…
标签: angular ssl spring-boot cas