@Override public AccountData getAccount(ParticipantId id) { AccountData account = accounts.get(id); if (account == null && !id.getAddress().startsWith("xxx")) { account = new HumanAccountDataImpl(id, new PasswordDigest("".toCharArray())); accounts.put(id, account); } return account; }
public static boolean createAccountIfMissing(AccountStore accountStore, ParticipantId id, PasswordDigest password, WelcomeRobot welcomeBot) { HumanAccountDataImpl account = new HumanAccountDataImpl(id, password); try { LOG.info("Registering new account for" + id); accountStore.putAccount(account); } catch (PersistenceException e) { LOG.severe("Failed to cretaea new account for " + id, e); return false; } try { welcomeBot.greet(account.getId()); } catch (IOException e) { LOG.warning("Failed to create a welcome wavelet for " + id, e);; } return true; }
private static HumanAccountData deserialize(String account_id, ProtoHumanAccountData data) { ParticipantId id = ParticipantId.ofUnsafe(account_id); if (data.hasPasswordDigest()) { return new HumanAccountDataImpl(id, deserialize(data.getPasswordDigest())); } else { return new HumanAccountDataImpl(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); } } }
/** * 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 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); }
@Override protected void setUp() throws Exception { waveletProvider = new WaveletProviderStub(); AccountStore accountStore = new MemoryStore(); accountStore.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("fred@example.com"))); org.eclipse.jetty.server.SessionManager jettySessionManager = mock(org.eclipse.jetty.server.SessionManager.class); SessionManager sessionManager = new SessionManagerImpl(accountStore, jettySessionManager); session = mock(HttpSession.class); when(session.getAttribute(SessionManager.USER_FIELD)).thenReturn(ParticipantId.ofUnsafe("fred@example.com")); servlet = new FetchServlet(waveletProvider, protoSerializer, sessionManager); }
public void testUnregisterFailsOnHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.unregister(HUMAN_ID); fail(); } catch (RobotRegistrationException e) { // Expected. } }
public void testReRegisterFailsOnExistingHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.registerOrUpdate(HUMAN_ID, OTHER_LOCATION); fail(); } catch (RobotRegistrationException e) { // Expected. } }
public void testUserWithNoPasswordHasNoPasswordDigest() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("moist@example.com")); assertNull(account.getPasswordDigest()); } }
@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); AccountStore store = new MemoryStore(); account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("tubes@example.com")); store.putAccount(account); sessionManager = new SessionManagerImpl(store, jettySessionManager); }
public void testUserWithNoPasswordHasNoPasswordDigest() { HumanAccountData account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("moist@example.com")); assertNull(account.getPasswordDigest()); } }
public void testReRegisterFailsOnExistingHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.registerOrUpdate(HUMAN_ID, OTHER_LOCATION); fail(); } catch (RobotRegistrationException e) { // Expected. } }
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; }
@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); AccountStore store = new MemoryStore(); account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("tubes@example.com")); store.putAccount(account); sessionManager = new SessionManagerImpl(store, jettySessionManager); }
public void testUnregisterFailsOnHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.unregister(HUMAN_ID); fail(); } catch (RobotRegistrationException e) { // Expected. } }
@Override protected void setUp() throws Exception { AccountStore store = new MemoryStore(); store.putAccount(new HumanAccountDataImpl( ParticipantId.ofUnsafe("haspwd@example.com"), new PasswordDigest("pwd".toCharArray()))); store.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("nopwd@example.com"))); AccountStoreHolder.init(store, "example.com"); }
@Override protected void setUp() throws Exception { AccountStore store = new MemoryStore(); store.putAccount(new HumanAccountDataImpl( ParticipantId.ofUnsafe("haspwd@example.com"), new PasswordDigest("pwd".toCharArray()))); store.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("nopwd@example.com"))); AccountStoreHolder.init(store, "example.com"); }
@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); AccountStore store = new MemoryStore(); HumanAccountData account = new HumanAccountDataImpl(USER, new PasswordDigest("password".toCharArray())); store.putAccount(account); Config config = ConfigFactory.parseMap(ImmutableMap.<String, Object>of( "administration.disable_registration", false, "administration.analytics_account", "UA-someid", "security.enable_clientauth", false, "security.clientauth_cert_domain", "", "administration.disable_loginpage", false) ); servlet = new AuthenticationServlet(store, AuthTestUtil.makeConfiguration(), manager, "examPLe.com", config); AccountStoreHolder.init(store, "eXaMple.com"); when(session.getId()).thenReturn(""); }