...
|
...
|
@@ -18,7 +18,9 @@ package org.thingsboard.server.config; |
18
|
18
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
19
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
20
|
20
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
21
|
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
21
|
22
|
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
|
23
|
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
22
|
24
|
import org.springframework.context.annotation.Bean;
|
23
|
25
|
import org.springframework.context.annotation.Configuration;
|
24
|
26
|
import org.springframework.core.annotation.Order;
|
...
|
...
|
@@ -34,6 +36,9 @@ import org.springframework.security.web.authentication.AuthenticationFailureHand |
34
|
36
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
35
|
37
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
36
|
38
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
39
|
+import org.springframework.web.cors.CorsUtils;
|
|
40
|
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
|
41
|
+import org.springframework.web.filter.CorsFilter;
|
37
|
42
|
import org.thingsboard.server.exception.ThingsboardErrorResponseHandler;
|
38
|
43
|
import org.thingsboard.server.service.security.auth.rest.RestAuthenticationProvider;
|
39
|
44
|
import org.thingsboard.server.service.security.auth.rest.RestLoginProcessingFilter;
|
...
|
...
|
@@ -146,6 +151,8 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt |
146
|
151
|
protected void configure(HttpSecurity http) throws Exception {
|
147
|
152
|
http.headers().cacheControl().disable().frameOptions().disable()
|
148
|
153
|
.and()
|
|
154
|
+ .cors()
|
|
155
|
+ .and()
|
149
|
156
|
.csrf().disable()
|
150
|
157
|
.exceptionHandling()
|
151
|
158
|
.and()
|
...
|
...
|
@@ -172,4 +179,17 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt |
172
|
179
|
.addFilterBefore(buildRefreshTokenProcessingFilter(), UsernamePasswordAuthenticationFilter.class)
|
173
|
180
|
.addFilterBefore(buildWsJwtTokenAuthenticationProcessingFilter(), UsernamePasswordAuthenticationFilter.class);
|
174
|
181
|
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+ @Bean
|
|
185
|
+ @ConditionalOnMissingBean(CorsFilter.class)
|
|
186
|
+ public CorsFilter corsFilter(@Autowired MvcCorsProperties mvcCorsProperties) {
|
|
187
|
+ if (mvcCorsProperties.getMappings().size() == 0) {
|
|
188
|
+ return new CorsFilter(new UrlBasedCorsConfigurationSource());
|
|
189
|
+ } else {
|
|
190
|
+ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
|
191
|
+ source.setCorsConfigurations(mvcCorsProperties.getMappings());
|
|
192
|
+ return new CorsFilter(source);
|
|
193
|
+ }
|
|
194
|
+ }
|
175
|
195
|
} |
...
|
...
|
|