Search in sources :

Example 6 with UserContext

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());
}
Also used : UserContext(com.epam.pipeline.security.UserContext) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 7 with UserContext

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();
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) UserContext(com.epam.pipeline.security.UserContext)

Example 8 with UserContext

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;
}
Also used : UserContext(com.epam.pipeline.security.UserContext) EnumMap(java.util.EnumMap)

Example 9 with UserContext

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;
}
Also used : GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) UserContext(com.epam.pipeline.security.UserContext) ArrayList(java.util.ArrayList) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) Sid(org.springframework.security.acls.model.Sid) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) AclSid(com.epam.pipeline.entity.security.acl.AclSid)

Example 10 with UserContext

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);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) UserContext(com.epam.pipeline.security.UserContext)

Aggregations

UserContext (com.epam.pipeline.security.UserContext)13 JwtRawToken (com.epam.pipeline.entity.security.JwtRawToken)3 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)3 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)2 JwtTokenClaims (com.epam.pipeline.entity.security.JwtTokenClaims)2 Test (org.junit.Test)2 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)2 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)2 SamlResponse (com.coveo.saml.SamlResponse)1 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)1 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)1 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)1 AclSecuredEntry (com.epam.pipeline.entity.security.acl.AclSecuredEntry)1 AclSid (com.epam.pipeline.entity.security.acl.AclSid)1 DockerAuthorizationException (com.epam.pipeline.exception.docker.DockerAuthorizationException)1 JwtAuthenticationToken (com.epam.pipeline.security.jwt.JwtAuthenticationToken)1 File (java.io.File)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1