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