use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class MappingTest method testCheckinValidMapping.
@Test
public void testCheckinValidMapping() throws Exception {
IUserContext userContext = createUserContext("admin", "playground");
UploadModelResult uploadResult = this.importer.upload(FileUpload.create("Color.type", IOUtils.toByteArray(new ClassPathResource("sample_models/Color.type").getInputStream())), Context.create(userContext, Optional.empty()));
assertEquals(true, uploadResult.isValid());
assertEquals(0, repositoryFactory.getRepository(userContext).search("*").size());
User user = new User();
user.setUsername("alex");
Collection<User> users = new ArrayList<>();
users.add(user);
when(userRepository.findAll()).thenReturn(users);
this.importer.doImport(uploadResult.getHandleId(), Context.create(createUserContext("alex", "playground"), Optional.empty()));
assertEquals(1, repositoryFactory.getRepository(userContext).search("*").size());
uploadResult = this.importer.upload(FileUpload.create("sample.mapping", IOUtils.toByteArray(new ClassPathResource("sample_models/sample.mapping").getInputStream())), Context.create(createUserContext("admin", "playground"), Optional.empty()));
assertEquals(true, uploadResult.getReports().get(0).isValid());
this.importer.doImport(uploadResult.getHandleId(), Context.create(createUserContext("alex", "playground"), Optional.empty()));
assertEquals(1, repositoryFactory.getRepository(userContext).search("type:Mapping").size());
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class IsReviewerCondition method passesCondition.
@Override
public boolean passesCondition(ModelInfo model, IUserContext user) {
IRole role = roleService.findAnyByName("model_reviewer").orElseThrow(() -> new IllegalStateException("model_reviewer role not found."));
User foundUser = userAccountService.getUser(user.getUsername());
return Objects.nonNull(foundUser) && hasRole(user, foundUser, role);
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class UserDBAuthoritiesExtractor method getGrantedAuthorities.
protected List<GrantedAuthority> getGrantedAuthorities(Map<String, Object> map, String userAttr) {
String username = (String) map.get(userAttr);
User user = userService.getUser(username);
if (user == null) {
return Collections.emptyList();
}
Set<IRole> allRoles = getAllRoles(user);
if (allRoles.isEmpty()) {
allRoles.add(roleService.findAnyByName("user").orElseThrow(() -> new IllegalStateException("Role 'user' is not present.")));
}
return SpringUserUtils.toAuthorityList(allRoles);
}
use of org.eclipse.vorto.repository.domain.User in project vorto by eclipse.
the class NamespaceControllerIntegrationTest method updateCollaboratorAddTechnicalUser.
@Test
public void updateCollaboratorAddTechnicalUser() throws Exception {
String namespaceName = "com.mycompany";
Collaborator collaborator = new Collaborator("my-technical-user", GITHUB, "ProjectX", Lists.newArrayList("model_viewer", "model_creator"));
collaborator.setTechnicalUser(true);
createTechnicalUserAndAddToNamespace(namespaceName, collaborator);
User technicalUser = userRepository.findByUsername("my-technical-user");
assertNotNull(technicalUser);
assertTrue(technicalUser.isTechnicalUser());
checkCollaboratorRoles(namespaceName, "my-technical-user", "model_viewer", "model_creator");
collaborator = new Collaborator("my-technical-user", GITHUB, "ProjectX", Lists.newArrayList("model_viewer"));
// cannot re-create tech user so adding as collaborator since it already exists now
addCollaboratorToNamespace(namespaceName, collaborator);
checkCollaboratorRoles(namespaceName, "my-technical-user", "model_viewer");
}
use of org.eclipse.vorto.repository.domain.User 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);
}
Aggregations