Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
IncomeCalculator
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
neel
IncomeCalculator
Commits
0fbafda4
Commit
0fbafda4
authored
Apr 24, 2020
by
neel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auth token in response header
parent
798038fe
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
src/main/java/com/iRecruit/config/SecurityConfig.java
+15
-0
src/main/java/com/iRecruit/security/JwtAuthenticationFilter.java
+2
-0
No files found.
src/main/java/com/iRecruit/config/SecurityConfig.java
View file @
0fbafda4
...
@@ -17,6 +17,9 @@ import org.springframework.security.config.http.SessionCreationPolicy;
...
@@ -17,6 +17,9 @@ import org.springframework.security.config.http.SessionCreationPolicy;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.CorsConfigurationSource
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
com.iRecruit.security.AuthProvider
;
import
com.iRecruit.security.AuthProvider
;
import
com.iRecruit.security.CustomUserDetailsService
;
import
com.iRecruit.security.CustomUserDetailsService
;
...
@@ -102,4 +105,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -102,4 +105,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
http
.
addFilterBefore
(
jwtAuthenticationFilter
(),
UsernamePasswordAuthenticationFilter
.
class
);
http
.
addFilterBefore
(
jwtAuthenticationFilter
(),
UsernamePasswordAuthenticationFilter
.
class
);
}
}
@Bean
public
CorsConfigurationSource
corsConfigurationSource
()
{
CorsConfiguration
configuration
=
new
CorsConfiguration
();
configuration
.
setAllowedOrigins
(
Arrays
.
asList
(
"*"
));
configuration
.
setAllowedMethods
(
Arrays
.
asList
(
"GET"
,
"POST"
,
"PUT"
,
"PATCH"
,
"DELETE"
,
"OPTIONS"
));
configuration
.
setAllowedHeaders
(
Arrays
.
asList
(
"authorization"
,
"content-type"
,
"x-auth-token"
,
"auth"
));
configuration
.
setExposedHeaders
(
Arrays
.
asList
(
"x-auth-token"
,
"auth"
));
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
configuration
);
return
source
;
}
}
}
\ No newline at end of file
src/main/java/com/iRecruit/security/JwtAuthenticationFilter.java
View file @
0fbafda4
...
@@ -44,6 +44,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
...
@@ -44,6 +44,8 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
authentication
.
setDetails
(
new
WebAuthenticationDetailsSource
().
buildDetails
(
request
));
authentication
.
setDetails
(
new
WebAuthenticationDetailsSource
().
buildDetails
(
request
));
jwt
=
tokenProvider
.
generateToken
(
authentication
);
jwt
=
tokenProvider
.
generateToken
(
authentication
);
response
.
setHeader
(
"Access-Control-Allow-Headers"
,
"auth"
);
response
.
setHeader
(
"Access-Control-Expose-Headers"
,
"auth"
);
response
.
setHeader
(
"auth"
,
jwt
);
response
.
setHeader
(
"auth"
,
jwt
);
UserPrincipal
userPrincipal
=
(
UserPrincipal
)
authentication
.
getPrincipal
();
UserPrincipal
userPrincipal
=
(
UserPrincipal
)
authentication
.
getPrincipal
();
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
SecurityContextHolder
.
getContext
().
setAuthentication
(
authentication
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment