@Override public void putAccount(AccountData account) { accounts.put(account.getId(), account); }
protected static HumanAccountData createHumanAccount(ParticipantId pid, String email, String avatarFileId, String locale) { HumanAccountData account = new HumanAccountDataImpl(pid); account.setAvatarFileId(avatarFileId); account.setEmail(email); account.setLocale(locale); return account; }
public void testUserAddressReturnsCorrectResult() { ParticipantId id = ParticipantId.ofUnsafe("drhorrible@example.com"); HumanAccountData account = new HumanAccountDataImpl(id); assertEquals(account.getId(), id); assertTrue(account.isHuman()); assertFalse(account.isRobot()); }
/** * Returns a new {@link RobotAccountData} updated with the new capabilities * using the given {@link RobotAccountData}. * * @param account The {@link RobotAccountData} to update the capabilities for. * @param activeApiUrl the url of the Active Robot API. * @throws CapabilityFetchException if the capabilities couldn't be retrieved * or parsed. */ public RobotAccountData fetchCapabilities(RobotAccountData account, String activeApiUrl) throws CapabilityFetchException { RobotCapabilitiesParser parser = new RobotCapabilitiesParser( account.getUrl() + Robot.CAPABILITIES_URL, connection, activeApiUrl); RobotCapabilities capabilities = new RobotCapabilities( parser.getCapabilities(), parser.getCapabilitiesHash(), parser.getProtocolVersion()); return new RobotAccountDataImpl(account.getId(), account.getUrl(), account.getConsumerSecret(), capabilities, account.isVerified()); } }
public void testPasswordDigestVerifies() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("captainhammer@example.com"), new PasswordDigest("wonderflownium".toCharArray())); assertNotNull(account.getPasswordDigest()); assertTrue(account.getPasswordDigest().verify("wonderflownium".toCharArray())); }
public final void testRoundtripHumanAccountWithPassword() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount( new HumanAccountDataImpl(HUMAN_ID, new PasswordDigest("internet".toCharArray()))); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertTrue(retrievedAccount.asHuman().getPasswordDigest().verify("internet".toCharArray())); }
private DBObject robotToObject(RobotAccountData account) { return new BasicDBObject() .append(ROBOT_URL_FIELD, account.getUrl()) .append(ROBOT_SECRET_FIELD, account.getConsumerSecret()) .append(ROBOT_CAPABILITIES_FIELD, capabilitiesToObject(account.getCapabilities())) .append(ROBOT_VERIFIED_FIELD, account.isVerified()); }
public void testUserWithNoPasswordHasNoPasswordDigest() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("moist@example.com")); assertNull(account.getPasswordDigest()); } }
private HumanAccountData objectToHuman(ParticipantId id, DBObject object) { PasswordDigest passwordDigest = null; DBObject digestObj = (DBObject) object.get(HUMAN_PASSWORD_FIELD); if (digestObj != null) { byte[] salt = (byte[]) digestObj.get(PASSWORD_SALT_FIELD); byte[] digest = (byte[]) digestObj.get(PASSWORD_DIGEST_FIELD); passwordDigest = PasswordDigest.from(salt, digest); } return new HumanAccountDataImpl(id, passwordDigest); }
/** * Executes operations in the given context. * * @param context the context to perform the operations in. * @param operations the operations to perform. * @param account the account for which to execute robot operations. */ private void executeOperations( OperationContext context, List<OperationRequest> operations, RobotAccountData account) { for (OperationRequest operation : operations) { // Get the operation of the author taking into account the proxying for // field. OperationUtil.executeOperation(operation, operationRegistry, context, account.getId()); } }
private AccountData objectToRobot(ParticipantId id, DBObject robot) { String url = (String) robot.get(ROBOT_URL_FIELD); String secret = (String) robot.get(ROBOT_SECRET_FIELD); RobotCapabilities capabilities = objectToCapabilities((DBObject) robot.get(ROBOT_CAPABILITIES_FIELD)); boolean verified = (Boolean) robot.get(ROBOT_VERIFIED_FIELD); return new RobotAccountDataImpl(id, url, secret, capabilities, verified); }
public void testUserAddressReturnsCorrectResult() { ParticipantId id = ParticipantId.ofUnsafe("drhorrible@example.com"); HumanAccountData account = new HumanAccountDataImpl(id); assertEquals(account.getId(), id); assertTrue(account.isHuman()); assertFalse(account.isRobot()); }
public void testPasswordDigestVerifies() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("captainhammer@example.com"), new PasswordDigest("wonderflownium".toCharArray())); assertNotNull(account.getPasswordDigest()); assertTrue(account.getPasswordDigest().verify("wonderflownium".toCharArray())); }
public final void testRoundtripHumanAccountWithPassword() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount( new HumanAccountDataImpl(HUMAN_ID, new PasswordDigest("internet".toCharArray()))); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertTrue(retrievedAccount.asHuman().getPasswordDigest().verify("internet".toCharArray())); }
public void testUserWithNoPasswordHasNoPasswordDigest() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("moist@example.com")); assertNull(account.getPasswordDigest()); } }
public final void testRoundtripHumanAccount() throws Exception { AccountStore accountStore = newAccountStore(); HumanAccountDataImpl account = new HumanAccountDataImpl(HUMAN_ID); accountStore.putAccount(account); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertEquals(account, retrievedAccount); }
@Override public void putAccount(AccountData account) { accountStore.put(account.getId(), account); }
/** * Removes the robot account and notifies the listeners. * @param existingAccount the account to remove * @throws PersistenceException if the persistence layer reports an error. */ private void removeRobotAccount(RobotAccountData existingAccount) throws PersistenceException { accountStore.removeAccount(existingAccount.getId()); for (Listener listener : listeners) { listener.onUnregistrationSuccess(existingAccount); } }
public final void testRoundtripHumanAccount() throws Exception { AccountStore accountStore = newAccountStore(); HumanAccountDataImpl account = new HumanAccountDataImpl(HUMAN_ID); accountStore.putAccount(account); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertEquals(account, retrievedAccount); }