Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ spring.redis.host=@env.REDIS_HOST@

# Stop TB: when true, beneficiary registration fails with an error if camp (vanID) is not configured
stoptb.enforce.vanid=@env.STOPTB_ENFORCE_VANID@
# Stop TB: this deployment's van/camp ID, replacing the old Redis camp:vanID lookup
stoptb.van.id=@env.STOPTB_VAN_ID@
jwt.secret=@env.JWT_SECRET_KEY@


Expand Down
2 changes: 2 additions & 0 deletions src/main/environment/common_docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ spring.redis.host=${REDIS_HOST}

# Stop TB: when true, beneficiary registration fails with an error if camp (vanID) is not configured
stoptb.enforce.vanid=${STOPTB_ENFORCE_VANID}
# Stop TB: this deployment's van/camp ID, replacing the old Redis camp:vanID lookup
stoptb.van.id=${STOPTB_VAN_ID}
jwt.secret=${JWT_SECRET_KEY}

#ELK logging file name
Expand Down
2 changes: 2 additions & 0 deletions src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ spring.redis.host=localhost
# Stop TB: when true, beneficiary registration fails with an error if camp (vanID)
# is not configured instead of silently registering without it
stoptb.enforce.vanid=false
# Stop TB: this deployment's van/camp ID, replacing the old Redis camp:vanID lookup
stoptb.van.id=0

jwt.secret=my-32-character-ultra-secure-and-ultra-long-secret
logging.path=logs/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -114,8 +112,15 @@ public class RegistrarServiceImpl implements RegistrarService {
@Autowired
private CookieUtil cookieUtil;

@Autowired
private LettuceConnectionFactory redisConnectionFactory;
// This deployment's van/camp ID. Previously looked up from Redis ("camp:vanID"),
// written at MMU login and deleted (globally, unscoped) on ANY user's logout β€” a Redis
// outage or an unrelated user's logout would silently break registration on this camp.
// Each camp/van already runs its own dedicated backend instance, so which van this is
// never actually changes at runtime; reading it from properties removes the Redis
// dependency entirely. No inline default β€” every properties file must set this
// explicitly. Scope: vanID only, parkingPlaceID is not part of this change.
@Value("${stoptb.van.id}")
private int vanID;

// When true, beneficiary registration fails loudly if camp is not configured
// instead of silently registering with vanID unset. No inline default β€” every
Expand Down Expand Up @@ -671,26 +676,16 @@ public String registerBeneficiary(String comingRequest, String Authorization) th
Long beneficiaryID = null;
Map<String, Object> responseMap = new HashMap<>();

// Inject correct vanID from Redis (mobile sends vanID=0 as placeholder)
byte[] vanIDBytes = null;
byte[] ppIDBytes = null;
try {
RedisConnection conn = redisConnectionFactory.getConnection();
vanIDBytes = conn.get("camp:vanID".getBytes());
ppIDBytes = conn.get("camp:parkingPlaceID".getBytes());
conn.close();
} catch (Exception e) {
logger.warn("Camp vanID lookup failed: " + e.getMessage());
}
if (vanIDBytes != null) {
// Inject configured vanID (mobile sends vanID=0 as placeholder). Previously looked
// up from Redis at request time; now a fixed property of this deployment (see
// vanID field javadoc above).
if (vanID > 0) {
JSONObject reqJson = new JSONObject(comingRequest);
reqJson.put("vanID", Integer.parseInt(new String(vanIDBytes)));
if (ppIDBytes != null)
reqJson.put("parkingPlaceID", Integer.parseInt(new String(ppIDBytes)));
reqJson.put("vanID", vanID);
comingRequest = reqJson.toString();
} else if (enforceVanID) {
throw new Exception(
"Camp not configured: vanID missing. Please select van/service point in MMU before registering beneficiary.");
"Camp not configured: stoptb.van.id is 0. Set stoptb.van.id in this deployment's properties file.");
}

RestTemplate restTemplate = new RestTemplate();
Expand Down
Loading