@Test public void enrollTest() throws OktaException { ResponseEntity<Factor> responseEntity = new ResponseEntity<>(expectedFactor, HttpStatus.OK); String expectedRequestBody = "{\"provider\":\"OKTA\",\"profile\":{\"email\":\"test@armedia.com\"},\"factorType\":\"email\"}"; expect(mockOktaRestService.doRestCall("/api/v1/users/" + expectedUser.getId() + "/factors?activate=true", HttpMethod.POST, Factor.class, expectedRequestBody)).andReturn(responseEntity); replayAll(); Factor factor = unit.enroll(expectedFactor.getFactorType(), expectedFactor.getProvider(), expectedProfile, expectedUser); verifyAll(); assertNotNull(factor); assertEquals(expectedFactor.getId(), factor.getId()); assertEquals(expectedFactor.getFactorType(), factor.getFactorType()); assertEquals(expectedFactor.getProvider(), factor.getProvider()); FactorProfile profile = factor.getProfile(); assertNotNull(profile); assertEquals(expectedProfile.getEmail(), profile.getEmail()); }
@Override public Factor enroll(FactorType factorType, ProviderType provider, FactorProfile profile, OktaUser user) throws OktaException { Preconditions.checkNotNull(factorType, "factorType is null"); Preconditions.checkNotNull(provider, "provider is null"); if (user != null) { String apiPath = buildEnrollmentPath(factorType, user); JSONObject body = new JSONObject(); body.put(OktaAPIConstants.FACTOR_TYPE, factorType.getFactorType()); body.put(OktaAPIConstants.PROVIDER, provider.name()); JSONObject enrollProfile = buildEnrollmentProfile(factorType, profile); if (enrollProfile != null && enrollProfile.length() > 0) { body.put(OktaAPIConstants.PROFILE, enrollProfile); } ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { LOGGER.debug("Failed to enroll factor [{}, {}]", ErrorResponse.class.cast(exchange.getBody()).getErrorSummary(), ErrorResponse.class.cast(exchange.getBody()).getErrorId()); throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }
FactorLifecycleServiceImpl implements FactorLifecycleService { @Override public Factor enroll(FactorType factorType, ProviderType provider, FactorProfile profile, OktaUser user) throws OktaException { Preconditions.checkNotNull(factorType, "factorType is null"); Preconditions.checkNotNull(provider, "provider is null"); if (user != null) { String apiPath = buildEnrollmentPath(factorType, user); JSONObject body = new JSONObject(); body.put(OktaAPIConstants.FACTOR_TYPE, factorType.getFactorType()); body.put(OktaAPIConstants.PROVIDER, provider.name()); JSONObject enrollProfile = buildEnrollmentProfile(factorType, profile); if (enrollProfile != null && enrollProfile.length() > 0) { body.put(OktaAPIConstants.PROFILE, enrollProfile); } ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { LOGGER.debug("Failed to enroll factor [{}, {}]", ErrorResponse.class.cast(exchange.getBody()).getErrorSummary(), ErrorResponse.class.cast(exchange.getBody()).getErrorId()); throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; } }
FactorLifecycleServiceImpl implements FactorLifecycleService { @Override public Factor enroll(FactorType factorType, ProviderType provider, FactorProfile profile, OktaUser user) throws OktaException { Preconditions.checkNotNull(factorType, "factorType is null"); Preconditions.checkNotNull(provider, "provider is null"); if (user != null) { String apiPath = buildEnrollmentPath(factorType, user); JSONObject body = new JSONObject(); body.put(OktaAPIConstants.FACTOR_TYPE, factorType.getFactorType()); body.put(OktaAPIConstants.PROVIDER, provider.name()); JSONObject enrollProfile = buildEnrollmentProfile(factorType, profile); if (enrollProfile != null && enrollProfile.length() > 0) { body.put(OktaAPIConstants.PROFILE, enrollProfile); } ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { LOGGER.debug("Failed to enroll factor [{}, {}]", ErrorResponse.class.cast(exchange.getBody()).getErrorSummary(), ErrorResponse.class.cast(exchange.getBody()).getErrorId()); throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }  }
FactorLifecycleServiceImpl implements FactorLifecycleService { @Override public Factor enroll(FactorType factorType, ProviderType provider, FactorProfile profile, OktaUser user) throws OktaException { Preconditions.checkNotNull(factorType, "factorType is null"); Preconditions.checkNotNull(provider, "provider is null"); if (user != null) { String apiPath = buildEnrollmentPath(factorType, user); JSONObject body = new JSONObject(); body.put(OktaAPIConstants.FACTOR_TYPE, factorType.getFactorType()); body.put(OktaAPIConstants.PROVIDER, provider.name()); JSONObject enrollProfile = buildEnrollmentProfile(factorType, profile); if (enrollProfile != null && enrollProfile.length() > 0) { body.put(OktaAPIConstants.PROFILE, enrollProfile); } ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { LOGGER.debug("Failed to enroll factor [{}, {}]", ErrorResponse.class.cast(exchange.getBody()).getErrorSummary(), ErrorResponse.class.cast(exchange.getBody()).getErrorId()); throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }  @Override Factor enroll(FactorType factorType, ProviderType provider, FactorProfile profile, OktaUser user); @Override Factor activate(String factorId, String passCode, OktaUser user); @Override Factor activate(String href, String passCode); @Override Factor activate(FactorType factorType, String passCode, OktaUser user); @Override void resetFactors(OktaUser user); OktaRestService getOktaRestService(); void setOktaRestService(OktaRestService oktaRestService); FactorService getFactorService(); void setFactorService(FactorService factorService); }
FactorLifecycleServiceImpl implements FactorLifecycleService { @Override public Factor enroll(FactorType factorType, ProviderType provider, FactorProfile profile, OktaUser user) throws OktaException { Preconditions.checkNotNull(factorType, "factorType is null"); Preconditions.checkNotNull(provider, "provider is null"); if (user != null) { String apiPath = buildEnrollmentPath(factorType, user); JSONObject body = new JSONObject(); body.put(OktaAPIConstants.FACTOR_TYPE, factorType.getFactorType()); body.put(OktaAPIConstants.PROVIDER, provider.name()); JSONObject enrollProfile = buildEnrollmentProfile(factorType, profile); if (enrollProfile != null && enrollProfile.length() > 0) { body.put(OktaAPIConstants.PROFILE, enrollProfile); } ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { LOGGER.debug("Failed to enroll factor [{}, {}]", ErrorResponse.class.cast(exchange.getBody()).getErrorSummary(), ErrorResponse.class.cast(exchange.getBody()).getErrorId()); throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }  @Override Factor enroll(FactorType factorType, ProviderType provider, FactorProfile profile, OktaUser user); @Override Factor activate(String factorId, String passCode, OktaUser user); @Override Factor activate(String href, String passCode); @Override Factor activate(FactorType factorType, String passCode, OktaUser user); @Override void resetFactors(OktaUser user); OktaRestService getOktaRestService(); void setOktaRestService(OktaRestService oktaRestService); FactorService getFactorService(); void setFactorService(FactorService factorService);  }