parent
a58f3f0fe3
commit
843b16c1f0
|
@ -46,7 +46,7 @@ public class ProvisioningController {
|
||||||
{
|
{
|
||||||
rateLimiters.getMessagesLimiter().validate(source.getNumber());
|
rateLimiters.getMessagesLimiter().validate(source.getNumber());
|
||||||
|
|
||||||
if (!websocketSender.sendProvisioningMessage(new ProvisioningAddress(destinationName),
|
if (!websocketSender.sendProvisioningMessage(new ProvisioningAddress(destinationName, 0),
|
||||||
Base64.decode(message.getBody())))
|
Base64.decode(message.getBody())))
|
||||||
{
|
{
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
|
|
|
@ -7,15 +7,16 @@ import java.security.SecureRandom;
|
||||||
|
|
||||||
public class ProvisioningAddress extends WebsocketAddress {
|
public class ProvisioningAddress extends WebsocketAddress {
|
||||||
|
|
||||||
private final String address;
|
public ProvisioningAddress(String address, int id) throws InvalidWebsocketAddressException {
|
||||||
|
super(address, id);
|
||||||
|
}
|
||||||
|
|
||||||
public ProvisioningAddress(String address) throws InvalidWebsocketAddressException {
|
public ProvisioningAddress(String serialized) throws InvalidWebsocketAddressException {
|
||||||
super(address, 0);
|
super(serialized);
|
||||||
this.address = address;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
return address;
|
return getNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProvisioningAddress generate() {
|
public static ProvisioningAddress generate() {
|
||||||
|
@ -24,7 +25,7 @@ public class ProvisioningAddress extends WebsocketAddress {
|
||||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(random);
|
SecureRandom.getInstance("SHA1PRNG").nextBytes(random);
|
||||||
|
|
||||||
return new ProvisioningAddress(Base64.encodeBytesWithoutPadding(random)
|
return new ProvisioningAddress(Base64.encodeBytesWithoutPadding(random)
|
||||||
.replace('+', '-').replace('/', '_'));
|
.replace('+', '-').replace('/', '_'), 0);
|
||||||
} catch (NoSuchAlgorithmException | InvalidWebsocketAddressException e) {
|
} catch (NoSuchAlgorithmException | InvalidWebsocketAddressException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,16 @@ public class ProvisioningConnection implements DispatchChannel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDispatchSubscribed(String channel) {
|
public void onDispatchSubscribed(String channel) {
|
||||||
this.client.sendRequest("PUT", "/v1/address", Optional.of(ProvisioningUuid.newBuilder()
|
try {
|
||||||
.setUuid(channel)
|
ProvisioningAddress address = new ProvisioningAddress(channel);
|
||||||
.build()
|
this.client.sendRequest("PUT", "/v1/address", Optional.of(ProvisioningUuid.newBuilder()
|
||||||
.toByteArray()));
|
.setUuid(address.getAddress())
|
||||||
|
.build()
|
||||||
|
.toByteArray()));
|
||||||
|
} catch (InvalidWebsocketAddressException e) {
|
||||||
|
logger.warn("Badly formatted address", e);
|
||||||
|
this.client.close(1001, "Server Error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue