Search in sources :

Example 26 with PipelineUser

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

the class UserManager method getUserControls.

/**
 * Reads file with control setting from disk and resolves settings applied to current user.
 * @return {@link List} of {@link CustomControl} that should be applied to current user
 */
public List<CustomControl> getUserControls() {
    PipelineUser currentUser = authManager.getCurrentUser();
    if (currentUser == null) {
        return Collections.emptyList();
    }
    List<ControlEntry> settings = preferenceManager.getPreference(SystemPreferences.UI_CONTROLS_SETTINGS);
    if (settings == null) {
        return Collections.emptyList();
    }
    Set<String> authorities = currentUser.getAuthorities();
    return settings.stream().map(entry -> {
        Map<String, String> userSettings = entry.getUserSettings().entrySet().stream().filter(authEntry -> authorities.contains(authEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        // if no setting found or settings are ambiguous (more than one are present)
        if (MapUtils.isEmpty(userSettings) || userSettings.size() > 1) {
            return new CustomControl(entry.getKey(), entry.getDefaultValue());
        }
        return new CustomControl(entry.getKey(), userSettings.values().stream().findFirst().orElse(entry.getDefaultValue()));
    }).collect(Collectors.toList());
}
Also used : CustomControl(com.epam.pipeline.entity.user.CustomControl) StringUtils(org.apache.commons.lang.StringUtils) DataStorageValidator(com.epam.pipeline.manager.datastorage.DataStorageValidator) MessageConstants(com.epam.pipeline.common.MessageConstants) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) CollectionUtils(org.apache.commons.collections4.CollectionUtils) NumberUtils(org.apache.commons.lang.math.NumberUtils) ArrayList(java.util.ArrayList) UserContext(com.epam.pipeline.security.UserContext) MessageHelper(com.epam.pipeline.common.MessageHelper) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) PipelineUserVO(com.epam.pipeline.controller.vo.PipelineUserVO) Map(java.util.Map) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Role(com.epam.pipeline.entity.user.Role) MapUtils(org.apache.commons.collections4.MapUtils) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Collection(java.util.Collection) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Set(java.util.Set) ControlEntry(com.epam.pipeline.entity.utils.ControlEntry) Collectors(java.util.stream.Collectors) List(java.util.List) UserDao(com.epam.pipeline.dao.user.UserDao) AuthManager(com.epam.pipeline.manager.security.AuthManager) RoleDao(com.epam.pipeline.dao.user.RoleDao) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) ControlEntry(com.epam.pipeline.entity.utils.ControlEntry) CustomControl(com.epam.pipeline.entity.user.CustomControl) ControlEntry(com.epam.pipeline.entity.utils.ControlEntry) Map(java.util.Map)

Example 27 with PipelineUser

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

the class UserManager method updateUser.

@Transactional(propagation = Propagation.REQUIRED)
public PipelineUser updateUser(Long id, PipelineUserVO userVO) {
    PipelineUser user = loadUserById(id);
    user.setDefaultStorageId(userVO.getDefaultStorageId());
    storageValidator.validate(user);
    return userDao.updateUser(user);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser 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)

Example 29 with PipelineUser

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

the class UserManager method loadUserById.

public PipelineUser loadUserById(Long id) {
    PipelineUser user = userDao.loadUserById(id);
    Assert.notNull(user, messageHelper.getMessage(MessageConstants.ERROR_USER_ID_NOT_FOUND, id));
    return user;
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser)

Example 30 with PipelineUser

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

the class SAMLUserDetailsServiceImpl method loadUserBySAML.

@Override
public UserContext loadUserBySAML(SAMLCredential credential) {
    String userName = credential.getNameID().getValue().toUpperCase();
    List<String> groups = readAuthorities(credential);
    Map<String, String> attributes = readAttributes(credential);
    PipelineUser loadedUser = userManager.loadUserByName(userName);
    if (loadedUser == null) {
        String message = messageHelper.getMessage(MessageConstants.ERROR_USER_NAME_NOT_FOUND, userName);
        if (!autoCreateUsers) {
            throw new UsernameNotFoundException(message);
        }
        LOGGER.debug(message);
        List<Long> roles = roleManager.getDefaultRolesIds();
        PipelineUser createdUser = userManager.createUser(userName, roles, groups, attributes, null);
        UserContext userContext = new UserContext(createdUser.getId(), userName);
        userContext.setGroups(createdUser.getGroups());
        LOGGER.debug("Created user {} with groups {}", userName, groups);
        userContext.setRoles(createdUser.getRoles());
        return userContext;
    } else {
        LOGGER.debug("Found user by name {}", userName);
        loadedUser.setUserName(userName);
        List<Long> roles = loadedUser.getRoles().stream().map(Role::getId).collect(Collectors.toList());
        if (userManager.needToUpdateUser(groups, attributes, loadedUser)) {
            loadedUser = userManager.updateUserSAMLInfo(loadedUser.getId(), userName, roles, groups, attributes);
            LOGGER.debug("Updated user groups {} ", groups);
        }
        return new UserContext(loadedUser);
    }
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) UserContext(com.epam.pipeline.security.UserContext)

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