Support URL-safe Base64 encoding for directory tokens.
// FREEBIE
This commit is contained in:
parent
887f49760f
commit
080ae0985f
|
@ -74,7 +74,7 @@ public class DirectoryController {
|
||||||
rateLimiters.getContactsLimiter().validate(account.getNumber());
|
rateLimiters.getContactsLimiter().validate(account.getNumber());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Optional<ClientContact> contact = directory.get(Base64.decodeWithoutPadding(token));
|
Optional<ClientContact> contact = directory.get(decodeToken(token));
|
||||||
|
|
||||||
if (contact.isPresent()) return Response.ok().entity(contact.get()).build();
|
if (contact.isPresent()) return Response.ok().entity(contact.get()).build();
|
||||||
else return Response.status(404).build();
|
else return Response.status(404).build();
|
||||||
|
@ -100,7 +100,7 @@ public class DirectoryController {
|
||||||
List<byte[]> tokens = new LinkedList<>();
|
List<byte[]> tokens = new LinkedList<>();
|
||||||
|
|
||||||
for (String encodedContact : contacts.getContacts()) {
|
for (String encodedContact : contacts.getContacts()) {
|
||||||
tokens.add(Base64.decodeWithoutPadding(encodedContact));
|
tokens.add(decodeToken(encodedContact));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ClientContact> intersection = directory.get(tokens);
|
List<ClientContact> intersection = directory.get(tokens);
|
||||||
|
@ -110,4 +110,8 @@ public class DirectoryController {
|
||||||
throw new WebApplicationException(Response.status(400).build());
|
throw new WebApplicationException(Response.status(400).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] decodeToken(String encoded) throws IOException {
|
||||||
|
return Base64.decodeWithoutPadding(encoded.replace('-', '+').replace('_', '/'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue