@Autowired public AuthenticationSourceServiceImpl(Collection<? extends AuthenticationSourceProvider> providers) { this.providers = Maps.uniqueIndex( providers, p -> p.getSource().getId() ); }
public static AuthenticationSource of(String id, String name) { return new AuthenticationSource(id, name, false); }
public AccountCall(String name, SecurityRole role) { this(Account.of(name, name, name + "@test.com", role, AuthenticationSource.none())); }
/** * Authentication source used for tests */ public static AuthenticationSource none() { return of("none", "Not defined"); } }
@Override public Ack changePassword(PasswordChange input) { // Checks the account Account account = securityService.getCurrentAccount(); if (account == null) { throw new AccessDeniedException("Must be logged to change password."); } else if (!account.getAuthenticationSource().isAllowingPasswordChange()) { throw new AccessDeniedException("Password change is not allowed from ontrack."); } else if (!accountRepository.checkPassword( account.id(), encodedPassword -> passwordEncoder.matches(input.getOldPassword(), encodedPassword) )) { throw new UserOldPasswordException(); } else { accountRepository.setPassword( account.id(), passwordEncoder.encode(input.getNewPassword()) ); return Ack.OK; } } }
@Override public Optional<Account> findUserByNameAndSource(String username, AuthenticationSourceProvider sourceProvider) { return Optional.ofNullable( getFirstItem( "SELECT * FROM ACCOUNTS WHERE MODE = :mode AND NAME = :name", params("name", username).addValue("mode", sourceProvider.getSource().getId()), (rs, rowNum) -> toAccount(rs, mode -> sourceProvider.getSource()) ) ); }
@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()); } }
.description("Source of authentication (builtin, ldap, etc.)") .type(GraphQLString) .dataFetcher(environment -> ((Account) environment.getSource()).getAuthenticationSource().getId()) .build()