use of com.epam.pipeline.security.UserContext in project cloud-pipeline by epam.
the class SAMLUserDetailsServiceImplTest method testLoadUserBySAMLWithExistingUser.
@Test
public void testLoadUserBySAMLWithExistingUser() {
user.setUserName(OLD_USER_NAME);
user.setGroups(Stream.of(SAML_ATTRIBUTE_1).collect(Collectors.toList()));
Mockito.when(userManager.loadUserByName(Matchers.anyString())).thenReturn(user);
user.setGroups(Stream.of(SAML_ATTRIBUTE_1, SAML_ATTRIBUTE_2).collect(Collectors.toList()));
Mockito.when(userManager.updateUserSAMLInfo(Matchers.anyLong(), Matchers.anyString(), Matchers.anyListOf(Long.class), Matchers.anyListOf(String.class), Matchers.anyMapOf(String.class, String.class))).thenReturn(user);
UserContext actualUserContext = userDetailsService.loadUserBySAML(credential);
Assert.assertEquals(expectedUserContext.getUsername(), actualUserContext.getUsername());
Assert.assertEquals(expectedUserContext.getGroups(), actualUserContext.getGroups());
}
use of com.epam.pipeline.security.UserContext in project cloud-pipeline by epam.
the class ClusterManagerImpl method getApiTokenForRun.
private String getApiTokenForRun(String runId) {
PipelineRun run = pipelineRunManager.loadPipelineRun(Long.valueOf(runId));
UserContext owner = Optional.ofNullable(authManager.getUserContext()).orElse(userManager.loadUserContext(run.getOwner()));
return authManager.issueToken(owner, null).getToken();
}
use of com.epam.pipeline.security.UserContext in project cloud-pipeline by epam.
the class PipelineLauncher method matchCommonParams.
public EnumMap<SystemParams, String> matchCommonParams(PipelineRun run, String apiHost, GitCredentials gitCredentials) {
EnumMap<SystemParams, String> systemParamsWithValue = new EnumMap<>(SystemParams.class);
if (run.getPipelineId() == null || run.getVersion() == null) {
systemParamsWithValue.put(SystemParams.VERSION, EMPTY_PARAMETER);
systemParamsWithValue.put(SystemParams.PIPELINE_ID, EMPTY_PARAMETER);
} else {
systemParamsWithValue.put(SystemParams.VERSION, run.getVersion());
systemParamsWithValue.put(SystemParams.PIPELINE_ID, String.valueOf(run.getPipelineId()));
}
systemParamsWithValue.put(SystemParams.API, apiHost);
systemParamsWithValue.put(SystemParams.API_EXTERNAL, preferenceManager.getPreference(SystemPreferences.BASE_API_HOST_EXTERNAL));
systemParamsWithValue.put(SystemParams.DISTRIBUTION_URL, preferenceManager.getPreference(SystemPreferences.BASE_PIPE_DISTR_URL));
systemParamsWithValue.put(SystemParams.PARENT, run.getPodId());
systemParamsWithValue.put(SystemParams.PIPELINE_NAME, run.getPipelineName().replaceAll("\\s+", ""));
systemParamsWithValue.put(SystemParams.RUN_DATE, dateFormat.format(run.getStartDate()));
systemParamsWithValue.put(SystemParams.RUN_TIME, timeFormat.format(run.getStartDate()));
systemParamsWithValue.put(SystemParams.RUN_ID, run.getId().toString());
systemParamsWithValue.put(SystemParams.AWS_REGION, run.getInstance().getAwsRegionId());
UserContext owner = Optional.ofNullable(authManager.getUserContext()).orElse(userManager.loadUserContext(run.getOwner()));
systemParamsWithValue.put(SystemParams.API_TOKEN, authManager.issueToken(owner, null).getToken());
systemParamsWithValue.put(SystemParams.OWNER, run.getOwner());
if (gitCredentials != null) {
putIfStringValuePresent(systemParamsWithValue, SystemParams.GIT_USER, gitCredentials.getUserName());
putIfStringValuePresent(systemParamsWithValue, SystemParams.GIT_TOKEN, gitCredentials.getToken());
}
return systemParamsWithValue;
}
use of com.epam.pipeline.security.UserContext in project cloud-pipeline by epam.
the class GrantPermissionManager method convertUserToSids.
private List<Sid> convertUserToSids(String user) {
String principal = user.toUpperCase();
UserContext eventOwner = userManager.loadUserContext(user.toUpperCase());
Assert.notNull(eventOwner, messageHelper.getMessage(MessageConstants.ERROR_USER_NAME_NOT_FOUND, principal));
List<Sid> sids = new ArrayList<>();
sids.add(new PrincipalSid(principal));
sids.addAll(eventOwner.getAuthorities().stream().map(GrantedAuthoritySid::new).collect(toList()));
return sids;
}
use of com.epam.pipeline.security.UserContext in project cloud-pipeline by epam.
the class UserManager method loadUserContext.
public UserContext loadUserContext(String name) {
PipelineUser pipelineUser = userDao.loadUserByName(name);
Assert.notNull(pipelineUser, messageHelper.getMessage(MessageConstants.ERROR_USER_NAME_NOT_FOUND, name));
return new UserContext(pipelineUser);
}
Aggregations