Search in sources :

Example 6 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class UserManager method loadUserByNameOrId.

public PipelineUser loadUserByNameOrId(String identifier) {
    PipelineUser user;
    if (NumberUtils.isDigits(identifier)) {
        user = loadUserById(Long.parseLong(identifier));
    } else {
        user = loadUserByName(identifier);
    }
    Assert.notNull(user, "User with identifier not found: " + identifier);
    return user;
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser)

Example 7 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class SAMLProxyFilter method authenticate.

private void authenticate(String samlResponse, Response decoded, String endpointId, ExternalServiceEndpoint endpoint) throws IOException, SAMLException {
    try (FileReader metadataReader = new FileReader(new File(endpoint.getMetadataPath()))) {
        CustomSamlClient client = CustomSamlClient.fromMetadata(endpointId, metadataReader, RESPONSE_SKEW);
        client.setMaxAuthenticationAge(MAX_AUTHENTICATION_AGE);
        SamlResponse parsedResponse = client.validate(decoded);
        String userName = parsedResponse.getNameID().toUpperCase();
        PipelineUser loadedUser = userManager.loadUserByName(userName);
        if (loadedUser == null) {
            throw new UsernameNotFoundException(messageHelper.getMessage(MessageConstants.ERROR_USER_NAME_NOT_FOUND, userName));
        }
        LOGGER.debug("Found user by name {}", userName);
        UserContext userContext = new UserContext(loadedUser);
        userContext.setExternal(endpoint.isExternal());
        SecurityContextHolder.getContext().setAuthentication(new SAMLProxyAuthentication(samlResponse, parsedResponse, userContext));
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) UserContext(com.epam.pipeline.security.UserContext) FileReader(java.io.FileReader) SamlResponse(com.coveo.saml.SamlResponse) File(java.io.File)

Example 8 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class PipelineRunDaoTest method testLoadActiveServicesByUserInGroup.

@Test
public void testLoadActiveServicesByUserInGroup() {
    List<RunSid> runSids = new ArrayList<>();
    RunSid runSid = new RunSid();
    runSid.setName(GROUP_NAME);
    runSid.setIsPrincipal(false);
    runSids.add(runSid);
    Pipeline testPipeline = getPipeline();
    PipelineRun run = createRunWithRunSids(testPipeline.getId(), null, runSids);
    PagingRunFilterVO filterVO = new PagingRunFilterVO();
    filterVO.setPage(1);
    filterVO.setPageSize(TEST_PAGE_SIZE);
    PipelineUser user = new PipelineUser();
    user.setUserName(TEST_USER);
    user.setGroups(Collections.singletonList(GROUP_NAME));
    List<PipelineRun> runs = pipelineRunDao.loadActiveServices(filterVO, user);
    assertEquals(1, runs.size());
    assertEquals(run.getId(), runs.get(0).getId());
    assertEquals(1, runs.size());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) RunSid(com.epam.pipeline.entity.pipeline.run.parameter.RunSid) ArrayList(java.util.ArrayList) PagingRunFilterVO(com.epam.pipeline.controller.vo.PagingRunFilterVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) EnvVarsBuilderTest(com.epam.pipeline.manager.execution.EnvVarsBuilderTest) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 9 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class PipelineRunDaoTest method testLoadActiveServicesByUserIsPrincipal.

@Test
public void testLoadActiveServicesByUserIsPrincipal() {
    List<RunSid> runSids = new ArrayList<>();
    RunSid runSid1 = new RunSid();
    runSid1.setName(TEST_USER);
    runSid1.setIsPrincipal(true);
    runSids.add(runSid1);
    Pipeline testPipeline = getPipeline();
    PipelineRun run = createRunWithRunSids(testPipeline.getId(), null, runSids);
    PagingRunFilterVO filterVO = new PagingRunFilterVO();
    filterVO.setPage(1);
    filterVO.setPageSize(TEST_PAGE_SIZE);
    PipelineUser user = new PipelineUser();
    user.setUserName(TEST_USER);
    List<PipelineRun> runs = pipelineRunDao.loadActiveServices(filterVO, user);
    assertEquals(1, runs.size());
    assertEquals(run.getId(), runs.get(0).getId());
    assertEquals(1, runs.size());
    int servicesCount = pipelineRunDao.countActiveServices(user);
    assertEquals(runs.size(), servicesCount);
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) RunSid(com.epam.pipeline.entity.pipeline.run.parameter.RunSid) ArrayList(java.util.ArrayList) PagingRunFilterVO(com.epam.pipeline.controller.vo.PagingRunFilterVO) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) EnvVarsBuilderTest(com.epam.pipeline.manager.execution.EnvVarsBuilderTest) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 10 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class UserDaoTest method testDefaultAdmin.

@Test
public void testDefaultAdmin() {
    PipelineUser admin = userDao.loadUserByName(defaultAdmin);
    Assert.assertNotNull(admin);
    Assert.assertEquals(defaultAdmin, admin.getUserName());
    Assert.assertTrue(admin.getId().equals(1L));
    Assert.assertEquals(1, admin.getRoles().size());
    Assert.assertTrue(isRolePresent(DefaultRoles.ROLE_ADMIN.getRole(), admin.getRoles()));
    Collection<Role> allRoles = roleDao.loadAllRoles(false);
    Assert.assertEquals(EXPECTED_DEFAULT_ROLES_NUMBER, allRoles.size());
    Assert.assertTrue(isRolePresent(DefaultRoles.ROLE_ADMIN.getRole(), allRoles));
    Assert.assertTrue(isRolePresent(DefaultRoles.ROLE_USER.getRole(), allRoles));
}
Also used : Role(com.epam.pipeline.entity.user.Role) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Aggregations

PipelineUser (com.epam.pipeline.entity.user.PipelineUser)44 Transactional (org.springframework.transaction.annotation.Transactional)23 Test (org.junit.Test)19 NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)13 NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)13 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)12 ArrayList (java.util.ArrayList)8 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)7 Collections (java.util.Collections)7 List (java.util.List)7 Map (java.util.Map)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Role (com.epam.pipeline.entity.user.Role)6 AbstractSpringTest (com.epam.pipeline.notifier.AbstractSpringTest)6 Arrays (java.util.Arrays)6 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)5 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)5 Collection (java.util.Collection)5 CollectionUtils (org.apache.commons.collections4.CollectionUtils)5 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)4