Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ARSnova Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
John Samuel Ako Deutesfeld
ARSnova Backend
Commits
a90b386b
There was an error fetching the commit references. Please try again later.
Commit
a90b386b
authored
7 years ago
by
Daniel Gerhardt
Browse files
Options
Downloads
Patches
Plain Diff
Catch unauthenticated WebSocket messages
parent
596a007b
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/thm/arsnova/websocket/WebsocketAuthenticationAspect.java
+11
-4
11 additions, 4 deletions
.../thm/arsnova/websocket/WebsocketAuthenticationAspect.java
with
11 additions
and
4 deletions
src/main/java/de/thm/arsnova/websocket/WebsocketAuthenticationAspect.java
+
11
−
4
View file @
a90b386b
...
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
...
@@ -28,6 +28,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Configurable
;
import
org.springframework.beans.factory.annotation.Configurable
;
import
org.springframework.security.access.AccessDeniedException
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.authentication.UsernamePasswordAuthenticationToken
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.Authentication
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
...
@@ -58,14 +59,20 @@ public class WebsocketAuthenticationAspect {
...
@@ -58,14 +59,20 @@ public class WebsocketAuthenticationAspect {
final
SocketIOClient
client
,
final
T
message
)
throws
Throwable
{
final
SocketIOClient
client
,
final
T
message
)
throws
Throwable
{
logger
.
debug
(
"Executing WebsocketAuthenticationAspect for onData event: Session Id: {}, Message Class: {}"
,
logger
.
debug
(
"Executing WebsocketAuthenticationAspect for onData event: Session Id: {}, Message Class: {}"
,
client
.
getSessionId
(),
message
.
getClass
());
client
.
getSessionId
(),
message
.
getClass
());
populateSecurityContext
(
client
.
getSessionId
());
try
{
pjp
.
proceed
();
populateSecurityContext
(
client
.
getSessionId
());
clearSecurityContext
();
pjp
.
proceed
();
}
finally
{
clearSecurityContext
();
}
}
}
private
void
populateSecurityContext
(
final
UUID
socketId
)
{
private
void
populateSecurityContext
(
final
UUID
socketId
)
{
SecurityContext
context
=
SecurityContextHolder
.
getContext
();
UserAuthentication
userAuth
=
userService
.
getUserToSocketId
(
socketId
);
UserAuthentication
userAuth
=
userService
.
getUserToSocketId
(
socketId
);
if
(
userAuth
==
null
)
{
throw
new
AccessDeniedException
(
"No user authenticated for WebSocket connection"
);
}
SecurityContext
context
=
SecurityContextHolder
.
getContext
();
Set
<
GrantedAuthority
>
authorities
=
new
HashSet
<>();
Set
<
GrantedAuthority
>
authorities
=
new
HashSet
<>();
authorities
.
add
(
WEBSOCKET_AUTHORITY
);
authorities
.
add
(
WEBSOCKET_AUTHORITY
);
User
user
=
new
User
(
userAuth
,
authorities
);
User
user
=
new
User
(
userAuth
,
authorities
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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