Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
authentication-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
Julian Horner
authentication-service
Commits
a35cf176
Commit
a35cf176
authored
5 years ago
by
Julian Horner
Browse files
Options
Downloads
Patches
Plain Diff
Improve comments and add header details to response
parent
73f05b3e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/rtuni/ms/as/SecurityConfiguration.java
+14
-9
14 additions, 9 deletions
src/main/java/de/rtuni/ms/as/SecurityConfiguration.java
with
14 additions
and
9 deletions
src/main/java/de/rtuni/ms/as/SecurityConfiguration.java
+
14
−
9
View file @
a35cf176
...
@@ -19,7 +19,7 @@ import org.springframework.security.core.userdetails.UserDetailsService;
...
@@ -19,7 +19,7 @@ import org.springframework.security.core.userdetails.UserDetailsService;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
/**
/**
* Class that
handles
security configuration.
* Class that
enables custom
security configuration.
*
*
* @author Julian
* @author Julian
*
*
...
@@ -32,7 +32,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
...
@@ -32,7 +32,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
@Autowired
private
UserDetailsService
userDetailsService
;
private
UserDetailsService
userDetailsService
;
/** The co
nfiguration
for the json web token. */
/** The
<
co
de>JwtConfig</code>
for the json web token. */
@Autowired
@Autowired
private
JwtConfig
jwtConfig
;
private
JwtConfig
jwtConfig
;
...
@@ -48,8 +48,12 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
...
@@ -48,8 +48,12 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
).
and
()
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
).
and
()
// handle an authorized attempts
// handle an authorized attempts
.
exceptionHandling
().
authenticationEntryPoint
(
.
exceptionHandling
().
authenticationEntryPoint
(
(
req
,
rsp
,
e
)
->
rsp
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
))
(
req
,
rsp
,
e
)
->
{
.
and
()
rsp
.
setContentType
(
"application/json"
);
rsp
.
setCharacterEncoding
(
"UTF-8"
);
rsp
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
);
}
).
and
()
/*
/*
* Add a filter to validate user credentials and add token in the response header.
* Add a filter to validate user credentials and add token in the response header.
...
@@ -58,8 +62,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
...
@@ -58,8 +62,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
* used to authenticate the user passing user's credentials. The filter needs this
* used to authenticate the user passing user's credentials. The filter needs this
* authentication manager to authenticate the user.
* authentication manager to authenticate the user.
*/
*/
.
addFilter
(
.
addFilter
(
new
JwtUsernameAndPasswordAuthenticationFilter
(
new
JwtUsernameAndPasswordAuthenticationFilter
(
authenticationManager
(),
jwtConfig
))
authenticationManager
(),
jwtConfig
))
.
authorizeRequests
()
.
authorizeRequests
()
// allow all POST requests
// allow all POST requests
.
antMatchers
(
HttpMethod
.
POST
,
jwtConfig
.
getUri
()).
permitAll
()
.
antMatchers
(
HttpMethod
.
POST
,
jwtConfig
.
getUri
()).
permitAll
()
...
@@ -67,13 +71,14 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
...
@@ -67,13 +71,14 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.
anyRequest
().
authenticated
();
.
anyRequest
().
authenticated
();
}
}
// TODO improve comment
/**
/**
* Spring has <code>UserDetailsService</code> interface, which can be overridden to provide our
* Spring has <code>UserDetailsService</code> interface, which can be overridden to provide our
* implementation for fetching user from database (or any other source).
* implementation for fetching user from database (or any other source).
* <p>
* <p>
* The UserDetailsService object is used by the authentication manager to load the
user
* The
<code>
UserDetailsService
</code>
object is used by the authentication manager to load the
* from database. In addition, we need to define the password encoder also. So,
authentication
*
user
from database. In addition, we need to define the password encoder also. So,
* manager can compare and verify passwords.
*
authentication
manager can compare and verify passwords.
*/
*/
@Override
@Override
protected
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
protected
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
...
...
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