Search in sources :

Example 16 with User

use of com.epam.ta.reportportal.entity.user.User in project service-authorization by reportportal.

the class ReportPortalSamlAuthenticationManager method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    if (authentication instanceof DefaultSamlAuthentication) {
        ReportPortalSamlAuthentication reportPortalSamlAuthentication = new ReportPortalSamlAuthentication((DefaultSamlAuthentication) authentication);
        if (reportPortalSamlAuthentication.isAuthenticated()) {
            User user = samlUserReplicator.replicateUser(reportPortalSamlAuthentication);
            reportPortalSamlAuthentication.setAuthorities(AuthUtils.AS_AUTHORITIES.apply(user.getRole()));
            SecurityContextHolder.getContext().setAuthentication(reportPortalSamlAuthentication);
        }
        return reportPortalSamlAuthentication;
    }
    return authentication;
}
Also used : DefaultSamlAuthentication(org.springframework.security.saml.spi.DefaultSamlAuthentication) User(com.epam.ta.reportportal.entity.user.User)

Example 17 with User

use of com.epam.ta.reportportal.entity.user.User in project commons-dao by reportportal.

the class UserCommonDataStoreServiceTest method saveUserPhoto.

@Test
void saveUserPhoto() throws IOException {
    CommonsMultipartFile multipartFile = getMultipartFile("meh.jpg");
    User user = userRepository.findByLogin("default").get();
    userDataStoreService.saveUserPhoto(user, multipartFile);
    user = userRepository.findByLogin("default").get();
    BinaryData binaryData = userDataStoreService.loadUserPhoto(user, false);
    assertThat(IOUtils.contentEquals(multipartFile.getInputStream(), binaryData.getInputStream())).isTrue();
    BinaryData binaryDataThumbnail = userDataStoreService.loadUserPhoto(user, true);
    assertThat(IOUtils.contentEquals(thumbnailator.createThumbnail(multipartFile.getInputStream()), binaryDataThumbnail.getInputStream())).isTrue();
}
Also used : User(com.epam.ta.reportportal.entity.user.User) BinaryData(com.epam.ta.reportportal.entity.attachment.BinaryData) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 18 with User

use of com.epam.ta.reportportal.entity.user.User in project commons-dao by reportportal.

the class UserRepositoryTest method loadUserByLastLogin.

@Test
void loadUserByLastLogin() {
    // given
    long now = new Date().getTime();
    Filter filter = Filter.builder().withTarget(User.class).withCondition(FilterCondition.builder().withCondition(Condition.LOWER_THAN).withSearchCriteria(CRITERIA_LAST_LOGIN).withValue(String.valueOf(now)).build()).withCondition(FilterCondition.builder().eq(CRITERIA_PROJECT_ID, "3").build()).build();
    // when
    List<User> users = userRepository.findByFilter(filter);
    // then
    assertThat("Users should exist", users.size(), Matchers.greaterThan(0));
    users.forEach(user -> assertThat("Last login should be lower than in the filer", Long.parseLong((String) user.getMetadata().getMetadata().get("last_login")), Matchers.lessThan(now)));
}
Also used : ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) Filter(com.epam.ta.reportportal.commons.querygen.Filter) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 19 with User

use of com.epam.ta.reportportal.entity.user.User in project commons-dao by reportportal.

the class UserRepositoryTest method loadUsersByFilterForProject.

@Test
void loadUsersByFilterForProject() {
    // given
    Filter filter = buildDefaultUserFilter();
    filter.withCondition(new FilterCondition(Condition.EQUALS, false, "3", CRITERIA_PROJECT_ID));
    // when
    List<User> users = userRepository.findByFilterExcluding(filter, PageRequest.of(0, 5), "email").getContent();
    // then
    assertThat("Users not found", users, Matchers.notNullValue());
    assertThat("Incorrect size of founded users", users, Matchers.hasSize(3));
    users.forEach(it -> assertNull(it.getEmail()));
}
Also used : ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) Filter(com.epam.ta.reportportal.commons.querygen.Filter) CompositeFilterCondition(com.epam.ta.reportportal.commons.querygen.CompositeFilterCondition) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 20 with User

use of com.epam.ta.reportportal.entity.user.User in project commons-dao by reportportal.

the class UserRepositoryTest method findAllMembersByProjectManagerRole.

@Test
void findAllMembersByProjectManagerRole() {
    List<String> emails = userRepository.findEmailsByProjectAndRole(1L, ProjectRole.PROJECT_MANAGER);
    assertFalse(emails.isEmpty());
    emails.forEach(e -> {
        User user = userRepository.findByEmail(e).get();
        assertEquals(ProjectRole.PROJECT_MANAGER, user.getProjects().stream().filter(it -> it.getId().getProjectId().equals(1L)).map(ProjectUser::getProjectRole).findFirst().get());
    });
}
Also used : ProjectUser(com.epam.ta.reportportal.entity.user.ProjectUser) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

User (com.epam.ta.reportportal.entity.user.User)22 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)14 ProjectUser (com.epam.ta.reportportal.entity.user.ProjectUser)13 Test (org.junit.jupiter.api.Test)13 BaseTest (com.epam.ta.reportportal.BaseTest)10 Filter (com.epam.ta.reportportal.commons.querygen.Filter)7 Project (com.epam.ta.reportportal.entity.project.Project)7 CompositeFilterCondition (com.epam.ta.reportportal.commons.querygen.CompositeFilterCondition)6 FilterCondition (com.epam.ta.reportportal.commons.querygen.FilterCondition)6 Transactional (org.springframework.transaction.annotation.Transactional)6 AbstractUserReplicator (com.epam.reportportal.auth.integration.AbstractUserReplicator)4 ContentTypeResolver (com.epam.reportportal.commons.ContentTypeResolver)4 UserBinaryDataService (com.epam.ta.reportportal.binary.UserBinaryDataService)4 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)4 UserRepository (com.epam.ta.reportportal.dao.UserRepository)4 UserRole (com.epam.ta.reportportal.entity.user.UserRole)4 UserType (com.epam.ta.reportportal.entity.user.UserType)4 PersonalProjectService (com.epam.ta.reportportal.util.PersonalProjectService)4 Optional (java.util.Optional)4 Component (org.springframework.stereotype.Component)4