Package com.googlecode.memwords.domain

Examples of com.googlecode.memwords.domain.Account


        try {
            tx.begin();
            Card card = new Card();
            card.setInitializationVector(cryptoEngine.generateInitializationVector());
            updateCard(card, cardDetails, encryptionKey, true);
            Account account = em.find(Account.class, userId);
            account.addCard(card);
            em.persist(card);
            tx.commit();
            return card;
        }
        finally {
View Full Code Here


        // Add and remove in two separate transactions because of a bug in datanucleus
        boolean mustRemove = false;
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            Account account = em.find(Account.class, userId);
            HistoricLogin historicLogin = new HistoricLogin(new Date(), userAgent, ip);
            historicLogin.setAccount(account);
            mustRemove = account.addHistoricLogin(historicLogin);
            tx.commit();
        }
        finally {
            if (tx.isActive()) {
                tx.rollback();
            }
        }

        if (mustRemove) {
            tx = em.getTransaction();
            try {
                tx.begin();
                Account account = em.find(Account.class, userId);
                account.removeOldHistoricLogins();
                tx.commit();
            }
            finally {
                if (tx.isActive()) {
                    tx.rollback();
View Full Code Here

        }
    }

    @Override
    public List<HistoricLogin> getLoginHistory(String userId) {
        Account account = em.find(Account.class, userId);
        return account.getHistoricLogins();
    }
View Full Code Here

        return account.getHistoricLogins();
    }

    @Override
    public HistoricLogin getLatestHistoricLogin(String userId) {
        Account account = em.find(Account.class, userId);
        List<HistoricLogin> logins = account.getHistoricLogins();
        if (logins.size() > 1) {
            return logins.get(1);
        }
        return null;
    }
View Full Code Here

        }
    }

    @Override
    public UserInformation login(String userId, String masterPassword) {
        Account account = getAccount(userId);
        if (account == null) {
            return null;
        }
        byte[] persistentPassword = buildPersistentPassword(userId, masterPassword);
        if (!Arrays.equals(persistentPassword, account.getMasterPassword())) {
            return null;
        }
        SecretKey wrappingKey = buildWrappingKey(userId, masterPassword);
        byte[] iv = cryptoEngine.buildInitializationVector(wrappingKey.getEncoded());
        byte[] encryptionKeyAsBytes = cryptoEngine.decrypt(account.getEncryptedSecretKey(),
                                                           wrappingKey,
                                                           iv);
        SecretKey secretKey = cryptoEngine.bytesToSecretKey(encryptionKeyAsBytes);
        return new UserInformation(account.getUserId(),
                                   secretKey,
                                   new Preferences(account.getPreferredLocale(),
                                                   account.getPreferredTimeZone(),
                                                   account.isPasswordsUnmasked(),
                                                   account.getPasswordGenerationPreferences()));
    }
View Full Code Here

                                                   account.getPasswordGenerationPreferences()));
    }

    @Override
    public boolean checkPassword(String userId, String masterPassword) {
        Account account = getAccount(userId);
        if (account == null) {
            return false;
        }
        byte[] persistentPassword = buildPersistentPassword(userId, masterPassword);
        return Arrays.equals(persistentPassword, account.getMasterPassword());
    }
View Full Code Here

        byte[] iv = cryptoEngine.buildInitializationVector(wrappingKey.getEncoded());
        byte[] encryptedSecretKey = cryptoEngine.encrypt(secretKey.getEncoded(), wrappingKey, iv);
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            Account account = getAccount(userId);
            account.setMasterPassword(persistentPassword);
            account.setEncryptedSecretKey(encryptedSecretKey);
            tx.commit();
        }
        finally {
            if (tx.isActive()) {
                tx.rollback();
View Full Code Here

    @Override
    public void changePreferences(String userId, Preferences preferences) {
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            Account account = getAccount(userId);
            account.setPreferredLocale(preferences.getLocale());
            account.setPreferredTimeZone(preferences.getTimeZone());
            account.setPasswordsUnmasked(preferences.isPasswordsUnmasked());
            account.setPasswordGenerationPreferences(preferences.getPasswordGenerationPreferences());
            tx.commit();
        }
        finally {
            if (tx.isActive()) {
                tx.rollback();
View Full Code Here

    @Override
    public void destroyAccount(String userId) {
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            Account account = getAccount(userId);

            for (Card card : account.getCards()) {
                em.remove(card);
            }

            em.remove(account);
            tx.commit();
View Full Code Here

                                                         wrappingKey,
                                                         iv);
        EntityTransaction tx = em.getTransaction();
        try {
            tx.begin();
            Account account = new Account(userId);
            account.setMasterPassword(persistentPassword);
            account.setEncryptedSecretKey(encryptedSecretKey);
            em.persist(account);
            tx.commit();
            return new UserInformation(account.getUserId(),
                                       secretKey,
                                       new Preferences(account.getPreferredLocale(),
                                                       account.getPreferredTimeZone(),
                                                       account.isPasswordsUnmasked(),
                                                       account.getPasswordGenerationPreferences()));
        }
        finally {
            if (tx.isActive()) {
                tx.rollback();
            }
View Full Code Here

TOP

Related Classes of com.googlecode.memwords.domain.Account

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.