我正在使用Angular 5作为前端和Spring Boot REST服务器。如果不使用SSL,一切都可以正常工作。但是当我切换到SSL后,我最终让一切都有些工作。它适用于GET请求,但到目前为止,我无法使PUT请求通过。
我猜这可能是CORS问题,因为GET是一个简单的请求,而PUT显然不是 (CORS参考),但我无法找出如何解决问题。
在我的Spring Boot Rest Controllers上,我使用注释@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 Forbidden):
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
Angular服务运行在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
}
}