use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class UserManager method createUser.
@Transactional(propagation = Propagation.REQUIRED)
public PipelineUser createUser(String name, List<Long> roles, List<String> groups, Map<String, String> attributes, Long defaultStorageId) {
Assert.isTrue(StringUtils.isNotBlank(name), messageHelper.getMessage(MessageConstants.ERROR_USER_NAME_REQUIRED));
String userName = name.trim().toUpperCase();
PipelineUser loadedUser = userDao.loadUserByName(userName);
Assert.isNull(loadedUser, messageHelper.getMessage(MessageConstants.ERROR_USER_NAME_EXISTS, name));
PipelineUser user = new PipelineUser(userName);
List<Long> userRoles = getNewUserRoles(roles);
user.setRoles(roleDao.loadRolesList(userRoles));
user.setGroups(groups);
user.setAttributes(attributes);
user.setDefaultStorageId(defaultStorageId);
storageValidator.validate(user);
return userDao.createUser(user, userRoles);
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class UserManager method updateUserSAMLInfo.
@Transactional(propagation = Propagation.REQUIRED)
public PipelineUser updateUserSAMLInfo(Long id, String name, List<Long> roles, List<String> groups, Map<String, String> attributes) {
PipelineUser user = loadUserById(id);
if (needToUpdateUser(groups, attributes, user)) {
user.setUserName(name);
user.setGroups(groups);
user.setAttributes(attributes);
userDao.updateUser(user);
}
updateUserRoles(id, roles);
return loadUserById(id);
}
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());
}
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);
}
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);
}
Aggregations