Search in sources :

Example 1 with SecondFactorMethod

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());
    });
}
Also used : PATCH(io.dropwizard.jersey.PATCH) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) FIELD_USERNAME(uk.gov.pay.adminusers.model.User.FIELD_USERNAME) GET(javax.ws.rs.GET) CreateUserRequest(uk.gov.pay.adminusers.model.CreateUserRequest) User(uk.gov.pay.adminusers.model.User) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Valid(javax.validation.Valid) UserServices(uk.gov.pay.adminusers.service.UserServices) QueryParam(javax.ws.rs.QueryParam) ExistingUserOtpDispatcher(uk.gov.pay.adminusers.service.ExistingUserOtpDispatcher) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) SecondFactorMethod(uk.gov.pay.adminusers.model.SecondFactorMethod) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) Splitter(com.google.common.base.Splitter) AdminUsersExceptions.conflictingUsername(uk.gov.pay.adminusers.service.AdminUsersExceptions.conflictingUsername) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) UNAUTHORIZED(javax.ws.rs.core.Response.Status.UNAUTHORIZED) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) UserServicesFactory(uk.gov.pay.adminusers.service.UserServicesFactory) OK(javax.ws.rs.core.Response.Status.OK) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) AdminUsersExceptions.internalServerError(uk.gov.pay.adminusers.service.AdminUsersExceptions.internalServerError) PatchRequest(uk.gov.pay.adminusers.model.PatchRequest) List(java.util.List) Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) Optional(java.util.Optional) PUT(javax.ws.rs.PUT) CREATED(javax.ws.rs.core.Response.Status.CREATED) SecondFactorMethod(uk.gov.pay.adminusers.model.SecondFactorMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 2 with SecondFactorMethod

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;
}
Also used : RandomIdGenerator.randomUuid(uk.gov.pay.adminusers.app.util.RandomIdGenerator.randomUuid) User(uk.gov.pay.adminusers.model.User) DatabaseTestHelper(uk.gov.pay.adminusers.utils.DatabaseTestHelper) Role(uk.gov.pay.adminusers.model.Role) ArrayList(java.util.ArrayList) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) List(java.util.List) ServiceName(uk.gov.pay.adminusers.model.ServiceName) Pair(org.apache.commons.lang3.tuple.Pair) ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) RandomIdGenerator.randomInt(uk.gov.pay.adminusers.app.util.RandomIdGenerator.randomInt) Service(uk.gov.pay.adminusers.model.Service) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) SecondFactorMethod(uk.gov.pay.adminusers.model.SecondFactorMethod) ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) User(uk.gov.pay.adminusers.model.User)

Example 3 with SecondFactorMethod

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));
}
Also used : SecondFactorMethod(uk.gov.pay.adminusers.model.SecondFactorMethod) Test(org.junit.jupiter.api.Test)

Example 4 with SecondFactorMethod

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));
}
Also used : SecondFactorMethod(uk.gov.pay.adminusers.model.SecondFactorMethod) Test(org.junit.jupiter.api.Test)

Example 5 with SecondFactorMethod

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));
}
Also used : SecondFactorMethod(uk.gov.pay.adminusers.model.SecondFactorMethod) Test(org.junit.jupiter.api.Test)

Aggregations

SecondFactorMethod (uk.gov.pay.adminusers.model.SecondFactorMethod)5 Test (org.junit.jupiter.api.Test)3 List (java.util.List)2 User (uk.gov.pay.adminusers.model.User)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Splitter (com.google.common.base.Splitter)1 Inject (com.google.inject.Inject)1 PATCH (io.dropwizard.jersey.PATCH)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)1 Valid (javax.validation.Valid)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1