use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method updateUser.
/**
* Update user.
*
* @param userInfo the user info
* @param userId the user id
* @return the user info
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public UserInfo updateUser(final UserInfo userInfo, final Long userId) {
UserEntity userEntity = userValidator.validateUpdateUser(userInfo);
StringBuilder activityMessage = new StringBuilder(userEntity.getUsername() + " updated with:\n");
if (userInfo.getRoleIds() != null) {
StringBuilder roles = new StringBuilder();
userEntity.getRoles().clear();
Set<RoleEntity> roleEntities = roleService.getRolesById(userInfo.getRoleIds());
userEntity.getRoles().addAll(roleEntities);
for (RoleEntity role : roleEntities) {
roles = roles.length() > 0 ? roles.append("," + role.getName()) : roles.append(role.getName());
}
activityMessage.append("roles:" + roles.toString() + "\n");
}
UserConversionUtil.toUpateUserEntity(userInfo, userEntity, activityMessage);
userEntity = userRepository.save(userEntity);
activityLogger.log(ActivityType.UPDATE_USER, activityMessage.toString());
LOGGER.info("User updated successfully (id: " + userId + ")");
return UserConversionUtil.toUserInfo(userEntity);
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method createSamlUser.
/**
* Creates the saml user.
* @param username the username
* @param roles the user roles
*/
public void createSamlUser(String username, Set<RoleEntity> roles) {
UserEntity userEntity = new UserEntity();
userEntity.setUsername(username);
userEntity.setEmail(username);
userEntity.setName(username);
userEntity.setRoles(roles);
userEntity.setActiveFlag(true);
userEntity.setLoginTime(new Timestamp(System.currentTimeMillis()));
userEntity.setLogoutTime(new Timestamp(System.currentTimeMillis()));
userEntity.setIsAuthorized(true);
userEntity.setIs2FaEnabled(false);
userEntity.setIs2FaConfigured(false);
StatusEntity statusEntity = Status.ACTIVE.getStatusEntity();
userEntity.setStatusEntity(statusEntity);
String password = ValidatorUtil.randomAlphaNumeric(16);
userEntity.setPassword(StringUtil.encodeString(password));
userRepository.save(userEntity);
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method populateUserInfo.
/**
* Adds user information in session.
*
* @param userInfo the userInfo
* @param username who's information is added in session.
*/
public void populateUserInfo(final UserInfo userInfo, final String username) {
UserEntity user = getUserByUsername(username);
Set<RoleEntity> roleEntities = user.getRoles();
Set<String> roles = new HashSet<String>();
Set<String> permissions = new HashSet<String>();
for (RoleEntity roleEntity : roleEntities) {
roles.add(roleEntity.getName());
userInfo.setRole("ROLE_ADMIN");
if (user.getUserId() != 1) {
Set<PermissionEntity> permissionEntities = roleEntity.getPermissions();
for (PermissionEntity permissionEntity : permissionEntities) {
if (permissionEntity.getStatusEntity().getStatusCode().equalsIgnoreCase(Status.ACTIVE.getCode()) && !permissionEntity.getIsAdminPermission()) {
permissions.add(permissionEntity.getName());
}
}
}
}
if (user.getUserId() == 1) {
List<PermissionEntity> permissionEntities = permissionRepository.findAll();
for (PermissionEntity permissionEntity : permissionEntities) {
permissions.add(permissionEntity.getName());
}
}
userInfo.setUserId(user.getUserId());
userInfo.setUsername(user.getUsername());
userInfo.setName(user.getName());
userInfo.setRoles(roles);
userInfo.setPermissions(permissions);
userInfo.setIs2FaEnabled(user.getIs2FaEnabled());
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method updateLoginDetail.
/**
* Update login detail.
*
* @param userName the user name
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void updateLoginDetail(final String userName) {
UserEntity userEntity = userRepository.findByUsernameIgnoreCase(userName);
if (ValidatorUtil.isNull(userEntity)) {
LOGGER.warn("User with username '" + userName + "' not found. Error: " + messageUtil.getAttributeInvalid("username", userName + ""));
throw new RequestValidationException(messageUtil.getAttributeInvalid("username", userName + ""));
}
userEntity.setLoginTime(Calendar.getInstance().getTime());
userEntity.setFailedLoginCount(null);
userEntity.setUnlockTime(null);
if (userEntity.getIs2FaEnabled()) {
userEntity.setIs2FaConfigured(true);
}
userRepository.save(userEntity);
LOGGER.info("User last login updated successfully (username: " + userName + ")");
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class RoleConversionUtil method toRole.
/**
* To role.
*
* @param roleEntity the role entity
* @param withPermissions the with permissions
* @param withUsers the with users
* @return the role
*/
public static Role toRole(final RoleEntity roleEntity, final boolean withPermissions, final boolean withUsers) {
Role role = new Role();
role.setName(roleEntity.getName());
role.setRoleId(roleEntity.getRoleId());
role.setStatus(roleEntity.getStatusEntity().getStatus());
role.setDescription(roleEntity.getDescription());
if (withPermissions) {
List<Permission> permissionList = new ArrayList<Permission>();
if (!ValidatorUtil.isNull(roleEntity.getPermissions())) {
for (PermissionEntity permissionEntity : roleEntity.getPermissions()) {
permissionList.add(PermissionConversionUtil.toPermission(permissionEntity, null));
}
role.setPermissions(permissionList);
}
}
if (withUsers) {
List<UserInfo> userInfoList = new ArrayList<>();
for (UserEntity userEntity : roleEntity.getUsers()) {
if (userEntity.getUserId() != 1) {
UserInfo userInfo = new UserInfo();
userInfo.setUserId(userEntity.getUserId());
userInfo.setName(userEntity.getName());
userInfoList.add(userInfo);
}
}
role.setUserInfo(userInfoList);
}
return role;
}
Aggregations