@Transactional public void createAccount(Account user) throws UsernameAlreadyInUseException { try { jdbcTemplate.update( "insert into Account (firstName, lastName, username, password) values (?, ?, ?, ?)", user.getFirstName(), user.getLastName(), user.getUsername(), passwordEncoder.encodePassword(user.getPassword(), null)); } catch (DuplicateKeyException e) { throw new UsernameAlreadyInUseException(user.getUsername()); } }
@Test public void testCRUDAccount() { // Create Account account = new Account(); account.setGivenName("Anthony"); account.setSurname("Wolski"); account.setEmail("*****@*****.**"); account.setPassword("password"); account.setUsername("awolski"); accountService.createAccount(account); assertEquals(new Long(0), account.getVersion()); // Read Account found = accountService.getAccount(account.getId()); assertEquals("Anthony", found.getGivenName()); assertEquals("Wolski", found.getSurname()); assertEquals("*****@*****.**", found.getEmail()); assertEquals("password", found.getPassword()); assertEquals("awolski", found.getUsername()); assertEquals(new Long(0), account.getVersion()); // Update account.setMiddleName("Keith"); accountService.saveAccount(account); account = accountService.getAccount(account.getId()); assertEquals(new Long(1), account.getVersion()); // Delete String accountId = account.getId(); accountService.deleteAccountById(accountId); account = accountService.getAccount(accountId); assertNull(account); }
private User buildUserForAuthentication(Account account, List<GrantedAuthority> authorities) { return new User( account.getUsername(), account.getPassword(), account.isEnabled(), account.isAccountNonExpired(), account.isCredentialsNonExpired(), account.isAccountNonLocked(), authorities); }
public String getProposedNick() { if (conversation.getBookmark() != null && conversation.getBookmark().getNick() != null) { return conversation.getBookmark().getNick(); } else { if (!conversation.getContactJid().isBareJid()) { return conversation.getContactJid().getResourcepart(); } else { return account.getUsername(); } } }
/** Returns a String for a workername by workerid. */ public static String getWorkerName(int workerid) { if (workerid == 0) { return "TicketSystem"; } DBHelper db = DBHelperFactory.createDBHelper(); Account temp = db.retrieveAccount(workerid); String result = temp.getUsername(); db.close(); return result; }
public void putAccount(Account account) { Editor editor = mPreference.edit(); editor.putString(USERNAME_KEY, account.getUsername()); editor.putString(PASSWORD_KEY, account.getPassword()); editor.commit(); }
public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion, int newVersion) { // Update database to add the Paid Account flag. This was introduced in // DB version 3. if (oldVersion <= DatabaseVersionNumber.VERSION_1_0_0) { db.execSQL(QUERY_ADD_PAID_ACCOUNT_COLUM); } // Update database to create account content provider if (oldVersion <= DatabaseVersionNumber.VERSION_1_1_0) { // Rename old table db.execSQL(QUERY_RENAME_TABLE_OLD); db.execSQL(QUERY_TABLE_CREATE); db.execSQL(REPLICATE_ACCOUNT); db.execSQL(QUERY_DROP_TABLE_OLD); } // Migrate all accounts to Account Manager if (oldVersion < DatabaseVersionNumber.VERSION_1_5_0) { // List<Account> accounts = AccountProvider.retrieveAccounts(db); android.accounts.Account newAccount; String accountName; AccountManager mAccountManager = AccountManager.get(context); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); SyncContentManager syncManager = SyncContentManager.getInstance(context); for (Account account : accounts) { // Check Account Name accountName = AlfrescoAccountManager.getInstance(context) .createUniqueAccountName(account.getUsername()); newAccount = new android.accounts.Account(accountName, AlfrescoAccount.ACCOUNT_TYPE); Bundle b = new Bundle(); // Very important ! // We keep the same Account Id from previous version. // Used by the SyncService b.putString(AlfrescoAccount.ACCOUNT_ID, Long.toString(account.getId())); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_NAME, account.getDescription()); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_URL, account.getUrl()); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_USERNAME, account.getUsername()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_REPOSITORY_ID, account.getRepositoryId()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_REPOSITORY_TYPE_ID, String.valueOf(account.getTypeId())); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_IS_PAID_ACCOUNT, Boolean.toString(account.getIsPaidAccount())); BundleUtils.addIfNotEmpty(b, AlfrescoAccount.ACCOUNT_ACTIVATION, account.getActivation()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_ACCESS_TOKEN, account.getAccessToken()); BundleUtils.addIfNotEmpty( b, AlfrescoAccount.ACCOUNT_REFRESH_TOKEN, account.getRefreshToken()); // Time to create. if (mAccountManager.addAccountExplicitly(newAccount, account.getPassword(), b)) { // Let's define if sync automatically regarding previous // settings syncManager.setActivateSync( account.getId(), sharedPref.getBoolean(SYNCHRO_PREFIX + account.getId(), false)); sharedPref.edit().remove(SYNCHRO_PREFIX + account.getId()).apply(); } Log.i( "Migration", "Account " + account.getDescription() + "[" + account.getId() + "] has been migrated"); } // Delete old table db.execSQL(QUERY_DROP_TABLE); } }