Auto refactor Only: s/Account/Device/g

This commit is contained in:
Matt Corallo
2014-01-11 10:56:29 -10:00
parent 5a837d4481
commit bd6cf10402
20 changed files with 217 additions and 298 deletions

View File

@@ -31,7 +31,7 @@ import org.whispersystems.textsecuregcm.entities.GcmRegistrationId;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.sms.SmsSender;
import org.whispersystems.textsecuregcm.sms.TwilioSmsSender;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.PendingAccountsManager;
import org.whispersystems.textsecuregcm.util.Util;
@@ -134,19 +134,19 @@ public class AccountController {
throw new WebApplicationException(Response.status(403).build());
}
Account account = new Account();
account.setNumber(number);
account.setAuthenticationCredentials(new AuthenticationCredentials(password));
account.setSignalingKey(accountAttributes.getSignalingKey());
account.setSupportsSms(accountAttributes.getSupportsSms());
account.setFetchesMessages(accountAttributes.getFetchesMessages());
account.setDeviceId(0);
Device device = new Device();
device.setNumber(number);
device.setAuthenticationCredentials(new AuthenticationCredentials(password));
device.setSignalingKey(accountAttributes.getSignalingKey());
device.setSupportsSms(accountAttributes.getSupportsSms());
device.setFetchesMessages(accountAttributes.getFetchesMessages());
device.setDeviceId(0);
accounts.createResetNumber(account);
accounts.createResetNumber(device);
pendingAccounts.remove(number);
logger.debug("Stored account...");
logger.debug("Stored device...");
} catch (InvalidAuthorizationHeaderException e) {
logger.info("Bad Authorization Header", e);
throw new WebApplicationException(Response.status(401).build());
@@ -159,36 +159,36 @@ public class AccountController {
@PUT
@Path("/gcm/")
@Consumes(MediaType.APPLICATION_JSON)
public void setGcmRegistrationId(@Auth Account account, @Valid GcmRegistrationId registrationId) {
account.setApnRegistrationId(null);
account.setGcmRegistrationId(registrationId.getGcmRegistrationId());
accounts.update(account);
public void setGcmRegistrationId(@Auth Device device, @Valid GcmRegistrationId registrationId) {
device.setApnRegistrationId(null);
device.setGcmRegistrationId(registrationId.getGcmRegistrationId());
accounts.update(device);
}
@Timed
@DELETE
@Path("/gcm/")
public void deleteGcmRegistrationId(@Auth Account account) {
account.setGcmRegistrationId(null);
accounts.update(account);
public void deleteGcmRegistrationId(@Auth Device device) {
device.setGcmRegistrationId(null);
accounts.update(device);
}
@Timed
@PUT
@Path("/apn/")
@Consumes(MediaType.APPLICATION_JSON)
public void setApnRegistrationId(@Auth Account account, @Valid ApnRegistrationId registrationId) {
account.setApnRegistrationId(registrationId.getApnRegistrationId());
account.setGcmRegistrationId(null);
accounts.update(account);
public void setApnRegistrationId(@Auth Device device, @Valid ApnRegistrationId registrationId) {
device.setApnRegistrationId(registrationId.getApnRegistrationId());
device.setGcmRegistrationId(null);
accounts.update(device);
}
@Timed
@DELETE
@Path("/apn/")
public void deleteApnRegistrationId(@Auth Account account) {
account.setApnRegistrationId(null);
accounts.update(account);
public void deleteApnRegistrationId(@Auth Device device) {
device.setApnRegistrationId(null);
accounts.update(device);
}
@Timed

View File

@@ -26,7 +26,7 @@ import org.whispersystems.textsecuregcm.entities.AttachmentUri;
import org.whispersystems.textsecuregcm.federation.FederatedClientManager;
import org.whispersystems.textsecuregcm.federation.NoSuchPeerException;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.util.Conversions;
import org.whispersystems.textsecuregcm.util.UrlSigner;
@@ -38,7 +38,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -65,8 +64,8 @@ public class AttachmentController {
@Timed
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response allocateAttachment(@Auth Account account) throws RateLimitExceededException {
rateLimiters.getAttachmentLimiter().validate(account.getNumber());
public Response allocateAttachment(@Auth Device device) throws RateLimitExceededException {
rateLimiters.getAttachmentLimiter().validate(device.getNumber());
long attachmentId = generateAttachmentId();
URL url = urlSigner.getPreSignedUrl(attachmentId, HttpMethod.PUT);
@@ -79,7 +78,7 @@ public class AttachmentController {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{attachmentId}")
public Response redirectToAttachment(@Auth Account account,
public Response redirectToAttachment(@Auth Device device,
@PathParam("attachmentId") long attachmentId,
@QueryParam("relay") String relay)
{

View File

@@ -27,7 +27,7 @@ import org.whispersystems.textsecuregcm.auth.AuthorizationHeader;
import org.whispersystems.textsecuregcm.auth.InvalidAuthorizationHeaderException;
import org.whispersystems.textsecuregcm.entities.AccountAttributes;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.PendingDevicesManager;
import org.whispersystems.textsecuregcm.util.VerificationCode;
@@ -66,14 +66,15 @@ public class DeviceController {
@Timed
@GET
@Path("/provisioning_code")
@Produces(MediaType.APPLICATION_JSON)
public VerificationCode createDeviceToken(@Auth Account account)
public VerificationCode createDeviceToken(@Auth Device device)
throws RateLimitExceededException
{
rateLimiters.getVerifyLimiter().validate(account.getNumber()); //TODO: New limiter?
rateLimiters.getVerifyLimiter().validate(device.getNumber()); //TODO: New limiter?
VerificationCode verificationCode = generateVerificationCode();
pendingDevices.store(account.getNumber(), verificationCode.getVerificationCode());
pendingDevices.store(device.getNumber(), verificationCode.getVerificationCode());
return verificationCode;
}
@@ -88,7 +89,7 @@ public class DeviceController {
@Valid AccountAttributes accountAttributes)
throws RateLimitExceededException
{
Account account;
Device device;
try {
AuthorizationHeader header = AuthorizationHeader.fromFullHeader(authorizationHeader);
String number = header.getNumber();
@@ -104,24 +105,24 @@ public class DeviceController {
throw new WebApplicationException(Response.status(403).build());
}
account = new Account();
account.setNumber(number);
account.setAuthenticationCredentials(new AuthenticationCredentials(password));
account.setSignalingKey(accountAttributes.getSignalingKey());
account.setSupportsSms(accountAttributes.getSupportsSms());
account.setFetchesMessages(accountAttributes.getFetchesMessages());
device = new Device();
device.setNumber(number);
device.setAuthenticationCredentials(new AuthenticationCredentials(password));
device.setSignalingKey(accountAttributes.getSignalingKey());
device.setSupportsSms(accountAttributes.getSupportsSms());
device.setFetchesMessages(accountAttributes.getFetchesMessages());
accounts.createAccountOnExistingNumber(account);
accounts.createAccountOnExistingNumber(device);
pendingDevices.remove(number);
logger.debug("Stored new device account...");
logger.debug("Stored new device device...");
} catch (InvalidAuthorizationHeaderException e) {
logger.info("Bad Authorization Header", e);
throw new WebApplicationException(Response.status(401).build());
}
return account.getDeviceId();
return device.getDeviceId();
}
@VisibleForTesting protected VerificationCode generateVerificationCode() {

View File

@@ -18,12 +18,11 @@ package org.whispersystems.textsecuregcm.controllers;
import com.google.common.base.Optional;
import com.yammer.dropwizard.auth.Auth;
import com.yammer.metrics.annotation.Metered;
import com.yammer.metrics.annotation.Timed;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.entities.ClientContact;
import org.whispersystems.textsecuregcm.entities.ClientContactTokens;
import org.whispersystems.textsecuregcm.entities.ClientContacts;
@@ -61,10 +60,10 @@ public class DirectoryController {
@GET
@Path("/{token}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTokenPresence(@Auth Account account, @PathParam("token") String token)
public Response getTokenPresence(@Auth Device device, @PathParam("token") String token)
throws RateLimitExceededException
{
rateLimiters.getContactsLimiter().validate(account.getNumber());
rateLimiters.getContactsLimiter().validate(device.getNumber());
try {
Optional<ClientContact> contact = directory.get(Base64.decodeWithoutPadding(token));
@@ -83,10 +82,10 @@ public class DirectoryController {
@Path("/tokens")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ClientContacts getContactIntersection(@Auth Account account, @Valid ClientContactTokens contacts)
public ClientContacts getContactIntersection(@Auth Device device, @Valid ClientContactTokens contacts)
throws RateLimitExceededException
{
rateLimiters.getContactsLimiter().validate(account.getNumber(), contacts.getContacts().size());
rateLimiters.getContactsLimiter().validate(device.getNumber(), contacts.getContacts().size());
try {
List<byte[]> tokens = new LinkedList<>();

View File

@@ -32,7 +32,7 @@ import org.whispersystems.textsecuregcm.entities.RelayMessage;
import org.whispersystems.textsecuregcm.entities.UnstructuredPreKeyList;
import org.whispersystems.textsecuregcm.federation.FederatedPeer;
import org.whispersystems.textsecuregcm.push.PushSender;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.Keys;
import org.whispersystems.textsecuregcm.util.Pair;
@@ -124,7 +124,7 @@ public class FederationController {
deviceIds.second().add(message.getDestinationDeviceId());
}
Map<Pair<String, Long>, Account> accountCache = new HashMap<>();
Map<Pair<String, Long>, Device> accountCache = new HashMap<>();
List<String> numbersMissingDevices = new LinkedList<>();
pushSender.fillLocalAccountsCache(destinations, accountCache, numbersMissingDevices);
@@ -132,15 +132,15 @@ public class FederationController {
List<String> failure = new LinkedList<>(numbersMissingDevices);
for (RelayMessage message : messages) {
Account account = accountCache.get(new Pair<>(message.getDestination(), message.getDestinationDeviceId()));
if (account == null)
Device device = accountCache.get(new Pair<>(message.getDestination(), message.getDestinationDeviceId()));
if (device == null)
continue;
OutgoingMessageSignal signal = OutgoingMessageSignal.parseFrom(message.getOutgoingMessageSignal())
.toBuilder()
.setRelay(peer.getName())
.build();
try {
pushSender.sendMessage(account, signal);
pushSender.sendMessage(device, signal);
} catch (NoSuchUserException e) {
logger.info("No such user", e);
failure.add(message.getDestination());
@@ -169,14 +169,14 @@ public class FederationController {
public ClientContacts getUserTokens(@Auth FederatedPeer peer,
@PathParam("offset") int offset)
{
List<Account> numberList = accounts.getAllMasterAccounts(offset, ACCOUNT_CHUNK_SIZE);
List<Device> numberList = accounts.getAllMasterAccounts(offset, ACCOUNT_CHUNK_SIZE);
List<ClientContact> clientContacts = new LinkedList<>();
for (Account account : numberList) {
byte[] token = Util.getContactToken(account.getNumber());
ClientContact clientContact = new ClientContact(token, null, account.getSupportsSms());
for (Device device : numberList) {
byte[] token = Util.getContactToken(device.getNumber());
ClientContact clientContact = new ClientContact(token, null, device.getSupportsSms());
if (!account.isActive())
if (!device.isActive())
clientContact.setInactive(true);
clientContacts.add(clientContact);

View File

@@ -27,7 +27,7 @@ import org.whispersystems.textsecuregcm.entities.UnstructuredPreKeyList;
import org.whispersystems.textsecuregcm.federation.FederatedClientManager;
import org.whispersystems.textsecuregcm.federation.NoSuchPeerException;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.storage.AccountsManager;
import org.whispersystems.textsecuregcm.storage.Keys;
@@ -66,13 +66,13 @@ public class KeysController {
@Timed
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void setKeys(@Auth Account account, @Valid PreKeyList preKeys) {
keys.store(account.getNumber(), account.getDeviceId(), preKeys.getLastResortKey(), preKeys.getKeys());
public void setKeys(@Auth Device device, @Valid PreKeyList preKeys) {
keys.store(device.getNumber(), device.getDeviceId(), preKeys.getLastResortKey(), preKeys.getKeys());
}
public List<PreKey> getKeys(Account account, String number, String relay) throws RateLimitExceededException
private List<PreKey> getKeys(Device device, String number, String relay) throws RateLimitExceededException
{
rateLimiters.getPreKeysLimiter().validate(account.getNumber() + "__" + number);
rateLimiters.getPreKeysLimiter().validate(device.getNumber() + "__" + number);
try {
UnstructuredPreKeyList keyList;
@@ -95,15 +95,15 @@ public class KeysController {
@GET
@Path("/{number}")
@Produces(MediaType.APPLICATION_JSON)
public Response get(@Auth Account account,
public Response get(@Auth Device device,
@PathParam("number") String number,
@QueryParam("multikeys") Optional<String> multikey,
@QueryParam("relay") String relay)
throws RateLimitExceededException
{
if (!multikey.isPresent())
return Response.ok(getKeys(account, number, relay).get(0)).type(MediaType.APPLICATION_JSON).build();
return Response.ok(getKeys(device, number, relay).get(0)).type(MediaType.APPLICATION_JSON).build();
else
return Response.ok(getKeys(account, number, relay)).type(MediaType.APPLICATION_JSON).build();
return Response.ok(getKeys(device, number, relay)).type(MediaType.APPLICATION_JSON).build();
}
}

View File

@@ -28,7 +28,7 @@ import com.yammer.metrics.core.Timer;
import com.yammer.metrics.core.TimerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
import org.whispersystems.textsecuregcm.auth.DeviceAuthenticator;
import org.whispersystems.textsecuregcm.auth.AuthorizationHeader;
import org.whispersystems.textsecuregcm.auth.InvalidAuthorizationHeaderException;
import org.whispersystems.textsecuregcm.entities.IncomingMessage;
@@ -41,7 +41,7 @@ import org.whispersystems.textsecuregcm.federation.FederatedClientManager;
import org.whispersystems.textsecuregcm.federation.NoSuchPeerException;
import org.whispersystems.textsecuregcm.limits.RateLimiters;
import org.whispersystems.textsecuregcm.push.PushSender;
import org.whispersystems.textsecuregcm.storage.Account;
import org.whispersystems.textsecuregcm.storage.Device;
import org.whispersystems.textsecuregcm.util.Base64;
import org.whispersystems.textsecuregcm.util.IterablePair;
import org.whispersystems.textsecuregcm.util.Pair;
@@ -74,19 +74,19 @@ public class MessageController extends HttpServlet {
private final Logger logger = LoggerFactory.getLogger(MessageController.class);
private final RateLimiters rateLimiters;
private final AccountAuthenticator accountAuthenticator;
private final DeviceAuthenticator deviceAuthenticator;
private final PushSender pushSender;
private final FederatedClientManager federatedClientManager;
private final ObjectMapper objectMapper;
private final ExecutorService executor;
public MessageController(RateLimiters rateLimiters,
AccountAuthenticator accountAuthenticator,
DeviceAuthenticator deviceAuthenticator,
PushSender pushSender,
FederatedClientManager federatedClientManager)
{
this.rateLimiters = rateLimiters;
this.accountAuthenticator = accountAuthenticator;
this.deviceAuthenticator = deviceAuthenticator;
this.pushSender = pushSender;
this.federatedClientManager = federatedClientManager;
this.objectMapper = new ObjectMapper();
@@ -98,13 +98,13 @@ public class MessageController extends HttpServlet {
TimerContext timerContext = timer.time();
try {
Account sender = authenticate(req);
Device sender = authenticate(req);
IncomingMessageList messages = parseIncomingMessages(req);
rateLimiters.getMessagesLimiter().validate(sender.getNumber());
Map<Pair<String, Long>, Account> accountCache = new HashMap<>();
Map<Pair<String, Long>, Device> accountCache = new HashMap<>();
List<String> numbersMissingDevices = new LinkedList<>();
List<IncomingMessage> incomingMessages = messages.getMessages();
@@ -140,7 +140,7 @@ public class MessageController extends HttpServlet {
private void handleAsyncDelivery(final TimerContext timerContext,
final AsyncContext context,
final IterablePair<IncomingMessage, OutgoingMessageSignal> listPair,
final Map<Pair<String, Long>, Account> accountCache,
final Map<Pair<String, Long>, Device> accountCache,
final List<String> numbersMissingDevices)
{
executor.submit(new Runnable() {
@@ -223,7 +223,7 @@ public class MessageController extends HttpServlet {
@Nullable
private List<OutgoingMessageSignal> getOutgoingMessageSignals(String sourceNumber,
List<IncomingMessage> incomingMessages,
Map<Pair<String, Long>, Account> accountCache,
Map<Pair<String, Long>, Device> accountCache,
List<String> numbersMissingDevices)
{
List<OutgoingMessageSignal> outgoingMessages = new LinkedList<>();
@@ -310,13 +310,13 @@ public class MessageController extends HttpServlet {
return messages;
}
private Account authenticate(HttpServletRequest request) throws AuthenticationException {
private Device authenticate(HttpServletRequest request) throws AuthenticationException {
try {
AuthorizationHeader authorizationHeader = AuthorizationHeader.fromFullHeader(request.getHeader("Authorization"));
BasicCredentials credentials = new BasicCredentials(authorizationHeader.getNumber() + "." + authorizationHeader.getDeviceId(),
authorizationHeader.getPassword() );
Optional<Account> account = accountAuthenticator.authenticate(credentials);
Optional<Device> account = deviceAuthenticator.authenticate(credentials);
if (account.isPresent()) return account.get();
else throw new AuthenticationException("Bad credentials");
@@ -332,7 +332,7 @@ public class MessageController extends HttpServlet {
// @POST
// @Consumes(MediaType.APPLICATION_JSON)
// @Produces(MediaType.APPLICATION_JSON)
// public MessageResponse sendMessage(@Auth Account sender, IncomingMessageList messages)
// public MessageResponse sendMessage(@Auth Device sender, IncomingMessageList messages)
// throws IOException
// {
// List<String> success = new LinkedList<>();