Новый пустой проект только с подключенным rest-api аддоном.
rest.zip (105.6 КБ)
Шаги по воспроизведению:
- Запустить проект.
- Вызвать метод получения токена POST на localhost:8080/app/rest/v2/oauth/token?grant_type=password&username=admin&password=admin с базовой авторизацией.
Ожидаемый результат: возвращается json с токенами.
Фактический результат: возвращается html страница с ошибкой. В логах приложения ничего нет.
<!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.
org.springframework.web.cors.CorsConfiguration.validateAllowCredentials(CorsConfiguration.java:473)
org.springframework.web.cors.CorsConfiguration.checkOrigin(CorsConfiguration.java:577)
org.springframework.web.cors.DefaultCorsProcessor.checkOrigin(DefaultCorsProcessor.java:174)
org.springframework.web.cors.DefaultCorsProcessor.handleInternal(DefaultCorsProcessor.java:116)
org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:95)
org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:87)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:92)
org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:77)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:354)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:267)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108)
org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74)
com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:93)
</pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p><hr class="line" /><h3>Apache Tomcat/9.0.38</h3></body></html>
Причина ошибки видимо в связке allowCredentials=true
и allowedOrigins=*
что используется по умолчанию через свойство cuba.rest.allowedOrigins.
Там для этого появилось новое свойство allowedOriginPatterns
что поддерживает эту комбинацию.
Как обходной временный путь надо создать rest-dispatcher-spring.xml и переопределить бин:
<bean id="cuba_RestCorsConfig" class="org.springframework.web.cors.CorsConfiguration">
<!--<property name="allowedOrigins" value="${cuba.rest.allowedOrigins}"/>-->
<property name="allowedOriginPatterns" value="${cuba.rest.allowedOrigins}"/>
<property name="allowedHeaders" value="*"/>
<property name="allowedMethods" value="*"/>
<property name="allowCredentials" value="true"/>
<property name="exposedHeaders">
<list>
<value>X-Total-Count</value>
<value>Content-Disposition</value>
</list>
</property>
</bean>