Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GMS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
IA2
GMS
Commits
e812c2c9
Commit
e812c2c9
authored
5 years ago
by
Sonia Zorba
Browse files
Options
Downloads
Patches
Plain Diff
Fixed ISE in LoggingDAO when called from JWTFilter
parent
ef9122a2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
gms/src/main/java/it/inaf/ia2/gms/authn/JWTFilter.java
+4
-4
4 additions, 4 deletions
gms/src/main/java/it/inaf/ia2/gms/authn/JWTFilter.java
gms/src/main/java/it/inaf/ia2/gms/persistence/LoggingDAO.java
+9
-5
9 additions, 5 deletions
...src/main/java/it/inaf/ia2/gms/persistence/LoggingDAO.java
with
13 additions
and
9 deletions
gms/src/main/java/it/inaf/ia2/gms/authn/JWTFilter.java
+
4
−
4
View file @
e812c2c9
...
@@ -33,7 +33,7 @@ public class JWTFilter implements Filter {
...
@@ -33,7 +33,7 @@ public class JWTFilter implements Filter {
String
authHeader
=
request
.
getHeader
(
"Authorization"
);
String
authHeader
=
request
.
getHeader
(
"Authorization"
);
if
(
authHeader
==
null
)
{
if
(
authHeader
==
null
)
{
loggingDAO
.
logAction
(
"Attempt to access WS without token"
);
loggingDAO
.
logAction
(
"Attempt to access WS without token"
,
request
);
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"Missing Authorization token"
);
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"Missing Authorization token"
);
return
;
return
;
}
}
...
@@ -42,7 +42,7 @@ public class JWTFilter implements Filter {
...
@@ -42,7 +42,7 @@ public class JWTFilter implements Filter {
OAuth2AccessToken
accessToken
=
jwkTokenStore
.
readAccessToken
(
authHeader
);
OAuth2AccessToken
accessToken
=
jwkTokenStore
.
readAccessToken
(
authHeader
);
if
(
accessToken
.
isExpired
())
{
if
(
accessToken
.
isExpired
())
{
loggingDAO
.
logAction
(
"Attempt to access WS with expired token"
);
loggingDAO
.
logAction
(
"Attempt to access WS with expired token"
,
request
);
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"Access token is expired"
);
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"Access token is expired"
);
return
;
return
;
}
}
...
@@ -50,13 +50,13 @@ public class JWTFilter implements Filter {
...
@@ -50,13 +50,13 @@ public class JWTFilter implements Filter {
Map
<
String
,
Object
>
claims
=
accessToken
.
getAdditionalInformation
();
Map
<
String
,
Object
>
claims
=
accessToken
.
getAdditionalInformation
();
if
(
claims
.
get
(
"sub"
)
==
null
)
{
if
(
claims
.
get
(
"sub"
)
==
null
)
{
loggingDAO
.
logAction
(
"Attempt to access WS with invalid token"
);
loggingDAO
.
logAction
(
"Attempt to access WS with invalid token"
,
request
);
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"Invalid access token: missing sub claim"
);
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"Invalid access token: missing sub claim"
);
return
;
return
;
}
}
ServletRequestWithJWTPrincipal
wrappedRequest
=
new
ServletRequestWithJWTPrincipal
(
request
,
claims
);
ServletRequestWithJWTPrincipal
wrappedRequest
=
new
ServletRequestWithJWTPrincipal
(
request
,
claims
);
loggingDAO
.
logAction
(
"WS access from "
+
wrappedRequest
.
getUserPrincipal
().
getName
());
loggingDAO
.
logAction
(
"WS access from "
+
wrappedRequest
.
getUserPrincipal
().
getName
()
,
request
);
fc
.
doFilter
(
wrappedRequest
,
res
);
fc
.
doFilter
(
wrappedRequest
,
res
);
}
}
...
...
This diff is collapsed.
Click to expand it.
gms/src/main/java/it/inaf/ia2/gms/persistence/LoggingDAO.java
+
9
−
5
View file @
e812c2c9
...
@@ -18,7 +18,7 @@ public class LoggingDAO {
...
@@ -18,7 +18,7 @@ public class LoggingDAO {
private
final
JdbcTemplate
jdbcTemplate
;
private
final
JdbcTemplate
jdbcTemplate
;
@Autowired
@Autowired
(
required
=
false
)
private
HttpServletRequest
request
;
private
HttpServletRequest
request
;
@Autowired
@Autowired
...
@@ -53,15 +53,19 @@ public class LoggingDAO {
...
@@ -53,15 +53,19 @@ public class LoggingDAO {
}
}
public
void
logAction
(
String
action
)
{
public
void
logAction
(
String
action
)
{
logAction
(
action
,
request
);
}
public
void
logAction
(
String
action
,
HttpServletRequest
request
)
{
try
{
try
{
String
sql
=
"INSERT INTO audit_log (\"user\", action, ip_address) VALUES (?, ?, ?)"
;
String
sql
=
"INSERT INTO audit_log (\"user\", action, ip_address) VALUES (?, ?, ?)"
;
jdbcTemplate
.
update
(
conn
->
{
jdbcTemplate
.
update
(
conn
->
{
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
);
PreparedStatement
ps
=
conn
.
prepareStatement
(
sql
);
int
i
=
0
;
int
i
=
0
;
ps
.
setString
(++
i
,
getUser
());
ps
.
setString
(++
i
,
getUser
(
request
));
ps
.
setString
(++
i
,
action
);
ps
.
setString
(++
i
,
action
);
ps
.
setString
(++
i
,
getIPAddress
());
ps
.
setString
(++
i
,
getIPAddress
(
request
));
return
ps
;
return
ps
;
});
});
}
catch
(
Throwable
t
)
{
}
catch
(
Throwable
t
)
{
...
@@ -69,7 +73,7 @@ public class LoggingDAO {
...
@@ -69,7 +73,7 @@ public class LoggingDAO {
}
}
}
}
private
String
getIPAddress
()
{
private
String
getIPAddress
(
HttpServletRequest
request
)
{
String
ipAddress
=
request
.
getHeader
(
"X-FORWARDED-FOR"
);
String
ipAddress
=
request
.
getHeader
(
"X-FORWARDED-FOR"
);
if
(
ipAddress
==
null
)
{
if
(
ipAddress
==
null
)
{
return
request
.
getRemoteAddr
();
return
request
.
getRemoteAddr
();
...
@@ -78,7 +82,7 @@ public class LoggingDAO {
...
@@ -78,7 +82,7 @@ public class LoggingDAO {
}
}
}
}
private
String
getUser
()
{
private
String
getUser
(
HttpServletRequest
request
)
{
if
(
request
.
getUserPrincipal
()
!=
null
)
{
if
(
request
.
getUserPrincipal
()
!=
null
)
{
return
request
.
getUserPrincipal
().
getName
();
return
request
.
getUserPrincipal
().
getName
();
}
}
...
...
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