Search in sources :

Example 6 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class NamespaceControllerIntegrationTest method updateCollaboratorUnknownProvider.

/**
 * The difference between POST and PUT operations on collaborators essentially boils down to:
 * <ul>
 *   <li>
 *     POST ops mean creating a new technical user, and therefore validate the whole collaborator
 *     payload but assume the user does not exist.
 *   </li>
 *   <li>
 *     PUT ops mean adding an existing user to the namespace, and therefore only perform minimal
 *     validation (i.e. the user name), yet assume the user exists and fail otherwise.
 *   </li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public void updateCollaboratorUnknownProvider() throws Exception {
    // creates the collaborator payload and the existing user
    String otherUser = "userstandard2";
    Collaborator collaborator = new Collaborator(otherUser, "unknownProvider", null, Lists.newArrayList("model_viewer", "model_creator"));
    userRepository.save(new UserBuilder().withName(otherUser).withAuthenticationProviderID(GITHUB).build());
    repositoryServer.perform(put("/rest/namespaces/com.mycompany/users").content(objectMapper.writeValueAsString(collaborator)).contentType(MediaType.APPLICATION_JSON).with(userSysadmin)).andExpect(status().isOk());
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 7 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class AccountControllerTest method verifyTechnicalUserCreatedBy.

@Test
public void verifyTechnicalUserCreatedBy() throws Exception {
    UserDto payload = UserDto.fromUser(new UserBuilder().withName("theTechnicalUser").withAuthenticationProviderID("GITHUB").withAuthenticationSubject("theSubject").build());
    repositoryServer.perform(post("/rest/accounts/createTechnicalUser").content(objectMapper.writeValueAsString(payload)).contentType("application/json").with(userSysadmin)).andExpect(status().isCreated());
    // fetch sysadmin id
    User sysadmin = userRepository.findByUsername(USER_SYSADMIN_NAME);
    assertNotNull(sysadmin);
    // compare with the tech user created by
    User theTechnicalUser = userRepository.findByUsername("theTechnicalUser");
    assertNotNull(theTechnicalUser);
    assertEquals(sysadmin.getId(), theTechnicalUser.getCreatedBy());
}
Also used : User(org.eclipse.vorto.repository.domain.User) UserDto(org.eclipse.vorto.repository.web.account.dto.UserDto) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 8 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class RepositoryInitializer method createAdminUser.

private void createAdminUser(String username, long id) {
    if (userRepository.findByUsername(username) == null) {
        logger.info("Creating admin user: {}", username);
        User user = null;
        try {
            user = new UserBuilder().withName(username).build();
        } catch (InvalidUserException iue) {
            logger.warn("Unable to create admin user - skipping.");
            return;
        }
        // TODO : set to be configurable from configuration file
        user.setEmailAddress("vorto-dev@bosch-si.com");
        user.setAuthenticationProviderId("GITHUB");
        user.setTechnicalUser(false);
        userRepository.save(user);
    }
    User user = userRepository.findByUsername(username);
    UserRepositoryRoles roles = userRepositoryRoleRepository.findByUser(user.getId()).orElse(new UserRepositoryRoles());
    if (roles.getUser() == null) {
        roles.setUser(user);
    }
    if (roles.getId() == null) {
        roles.setId(id);
    }
    roles.setRoles(RepositoryRole.SYS_ADMIN.getRole());
    userRepositoryRoleRepository.save(roles);
}
Also used : User(org.eclipse.vorto.repository.domain.User) UserRepositoryRoles(org.eclipse.vorto.repository.domain.UserRepositoryRoles) InvalidUserException(org.eclipse.vorto.repository.services.exceptions.InvalidUserException) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder)

Example 9 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class WorkflowTest method testRejectModelInReviewState.

@Test
public void testRejectModelInReviewState() throws Exception {
    ModelInfo model = importModel("Color.type");
    IUserContext user = createUserContext("alex", PLAYGROUND);
    workflow.start(model.getId(), user);
    when(userRepository.findByUsername(createUserContext(getCallerId(), PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(getCallerId()).withAuthenticationProviderID(GITHUB).build());
    model = workflow.doAction(model.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), model.getState());
    when(userRepository.findByUsername(createUserContext(ADMIN, PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(ADMIN).withAuthenticationProviderID(GITHUB).build());
    model = workflow.doAction(model.getId(), createUserContext(ADMIN, PLAYGROUND), SimpleWorkflowModel.ACTION_REJECT.getName());
    assertEquals(0, workflow.getModelsByState(SimpleWorkflowModel.STATE_RELEASED.getName(), user).size());
    assertEquals(0, workflow.getModelsByState(SimpleWorkflowModel.STATE_IN_REVIEW.getName(), user).size());
    assertEquals(1, workflow.getModelsByState(SimpleWorkflowModel.STATE_DRAFT.getName(), user).size());
    assertEquals(1, workflow.getPossibleActions(model.getId(), createUserContext(getCallerId(), PLAYGROUND)).size());
}
Also used : IUserContext(org.eclipse.vorto.repository.core.IUserContext) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 10 with UserBuilder

use of org.eclipse.vorto.repository.services.UserBuilder in project vorto by eclipse.

the class WorkflowTest method testApproveWithNonApprovedDependencies.

@Test
public void testApproveWithNonApprovedDependencies() throws Exception {
    ModelInfo typeModel = importModel("Color.type");
    workflow.start(typeModel.getId(), createUserContext("alex", PLAYGROUND));
    ModelInfo fbModel = importModel("Colorlight.fbmodel");
    workflow.start(fbModel.getId(), createUserContext("alex", PLAYGROUND));
    when(userRepository.findByUsername(createUserContext(getCallerId(), PLAYGROUND).getUsername())).thenReturn(new UserBuilder().withName(getCallerId()).withAuthenticationProviderID(GITHUB).build());
    workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals("InReview", this.repositoryFactory.getRepositoryByModel(typeModel.getId()).getById(typeModel.getId()).getState());
    assertEquals("InReview", this.repositoryFactory.getRepositoryByModel(fbModel.getId()).getById(fbModel.getId()).getState());
    workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_APPROVE.getName());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Aggregations

UserBuilder (org.eclipse.vorto.repository.services.UserBuilder)14 Test (org.junit.Test)11 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)5 Collaborator (org.eclipse.vorto.repository.web.api.v1.dto.Collaborator)5 User (org.eclipse.vorto.repository.domain.User)4 HashSet (java.util.HashSet)2 SecurityMockMvcRequestPostProcessors (org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors)2 Transactional (javax.transaction.Transactional)1 DefaultUserAccountService (org.eclipse.vorto.repository.account.impl.DefaultUserAccountService)1 IUserContext (org.eclipse.vorto.repository.core.IUserContext)1 UserRepositoryRoles (org.eclipse.vorto.repository.domain.UserRepositoryRoles)1 UserNamespaceRoleService (org.eclipse.vorto.repository.services.UserNamespaceRoleService)1 InvalidUserException (org.eclipse.vorto.repository.services.exceptions.InvalidUserException)1 UserDto (org.eclipse.vorto.repository.web.account.dto.UserDto)1