Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api-gateway
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
api-gateway
Commits
623bc0c7
Commit
623bc0c7
authored
5 years ago
by
Julian Horner
Browse files
Options
Downloads
Patches
Plain Diff
Adjust security configurations
parent
0d3600e0
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
src/main/java/de/rtuni/ms/apig/SecurityConfiguration.java
+21
-15
21 additions, 15 deletions
src/main/java/de/rtuni/ms/apig/SecurityConfiguration.java
with
21 additions
and
15 deletions
src/main/java/de/rtuni/ms/apig/SecurityConfiguration.java
+
21
−
15
View file @
623bc0c7
...
@@ -5,11 +5,8 @@
...
@@ -5,11 +5,8 @@
package
de.rtuni.ms.apig
;
package
de.rtuni.ms.apig
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.builders.HttpSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
import
org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
;
...
@@ -17,7 +14,7 @@ import org.springframework.security.config.http.SessionCreationPolicy;
...
@@ -17,7 +14,7 @@ import org.springframework.security.config.http.SessionCreationPolicy;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
import
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
;
/**
/**
* Class that
handles
security configuration.
* Class that
enables custom
security configuration.
*
*
* @author Julian
* @author Julian
*/
*/
...
@@ -25,32 +22,41 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
...
@@ -25,32 +22,41 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
public
class
SecurityConfiguration
extends
WebSecurityConfigurerAdapter
{
public
class
SecurityConfiguration
extends
WebSecurityConfigurerAdapter
{
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/** 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
;
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
/**
/**
* Overrides the default configuration.
* Overrides the default
security
configuration.
*/
*/
@Override
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
csrf
().
disable
()
http
.
csrf
().
disable
()
// make sure we use stateless session; session won't be used to store user's state.
// make sure we use stateless session; session won't be used to store user's state.
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
).
and
()
.
sessionManagement
().
sessionCreationPolicy
(
SessionCreationPolicy
.
STATELESS
).
and
()
// handle an authorized attempts
.
exceptionHandling
().
authenticationEntryPoint
(
// Add a filter to validate the tokens with every request.
(
req
,
rsp
,
e
)
->
rsp
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
)).
and
()
// Add a filter to validate the tokens with every request
.
addFilterAfter
(
new
JwtTokenAuthenticationFilter
(
jwtConfig
),
.
addFilterAfter
(
new
JwtTokenAuthenticationFilter
(
jwtConfig
),
UsernamePasswordAuthenticationFilter
.
class
)
UsernamePasswordAuthenticationFilter
.
class
)
// authorization requests config
.
authorizeRequests
()
.
authorizeRequests
()
// allow all who are accessing "auth" service
.
antMatchers
(
"/auth/**"
).
permitAll
()
.
antMatchers
(
HttpMethod
.
POST
,
jwtConfig
.
getUri
()).
permitAll
()
// Anyone who is trying to access the securedPage must be an ADMIN.
// must be an admin if trying to access secured page (authentication is also required)
// TODO can we change the path to /securedPage?
.
antMatchers
(
"/securedPage/**"
).
hasRole
(
"ADMIN"
);
.
antMatchers
(
"/securedPage/**"
).
hasRole
(
"ADMIN"
)
// Permit default path.
.
antMatchers
(
"/login"
).
permitAll
().
and
()
// Configures where to forward if authentication is required.
.
formLogin
().
loginPage
(
"/login"
)
// Configures url for processing of login data.
.
loginProcessingUrl
(
"process_login"
)
// TODO can we remove this?
// Configures where to go if there is no previous visited page.
.
defaultSuccessUrl
(
"/"
,
true
).
and
()
// Configures url for processing of logout.
.
logout
().
logoutUrl
(
"/process_logout"
)
.
deleteCookies
(
"JSESSIONID"
);
// TODO i think we can remove this
}
}
//----------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------
...
...
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