@Override public String getUsername() { return account.getName(); }
public PermissionTarget asPermissionTarget() { return new PermissionTarget( PermissionTargetType.ACCOUNT, id(), getName(), getFullName() ); } }
@Override public Signature getCurrentSignature() { Account account = getCurrentAccount(); if (account != null) { return Signature.of(account.getName()); } else { return Signature.none(); } }
account -> contains(account.getName(), name) || contains(account.getFullName(), name) );
@Override public void saveAccount(Account account) { try { getNamedParameterJdbcTemplate().update( "UPDATE ACCOUNTS SET NAME = :name, FULLNAME = :fullName, EMAIL = :email " + "WHERE ID = :id", params("id", account.id()) .addValue("name", account.getName()) .addValue("fullName", account.getFullName()) .addValue("email", account.getEmail()) ); } catch (DuplicateKeyException ex) { throw new AccountNameAlreadyDefinedException(account.getName()); } }
public RunAsAdminAuthentication(Account account) { super(AuthorityUtils.createAuthorityList(SecurityRole.ADMINISTRATOR.name())); if (account == null) { this.account = RUNAS_ACCOUNT; } else { this.account = Account.of( account.getName(), account.getFullName(), account.getEmail(), SecurityRole.ADMINISTRATOR, account.getAuthenticationSource() ).withId(account.getId()); } }
@Override public Account newAccount(Account account) { try { int id = dbCreate( "INSERT INTO ACCOUNTS (NAME, FULLNAME, EMAIL, MODE, PASSWORD, ROLE) " + "VALUES (:name, :fullName, :email, :mode, :password, :role)", params("name", account.getName()) .addValue("fullName", account.getFullName()) .addValue("email", account.getEmail()) .addValue("mode", account.getAuthenticationSource().getId()) .addValue("password", "") .addValue("role", account.getRole().name()) ); return account.withId(ID.of(id)); } catch (DuplicateKeyException ex) { throw new AccountNameAlreadyDefinedException(account.getName()); } }
@Override public Account updateAccount(ID accountId, AccountInput input) { securityService.checkGlobalFunction(AccountManagement.class); // Gets the existing account Account account = getAccount(accountId); // Checks if default admin if (account.isDefaultAdmin() && !StringUtils.equals(account.getName(), input.getName())) { throw new AccountDefaultAdminCannotUpdateNameException(); } // Updates it account = account.update(input); // Saves it accountRepository.saveAccount(account); // Updating the password? if (StringUtils.isNotBlank(input.getPassword())) { accountRepository.setPassword(accountId.getValue(), passwordEncoder.encode(input.getPassword())); } // Account groups accountGroupRepository.linkAccountToGroups(account.id(), input.getGroups()); // OK return getAccount(accountId); }