Search in sources :

Example 16 with User

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());
}
Also used : UploadModelResult(org.eclipse.vorto.repository.importer.UploadModelResult) User(org.eclipse.vorto.repository.domain.User) ArrayList(java.util.ArrayList) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 17 with User

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);
}
Also used : User(org.eclipse.vorto.repository.domain.User) IRole(org.eclipse.vorto.repository.domain.IRole)

Example 18 with User

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);
}
Also used : User(org.eclipse.vorto.repository.domain.User) IRole(org.eclipse.vorto.repository.domain.IRole)

Example 19 with User

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");
}
Also used : Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) User(org.eclipse.vorto.repository.domain.User) Test(org.junit.Test)

Example 20 with User

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

User (org.eclipse.vorto.repository.domain.User)36 ResponseEntity (org.springframework.http.ResponseEntity)13 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 IUserContext (org.eclipse.vorto.repository.core.IUserContext)8 DoesNotExistException (org.eclipse.vorto.repository.services.exceptions.DoesNotExistException)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 OperationForbiddenException (org.eclipse.vorto.repository.services.exceptions.OperationForbiddenException)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 Optional (java.util.Optional)6 InvalidUserException (org.eclipse.vorto.repository.services.exceptions.InvalidUserException)6 ApiParam (io.swagger.annotations.ApiParam)5 Collection (java.util.Collection)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 DefaultUserAccountService (org.eclipse.vorto.repository.account.impl.DefaultUserAccountService)5 Namespace (org.eclipse.vorto.repository.domain.Namespace)5 NamespaceService (org.eclipse.vorto.repository.services.NamespaceService)5 UserNamespaceRoleService (org.eclipse.vorto.repository.services.UserNamespaceRoleService)5 Test (org.junit.Test)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5