@Test public void activateByIdTest() throws OktaException { ResponseEntity<Factor> responseEntity = new ResponseEntity<>(expectedFactor, HttpStatus.OK); String expectedRequestBody = "{\"passCode\":\"276825\"}"; expect(mockOktaRestService.doRestCall( "/api/v1/users/" + expectedUser.getId() + "/factors/" + expectedFactor.getId() + "/lifecycle/activate", HttpMethod.POST, Factor.class, expectedRequestBody)).andReturn(responseEntity); replayAll(); Factor factor = unit.activate(expectedFactor.getId(), "276825", 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 activate(String factorId, String passCode, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); Preconditions.checkArgument(!StringUtils.isEmpty(passCode), "passCode is null or empty"); if (user != null) { JSONObject body = new JSONObject(); body.put(OktaAPIConstants.PASS_CODE, passCode); String apiPath = String.format(OktaAPIConstants.ACTIVATE_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }
FactorLifecycleServiceImpl implements FactorLifecycleService { @Override public Factor activate(String factorId, String passCode, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); Preconditions.checkArgument(!StringUtils.isEmpty(passCode), "passCode is null or empty"); if (user != null) { JSONObject body = new JSONObject(); body.put(OktaAPIConstants.PASS_CODE, passCode); String apiPath = String.format(OktaAPIConstants.ACTIVATE_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; } }
FactorLifecycleServiceImpl implements FactorLifecycleService { @Override public Factor activate(String factorId, String passCode, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); Preconditions.checkArgument(!StringUtils.isEmpty(passCode), "passCode is null or empty"); if (user != null) { JSONObject body = new JSONObject(); body.put(OktaAPIConstants.PASS_CODE, passCode); String apiPath = String.format(OktaAPIConstants.ACTIVATE_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { throw new OktaException(buildErrorMessage(exchange.getBody())); } return exchange.getBody(); } return null; }  }
FactorLifecycleServiceImpl implements FactorLifecycleService { @Override public Factor activate(String factorId, String passCode, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); Preconditions.checkArgument(!StringUtils.isEmpty(passCode), "passCode is null or empty"); if (user != null) { JSONObject body = new JSONObject(); body.put(OktaAPIConstants.PASS_CODE, passCode); String apiPath = String.format(OktaAPIConstants.ACTIVATE_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { 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 activate(String factorId, String passCode, OktaUser user) throws OktaException { Preconditions.checkArgument(!StringUtils.isEmpty(factorId), "factorId is null or empty"); Preconditions.checkArgument(!StringUtils.isEmpty(passCode), "passCode is null or empty"); if (user != null) { JSONObject body = new JSONObject(); body.put(OktaAPIConstants.PASS_CODE, passCode); String apiPath = String.format(OktaAPIConstants.ACTIVATE_FACTOR, user.getId(), factorId); ResponseEntity<Factor> exchange = oktaRestService.doRestCall(apiPath, HttpMethod.POST, Factor.class, body.toString()); if (!exchange.getStatusCode().is2xxSuccessful()) { 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);  }