Search in sources :

Example 11 with UserBuilder

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

the class WorkflowTest method testStartReleaseModelWithReviewedDependencies.

@Test
public void testStartReleaseModelWithReviewedDependencies() 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(typeModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName());
    assertEquals("InReview", workflow.doAction(fbModel.getId(), createUserContext(getCallerId(), PLAYGROUND), SimpleWorkflowModel.ACTION_RELEASE.getName()).getState());
}
Also used : ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 12 with UserBuilder

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

the class NamespaceControllerIntegrationTest method testRemoveExistingUserFromNamespaceWithNoPrivileges.

/**
 * Tests that removing an existing user from a namespace fails if the user performing the operation
 * has no "tenant admin" role for that namespace. <br/>
 * In this case, we're creating a third user with tenant admin authority, who is not added as
 * admin of that namespace, and will try to remove the simple user.<br/>
 * Note that it might be worth thinking of the edge case where a user simply wants to be removed
 * from a namespace they have been added to, regardless of their role in that namespace. <br/>
 * See {@link org.eclipse.vorto.repository.web.api.v1.NamespaceController#removeUserFromNamespace(String, String)}
 * for specifications on how authorization is enforced.
 *
 * @throws Exception
 */
@Test
public void testRemoveExistingUserFromNamespaceWithNoPrivileges() throws Exception {
    // first, creates the namespace for the admin user
    createNamespaceSuccessfully("myAdminNamespace", userSysadmin);
    Collaborator userModelCreatorCollaborator = new Collaborator();
    userModelCreatorCollaborator.setUserId(USER_MODEL_CREATOR_NAME);
    Set<String> roles = new HashSet<>();
    roles.add("model_viewer");
    userModelCreatorCollaborator.setRoles(roles);
    // adds the collaborator with "model_viewer" roles to the namespace
    repositoryServer.perform(put("/rest/namespaces/myAdminNamespace/users").contentType("application/json").content(objectMapper.writeValueAsString(userModelCreatorCollaborator)).with(userSysadmin)).andExpect(status().isOk()).andExpect(content().string("true"));
    // creates a user with tenant admin privileges but no access to the namespace in question
    SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor thirdUser = user("thirdPartyUser").password("pass");
    userRepository.save(new UserBuilder().withAuthenticationProviderID(GITHUB).withName("thirdPartyUser").build());
    // finally removes the user from the namespace but with the "thirdPartyUser" who is tenant admin
    // "somewhere else", which fails due to lack of tenant admin role on that given namespace
    repositoryServer.perform(delete(String.format("/rest/namespaces/myAdminNamespace/users/%s", USER_MODEL_CREATOR_NAME)).with(thirdUser)).andExpect(status().isForbidden());
}
Also used : SecurityMockMvcRequestPostProcessors(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) HashSet(java.util.HashSet) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 13 with UserBuilder

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

the class NamespaceControllerIntegrationTest method testChangeUserRolesOnNamespaceUserWithExtraneousUser.

/**
 * Tests that changing a user's roles on a namespace from a user who's tenant admin, but not on
 * that namespace, fails.
 *
 * @throws Exception
 */
@Test
public void testChangeUserRolesOnNamespaceUserWithExtraneousUser() throws Exception {
    // first, creates the namespace for the admin user
    createNamespaceSuccessfully("myAdminNamespace", userSysadmin);
    // then, add the creator user
    Collaborator userModelCreatorCollaborator = new Collaborator();
    userModelCreatorCollaborator.setUserId(USER_MODEL_CREATOR_NAME);
    Set<String> roles = new HashSet<>();
    roles.add("model_viewer");
    userModelCreatorCollaborator.setRoles(roles);
    repositoryServer.perform(put("/rest/namespaces/myAdminNamespace/users").contentType("application/json").content(objectMapper.writeValueAsString(userModelCreatorCollaborator)).with(userSysadmin)).andExpect(status().isOk()).andExpect(content().string("true"));
    // creates a user with tenant admin privileges but no access to the namespace in question
    SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor thirdUser = user("thirdPartyUser").password("pass");
    userRepository.save(new UserBuilder().withAuthenticationProviderID(GITHUB).withName("thirdPartyUser").build());
    // finally, change the user roles on the DTO and PUT again
    roles.add("model_creator");
    userModelCreatorCollaborator.setRoles(roles);
    repositoryServer.perform(put("/rest/namespaces/myAdminNamespace/users").contentType("application/json").content(objectMapper.writeValueAsString(userModelCreatorCollaborator)).with(thirdUser)).andExpect(status().isForbidden());
}
Also used : SecurityMockMvcRequestPostProcessors(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) HashSet(java.util.HashSet) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder) Test(org.junit.Test)

Example 14 with UserBuilder

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

the class HydraTokenVerifierTest method getVerifier.

private BoschIoTSuiteOAuthProviderAuthCode getVerifier() throws InvalidUserException {
    User user = new UserBuilder().withName("d758a35e-94ef-443f-9625-7f03092e2005").withAuthenticationProviderID("GITHUB").build();
    DefaultUserAccountService userAccountService = Mockito.mock(DefaultUserAccountService.class);
    when(userAccountService.getUser("d758a35e-94ef-443f-9625-7f03092e2005")).thenReturn(user);
    UserNamespaceRoleService userNamespaceRoleService = Mockito.mock(UserNamespaceRoleService.class);
    return new BoschIoTSuiteOAuthProviderAuthCode("", publicKey(), configuration, userAccountService, userNamespaceRoleService);
}
Also used : User(org.eclipse.vorto.repository.domain.User) UserNamespaceRoleService(org.eclipse.vorto.repository.services.UserNamespaceRoleService) DefaultUserAccountService(org.eclipse.vorto.repository.account.impl.DefaultUserAccountService) UserBuilder(org.eclipse.vorto.repository.services.UserBuilder)

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