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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations