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