Skip to content

Commit 4d302c6

Browse files
authored
Add another way of checking if client has access to user in UserAccessGuard (#940)
1 parent 7a9b089 commit 4d302c6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

app/src/main/java/it/chalmers/gamma/app/authentication/UserAccessGuard.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import it.chalmers.gamma.app.apikey.domain.ApiKeyType;
44
import it.chalmers.gamma.app.client.domain.ClientRepository;
5+
import it.chalmers.gamma.app.client.domain.ClientUid;
56
import it.chalmers.gamma.app.user.domain.UserId;
67
import it.chalmers.gamma.bootstrap.BootstrapAuthenticated;
78
import it.chalmers.gamma.security.authentication.ApiAuthentication;
@@ -100,7 +101,7 @@ public boolean haveAccessToUser(UserId userId, boolean userLocked) {
100101
return true;
101102
}
102103

103-
LOGGER.debug("tried to access the user: {}; ", userId);
104+
LOGGER.info("tried to access the user: {}; ", userId);
104105

105106
// Return false by default
106107
return false;
@@ -131,6 +132,19 @@ private boolean haveAcceptedClient(UserId userId) {
131132
}
132133
}
133134

135+
if (SecurityContextHolder.getContext().getAuthentication()
136+
instanceof OAuth2ClientAuthenticationToken token) {
137+
var client = token.getRegisteredClient();
138+
139+
if (client == null) {
140+
return false;
141+
}
142+
143+
var clientUid = ClientUid.valueOf(client.getId());
144+
145+
return clientRepository.isApprovedByUser(userId, clientUid);
146+
}
147+
134148
return false;
135149
}
136150

0 commit comments

Comments
 (0)