fix(gateway): let the public QR registration reach its backend calls
A visitor has no user token, so the gateway refused every call the public page makes. Open only the exact method and path pairs it needs, and replace the full user lookup with a yes/no activeAdminOf endpoint so no user record is exposed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
1a7c542f5e
commit
eff4899c0d
8 files changed
+329
-10
No files matched your search
+1
@@ -6,6 +6,7 @@ public class RestApiSystemServiceConstants {
|
||||
|
||||
public static final String API_REST_SYSTEM_USER_FIND_BY_USERNAME = "/user/findByUsername/{username}";
|
||||
public static final String API_REST_SYSTEM_USER_FIND_BY_ID = "/user/findById/{id}";
|
||||
public static final String API_REST_SYSTEM_USER_ACTIVE_ADMIN_OF = "/user/{id}/activeAdminOf/{companyId}";
|
||||
public static final String API_REST_SYSTEM_USER_FIND_BY_EMAIL = "/user/findByEmail/{email}";
|
||||
public static final String API_REST_SYSTEM_USER_FIND_BY_EMAIL_AND_ID_NOT = "/user/findByEmailAndIdNot/{email}/{id}";
|
||||
public static final String API_REST_SYSTEM_USER_FIND_BY_EMAIL_AND_COMPANY = "/user/findByEmailAndCompanyId/{email}";
|
||||
|
||||
+12
-1
@@ -14,6 +14,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDate;
|
||||
@@ -44,6 +45,7 @@ public class PublicRegistrationService {
|
||||
private static final long WINDOW_MINUTES = 10;
|
||||
|
||||
private static final ParameterizedTypeReference<CompanyEvent> EVENT = new ParameterizedTypeReference<>() {};
|
||||
private static final ParameterizedTypeReference<Boolean> BOOL = new ParameterizedTypeReference<>() {};
|
||||
private static final ParameterizedTypeReference<Map<String, Object>> MAP = new ParameterizedTypeReference<>() {};
|
||||
|
||||
private final RestTemplateCustomUtil rest;
|
||||
@@ -124,7 +126,16 @@ public class PublicRegistrationService {
|
||||
private Long salesperson(Map<String, Object> link, CompanyEvent e) {
|
||||
if (!(link.get("salespersonUserId") instanceof Number n)) return null;
|
||||
long id = n.longValue();
|
||||
return leads.teamIds(e.getUuid()).contains(id) && AdminEventLeadService.isActiveAdminOf(found(() -> leads.user(id)), e.getCompanyId()) ? id : null;
|
||||
return leads.teamIds(e.getUuid()).contains(id) && Boolean.TRUE.equals(activeAdminOf(id, e.getCompanyId())) ? id : null;
|
||||
}
|
||||
|
||||
/** The user record is closed to visitors, so ask the one yes/no endpoint. Any failure means "no salesperson", never a 500. */
|
||||
private Boolean activeAdminOf(long userId, Long companyId) {
|
||||
try {
|
||||
return rest.getForEntity(url(RestApiSystemServiceConstants.API_REST_SYSTEM_USER_ACTIVE_ADMIN_OF), BOOL, userId, companyId).getBody();
|
||||
} catch (RestClientException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Open open(String token) {
|
||||
|
||||
Reference in new issue
Block a user