@Override protected void contextSetup() { SecurityContext context = new SecurityContextImpl(); TestingAuthenticationToken authentication = new TestingAuthenticationToken( (AccountHolder) () -> account, "", account.getRole().name() ); context.setAuthentication(authentication); SecurityContextHolder.setContext(context); } }
@Override public Collection<? extends GrantedAuthority> getAuthorities() { return AuthorityUtils.createAuthorityList(account.getRole().getRoleName()); }
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()); } }