class FactorEnrollmentAPIController {

    @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public Factor enrollFactor(@RequestBody Factor enrollRequestDTO, Authentication auth)
            throws OktaException
    {
        Preconditions.checkNotNull(enrollRequestDTO, "enrollRequestDTO is null");
        Preconditions.checkNotNull(enrollRequestDTO.getFactorType(), "factor type is null");
        Preconditions.checkNotNull(enrollRequestDTO.getProvider(), "provider is null");

        try
        {
            LOGGER.info("Enrolling user [{}] in factor [{}]", auth.getName(), enrollRequestDTO.getFactorType().name());
            OktaUser user = getOktaUserService().getUser(auth.getName());
            return getFactorLifecycleService().enroll(enrollRequestDTO.getFactorType(),
                    enrollRequestDTO.getProvider(), enrollRequestDTO.getProfile(), user);
        }
        catch (Exception e)
        {
            LOGGER.error("Failed to enroll user [{}] in factor [{}]", auth.getName(), enrollRequestDTO.getFactorType().name(), e);
            throw new OktaException(e.getMessage(), e);
        }
    }

}