use of uk.gov.pay.adminusers.model.SecondFactorMethod in project pay-adminusers by alphagov.
the class UserResource method activateSecondFactorOtpKey.
@Path("/{userExternalId}/second-factor/activate")
@POST
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public Response activateSecondFactorOtpKey(@PathParam("userExternalId") String externalId, JsonNode payload) {
LOGGER.info("User 2FA activate new OTP key request");
return validator.validate2faActivateRequest(payload).map(errors -> Response.status(BAD_REQUEST).entity(errors).build()).orElseGet(() -> {
int code = payload.get("code").asInt();
SecondFactorMethod secondFactor = SecondFactorMethod.valueOf(payload.get("second_factor").asText());
return userServices.activateNewOtpKey(externalId, secondFactor, code).map(user -> Response.status(OK).type(APPLICATION_JSON).entity(user).build()).orElseGet(() -> Response.status(UNAUTHORIZED).build());
});
}
use of uk.gov.pay.adminusers.model.SecondFactorMethod in project pay-adminusers by alphagov.
the class UserDbFixture method insertUser.
public User insertUser() {
List<ServiceRole> serviceRoles = serviceRolePairs.stream().map(servicePair -> ServiceRole.from(servicePair.getLeft(), servicePair.getRight())).collect(toUnmodifiableList());
User user = User.from(randomInt(), externalId, username, password, email, otpKey, telephoneNumber, serviceRoles, features, secondFactorMethod, provisionalOtpKey, null, null);
databaseTestHelper.add(user);
serviceRoles.forEach(serviceRole -> databaseTestHelper.addUserServiceRole(user.getId(), serviceRole.getService().getId(), serviceRole.getRole().getId()));
return user;
}
use of uk.gov.pay.adminusers.model.SecondFactorMethod in project pay-adminusers by alphagov.
the class SecondFactorMethodConverterTest method smsStringConvertToEntityAttributeReturnsSmsEnumVariant.
@Test
public void smsStringConvertToEntityAttributeReturnsSmsEnumVariant() {
SecondFactorMethod entityAttribute = secondFactorMethodConverter.convertToEntityAttribute("sms");
assertThat(entityAttribute, is(SecondFactorMethod.SMS));
}
use of uk.gov.pay.adminusers.model.SecondFactorMethod in project pay-adminusers by alphagov.
the class SecondFactorMethodConverterTest method appStringConvertToEntityAttributeReturnsAppEnumVariant.
@Test
public void appStringConvertToEntityAttributeReturnsAppEnumVariant() {
SecondFactorMethod entityAttribute = secondFactorMethodConverter.convertToEntityAttribute("app");
assertThat(entityAttribute, is(SecondFactorMethod.APP));
}
use of uk.gov.pay.adminusers.model.SecondFactorMethod in project pay-adminusers by alphagov.
the class SecondFactorMethodConverterTest method unhandledStringConvertToEntityAttributeReturnsSmsEnumVariant.
@Test
public void unhandledStringConvertToEntityAttributeReturnsSmsEnumVariant() {
SecondFactorMethod entityAttribute = secondFactorMethodConverter.convertToEntityAttribute("Someone went wild in the DB!");
assertThat(entityAttribute, is(SecondFactorMethod.SMS));
}
Aggregations