Search in sources :

Example 1 with ServiceRole

use of uk.gov.pay.adminusers.model.ServiceRole in project pay-adminusers by alphagov.

the class UserInviteCompleterTest method aUser.

private User aUser(String email) {
    Service service = Service.from(serviceId, serviceExternalId, new ServiceName(Service.DEFAULT_NAME_VALUE));
    ServiceRole serviceRole = ServiceRole.from(service, role(ADMIN.getId(), "Admin", "Administrator"));
    return User.from(randomInt(), randomUuid(), "a-username", "random-password", email, "784rh", "8948924", Collections.singletonList(serviceRole), null, SecondFactorMethod.SMS, null, null, null);
}
Also used : ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) ServiceName(uk.gov.pay.adminusers.model.ServiceName) Service(uk.gov.pay.adminusers.model.Service)

Example 2 with ServiceRole

use of uk.gov.pay.adminusers.model.ServiceRole in project pay-adminusers by alphagov.

the class LinksBuilderTest method shouldConstruct_userSelfLinkCorrectly.

@Test
void shouldConstruct_userSelfLinkCorrectly() throws Exception {
    Service service = Service.from(2, "34783g87ebg764r", new ServiceName(Service.DEFAULT_NAME_VALUE));
    Role role = Role.role(2, "blah", "blah");
    ServiceRole serviceRole = ServiceRole.from(service, role);
    User user = User.from(randomInt(), randomUuid(), "a-username", "a-password", "email@example.com", "4wrwef", "123435", Collections.singletonList(serviceRole), null, SecondFactorMethod.SMS, null, null, null);
    User decoratedUser = linksBuilder.decorate(user);
    String linkJson = objectMapper.writeValueAsString(decoratedUser.getLinks().get(0));
    assertThat(linkJson, is("{\"rel\":\"self\",\"method\":\"GET\",\"href\":\"http://localhost:8080/v1/api/users/" + decoratedUser.getExternalId() + "\"}"));
}
Also used : Role(uk.gov.pay.adminusers.model.Role) ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) User(uk.gov.pay.adminusers.model.User) ServiceName(uk.gov.pay.adminusers.model.ServiceName) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceRole

use of uk.gov.pay.adminusers.model.ServiceRole in project pay-adminusers by alphagov.

the class UserInviteCreatorTest method aUser.

private User aUser(String email) {
    Service service = Service.from(serviceId, serviceExternalId, new ServiceName(Service.DEFAULT_NAME_VALUE));
    ServiceRole serviceRole = ServiceRole.from(service, role(ADMIN.getId(), "Admin", "Administrator"));
    return User.from(randomInt(), randomUuid(), "a-username", "random-password", email, "784rh", "8948924", Collections.singletonList(serviceRole), null, SecondFactorMethod.SMS, null, null, null);
}
Also used : ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) ServiceName(uk.gov.pay.adminusers.model.ServiceName) Service(uk.gov.pay.adminusers.model.Service)

Example 4 with ServiceRole

use of uk.gov.pay.adminusers.model.ServiceRole in project pay-adminusers by alphagov.

the class UserEntity method toUser.

public User toUser() {
    List<ServiceRole> serviceRoles = this.servicesRoles.stream().map(ServiceRoleEntity::toServiceRole).collect(toUnmodifiableList());
    User user = User.from(getId(), externalId, username, password, email, otpKey, telephoneNumber, serviceRoles, features, secondFactor, provisionalOtpKey, provisionalOtpKeyCreatedAt, lastLoggedInAt);
    user.setLoginCounter(loginCounter);
    user.setDisabled(disabled);
    user.setSessionVersion(sessionVersion);
    return user;
}
Also used : ServiceRole(uk.gov.pay.adminusers.model.ServiceRole) User(uk.gov.pay.adminusers.model.User)

Example 5 with ServiceRole

use of uk.gov.pay.adminusers.model.ServiceRole 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)

Aggregations

ServiceRole (uk.gov.pay.adminusers.model.ServiceRole)5 Service (uk.gov.pay.adminusers.model.Service)4 ServiceName (uk.gov.pay.adminusers.model.ServiceName)4 User (uk.gov.pay.adminusers.model.User)3 Role (uk.gov.pay.adminusers.model.Role)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors.toUnmodifiableList (java.util.stream.Collectors.toUnmodifiableList)1 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)1 Pair (org.apache.commons.lang3.tuple.Pair)1 Test (org.junit.jupiter.api.Test)1 RandomIdGenerator.randomInt (uk.gov.pay.adminusers.app.util.RandomIdGenerator.randomInt)1 RandomIdGenerator.randomUuid (uk.gov.pay.adminusers.app.util.RandomIdGenerator.randomUuid)1 SecondFactorMethod (uk.gov.pay.adminusers.model.SecondFactorMethod)1 DatabaseTestHelper (uk.gov.pay.adminusers.utils.DatabaseTestHelper)1