fix/improve-rest-apis#67
Merged
Merged
Conversation
… handling and add authorization checks
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR tightens REST-side class resolution to an allowlist and improves SaaS account API responses/auth checks, while extending SimpleCache with map-like operations.
Changes:
- Add
put/putIfAbsentconvenience methods toSimpleCache. - Restrict
AbstractCrudServiceRestControllerentity class loading to classes discovered from CRUD view descriptors (allowlist). - Update SaaS
AccountApiControllerendpoints to returnResponseEntityand enforce authorization/same-account checks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| platform/core/commons/src/main/java/tools/dynamia/commons/SimpleCache.java | Adds map-style write APIs (put, putIfAbsent) to the cache. |
| platform/app/src/main/java/tools/dynamia/app/controllers/AbstractCrudServiceRestController.java | Introduces an allowlist cache for entity classes based on CRUD descriptors and blocks non-allowed classes. |
| extensions/saas/sources/core/src/main/java/tools/dynamia/modules/saas/controllers/AccountApiController.java | Adds authorization checks and switches responses to typed ResponseEntity payloads. |
| * @param value | ||
| */ | ||
| public void put(K key, V value) { | ||
| data.put(key, value); |
| */ | ||
| private final JsonMapper mapper = StringPojoParser.createJsonMapper(); | ||
|
|
||
| private SimpleCache<String, Class> allowedClasses = new SimpleCache<>(); |
Comment on lines
+174
to
183
| private void initAllowedClasses() { | ||
| if (allowedClasses == null || allowedClasses.isEmpty()) { | ||
| ViewDescriptorFactory viewDescriptorFactory = Containers.get().findObject(ViewDescriptorFactory.class); | ||
| if (viewDescriptorFactory != null) { | ||
| viewDescriptorFactory.findDescriptorsByType("crud").forEach(d -> { | ||
| var entityClass = d.getKey(); | ||
| allowedClasses.add(entityClass.getName(), entityClass); | ||
| }); | ||
| } | ||
| } |
| initAllowedClasses(); | ||
| Class entityClass = allowedClasses.get(className); | ||
| if (entityClass == null) { | ||
| throw new ValidationError("Class not allowed: " + className); |
Comment on lines
+175
to
+177
| public boolean isSameAccount(String uuid, HttpServletRequest request) { | ||
| var subdomain = HttpUtils.getSubdomain(request); | ||
| var currentAccount = service.getAccount(subdomain); |
Comment on lines
+167
to
+173
| public boolean isAuthorized(HttpServletRequest request) { | ||
| if (serviceAPI.getSystemAccountId().equals(serviceAPI.getCurrentAccountId())) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.