Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kypo-user-and-group
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MUNI-KYPO-CRP
backend-java
kypo-user-and-group
Commits
00682d3b
Commit
00682d3b
authored
5 years ago
by
Pavel Šeda
Browse files
Options
Downloads
Patches
Plain Diff
spring bean for cors based as primary filter.
parent
0efbc5d4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kypo2-security-user-and-group/src/main/java/cz/muni/ics/kypo/userandgroup/security/config/ResourceServerSecurityConfig.java
+11
-8
11 additions, 8 deletions
...ndgroup/security/config/ResourceServerSecurityConfig.java
with
11 additions
and
8 deletions
kypo2-security-user-and-group/src/main/java/cz/muni/ics/kypo/userandgroup/security/config/ResourceServerSecurityConfig.java
+
11
−
8
View file @
00682d3b
...
...
@@ -11,10 +11,9 @@ import org.mitre.openid.connect.client.service.impl.DynamicServerConfigurationSe
import
org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.*
;
import
org.springframework.core.Ordered
;
import
org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.http.SessionCreationPolicy
;
...
...
@@ -26,6 +25,7 @@ import org.springframework.security.web.session.HttpSessionEventPublisher;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.CorsConfigurationSource
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
@@ -58,14 +58,17 @@ public class ResourceServerSecurityConfig extends ResourceServerConfigurerAdapte
private
CustomAuthorityGranter
customAuthorityGranter
;
@Bean
@Primary
public
CorsConfigurationSource
corsConfigurationSource
()
{
CorsConfiguration
configuration
=
new
CorsConfiguration
();
configuration
.
setAllowedOrigins
(
Arrays
.
as
List
(
corsAllowedOrigins
));
configuration
.
setAllowedMethods
(
Arrays
.
as
List
(
"GET"
,
"POST"
,
"PUT"
,
"PATCH"
,
"DELETE"
,
"OPTIONS"
));
configuration
.
setAllowedHeaders
(
Arrays
.
as
List
(
"authorization"
,
"content-type"
,
"x-auth-token"
));
configuration
.
setExposedHeaders
(
Arrays
.
as
List
(
"x-auth-token"
));
configuration
.
setAllowedOrigins
(
List
.
of
(
corsAllowedOrigins
));
configuration
.
setAllowedMethods
(
List
.
of
(
"GET"
,
"POST"
,
"PUT"
,
"PATCH"
,
"DELETE"
,
"OPTIONS"
));
configuration
.
setAllowedHeaders
(
List
.
of
(
"authorization"
,
"content-type"
,
"x-auth-token"
));
configuration
.
setExposedHeaders
(
List
.
of
(
"x-auth-token"
));
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
configuration
);
FilterRegistrationBean
corsFilter
=
new
FilterRegistrationBean
(
new
CorsFilter
(
source
));
corsFilter
.
setOrder
(
Ordered
.
HIGHEST_PRECEDENCE
);
return
source
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment