/** * Creates a new user. * * @param accountStore the account store with user accounts. * @param participantId requested user wave address. * @param password requested user password * @throws PersistenceException if the persistence layer fails. * @throws IllegalArgumentException if the userId is already in use. */ public static void createUser(AccountStore accountStore, ParticipantId participantId, String password) throws PersistenceException, IllegalArgumentException { if (accountStore.getAccount(participantId) != null) { throw new IllegalArgumentException(String.format("User %s already exists on this domain.", participantId.getAddress())); } HumanAccountDataImpl account = new HumanAccountDataImpl(participantId, new PasswordDigest(password.toCharArray())); accountStore.putAccount(account); } }
/** * Changes the user password. * * @param newPassword the new password of the user. * @param participantId the user wave address. * @param accountStore the account store with user accounts. * @throws PersistenceException if the persistence layer fails. * @throws IllegalArgumentException if the user doesn't exist. */ public static void changeUserPassword(String newPassword, ParticipantId participantId, AccountStore accountStore) throws PersistenceException, IllegalArgumentException { PasswordDigest newPasswordDigest = new PasswordDigest(newPassword.toCharArray()); HumanAccountDataImpl account = new HumanAccountDataImpl(participantId, newPasswordDigest); if (accountStore.getAccount(participantId) != null) { accountStore.removeAccount(participantId); accountStore.putAccount(account); } else { throw new IllegalArgumentException(String.format("User %s does not exist on this domain.", participantId.getAddress())); } }
private static void initializeServer(Injector injector, String waveDomain) throws PersistenceException, WaveServerException { AccountStore accountStore = injector.getInstance(AccountStore.class); accountStore.initializeAccountStore(); AccountStoreHolder.init(accountStore, waveDomain); // Initialize the SignerInfoStore. CertPathStore certPathStore = injector.getInstance(CertPathStore.class); if (certPathStore instanceof SignerInfoStore) { ((SignerInfoStore)certPathStore).initializeSignerInfoStore(); } // Initialize the server. WaveletProvider waveServer = injector.getInstance(WaveletProvider.class); waveServer.initialize(); }
public void testUnregisterSucceeds() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertTrue(unregisteredAccountData.equals(accountData)); verify(accountData).isRobot(); verify(accountStore).removeAccount(ROBOT_ID); }
public static boolean doesAccountExist(AccountStore accountStore, ParticipantId id) { try { if (accountStore.getAccount(id) != null) { return true; } } catch (PersistenceException e) { LOG.severe("Failed to retrieve account data for " + id, e); throw new RuntimeException("An unexpected error occurred trying to retrieve account status"); } return false; } }
@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); store = new MemoryStore(); store.putAccount(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); } }
@Override public RobotAccountData registerNew(ParticipantId robotId, String location) throws RobotRegistrationException, PersistenceException { Preconditions.checkNotNull(robotId); Preconditions.checkNotNull(location); Preconditions.checkArgument(!location.isEmpty()); if (accountStore.getAccount(robotId) != null) { throw new RobotRegistrationException(robotId.getAddress() + " is already in use, please choose another one."); } return registerRobot(robotId, location); }
@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); store = new MemoryStore(); store.putAccount(account); }
public void testUnregisterSucceeds() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertTrue(unregisteredAccountData.equals(accountData)); verify(accountData).isRobot(); verify(accountStore).removeAccount(ROBOT_ID); }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { try { ParticipantId participant = sessionManager.getLoggedInUser(req.getSession(false)); if (participant == null) { resp.setStatus(HttpServletResponse.SC_FORBIDDEN); return; } String locale = URLDecoder.decode(req.getParameter("locale"), "UTF-8"); AccountData account = accountStore.getAccount(participant); HumanAccountData humanAccount; if (account != null) { humanAccount = account.asHuman(); } else { humanAccount = new HumanAccountDataImpl(participant); } humanAccount.setLocale(locale); accountStore.putAccount(humanAccount); } catch (PersistenceException ex) { throw new IOException(ex); } } }
public final void testRemoveAccount() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.removeAccount(ROBOT_ID); assertNull("Removed account was not null", accountStore.getAccount(ROBOT_ID)); } }
@Override public AccountData getLoggedInAccount(HttpSession session) { // Consider caching the account data in the session object. ParticipantId user = getLoggedInUser(session); if (user != null) { try { return accountStore.getAccount(user); } catch (PersistenceException e) { LOG.warning("Failed to retrieve account data for " + user, e); return null; } } else { return null; } }
public void testReRegisterSucceedsOnNonExistingAccount() throws PersistenceException, RobotRegistrationException { registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).putAccount(any(RobotAccountData.class)); } }
public final void testPutAccountOverrides() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.putAccount(updatedRobotAccount); AccountData updatedAccount = accountStore.getAccount(ROBOT_ID); assertEquals(updatedRobotAccount, updatedAccount); }
public final void testRemoveAccount() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.removeAccount(ROBOT_ID); assertNull("Removed account was not null", accountStore.getAccount(ROBOT_ID)); } }
@Override public RobotAccountData unregister(ParticipantId robotId) throws RobotRegistrationException, PersistenceException { Preconditions.checkNotNull(robotId); AccountData accountData = accountStore.getAccount(robotId); if (accountData == null) { return null; } throwExceptionIfNotRobot(accountData); RobotAccountData robotAccount = accountData.asRobot(); removeRobotAccount(robotAccount); return robotAccount; }
public void testReRegisterSucceedsOnNonExistingAccount() throws PersistenceException, RobotRegistrationException { registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).putAccount(any(RobotAccountData.class)); } }
public final void testPutAccountCanChangeType() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.putAccount(convertedRobot); AccountData updatedAccount = accountStore.getAccount(ROBOT_ID); assertEquals(convertedRobot, updatedAccount); }
public void testReRegisterSucceedsOnExistingRobotAccount() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).removeAccount(ROBOT_ID); verify(accountStore).putAccount(any(RobotAccountData.class)); assertTrue(unregisteredAccountData.isRobot()); RobotAccountData robotAccountData = unregisteredAccountData.asRobot(); // Remove the last '/'. assertEquals(OTHER_LOCATION.substring(0, OTHER_LOCATION.length() - 1), robotAccountData.getUrl()); assertEquals(ROBOT_ID, robotAccountData.getId()); assertEquals(CONSUMER_TOKEN, robotAccountData.getConsumerSecret()); }