class AuthUserRestAPIConfiguration {

	static UserDetails adoptUser(AuthUser entity) {
		UserBuilder builder = User.builder();
		builder.username(entity.getUserId());
		String hashedApiToken = entity.getHashedApiToken();
		builder.password(hashedApiToken);

		List<String> authorities = accumulateAuthorities(entity);

		builder.authorities(authorities.toArray(new String[authorities.size()]));

		/* when api token is empty or null then access is disabled */
		boolean disabled = hashedApiToken==null || hashedApiToken.isEmpty();
		builder.disabled(disabled);
		UserDetails details = builder.build();
		LOG.trace("User:{} has authorities: {}, entity:{}",entity.getUserId(), details.getAuthorities(),entity);
		return details;
	}

}