use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserService method unlockUserAccount.
/**
* Unlock user account.
*
* @param userId the user id
*/
public void unlockUserAccount(Long userId) {
UserEntity userEntity = userValidator.validateUserId(userId);
userEntity.setStatusEntity(Status.ACTIVE.getStatusEntity());
userEntity.setFailedLoginCount(null);
userEntity.setUnlockTime(null);
userEntity.setLoginTime(new Timestamp(System.currentTimeMillis()));
userRepository.save(userEntity);
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserActivityLogService method getActivityLog.
/**
* Gets the activity log.
*
* @param users the users
* @param activities the activities
* @param start the start
* @param end the end
* @return the activity log
*/
public List<LogInfo> getActivityLog(final List<Long> users, final List<String> activities, final String start, final String end) {
List<LogInfo> logs = userActivityService.getLogs(users, activities, start, end);
List<LogInfo> appAdminlogs = new ArrayList<LogInfo>();
if (!ValidatorUtil.isNull(logs)) {
Set<Long> userIds = new HashSet<Long>();
for (LogInfo log : logs) {
if (serverContext.getRequestContext().getUserId() != 1 && log.getUserId() == 1) {
appAdminlogs.add(log);
}
userIds.add(log.getUserId());
}
logs.removeAll(appAdminlogs);
List<UserEntity> usersList = userRepository.findByUserIdIn(userIds);
for (int i = 0; i < logs.size(); i++) {
UserEntity userEntity = getUser(logs.get(i).getUserId(), usersList);
if (userEntity != null) {
logs.get(i).setUsername(userEntity.getUsername());
} else {
logs.get(i).setUsername(String.valueOf(logs.get(i).getUserId()));
}
}
}
return logs;
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class CustomAuthenticationProvider method authenticate.
/*
* (non-Javadoc)
*
* @see org.springframework.security.authentication.dao.
* AbstractUserDetailsAuthenticationProvider#authenticate(org.
* springframework.security.core.Authentication)
*/
@Override
public Authentication authenticate(final Authentication auth) throws org.springframework.security.core.AuthenticationException {
CustomWebAuthenticationDetails customWebAuthenticationDetails = ((CustomWebAuthenticationDetails) auth.getDetails());
String verificationCode = customWebAuthenticationDetails.getVerificationCode();
UserEntity user = userRepository.findByUsernameIgnoreCase(auth.getName());
if (user == null || !user.getActiveFlag()) {
throw new BadCredentialsException("Login failed; Invalid email or password.");
}
String loginCount = null;
String unlockTime = null;
if (user.getUserId() != 1) {
loginCount = applicationSettingService.getApplicationSetting(ApplicationSetting.INVALID_LOGIN_ATTEMPT);
unlockTime = applicationSettingService.getApplicationSetting(ApplicationSetting.USER_ACCOUNT_UNLOCK_TIME);
if (!user.getStatusEntity().getStatus().equalsIgnoreCase("ACTIVE")) {
checkUserLoginAttempts(user, loginCount, unlockTime);
}
}
try {
final Authentication result = super.authenticate(auth);
if (user.getIs2FaEnabled()) {
if (!user.getIs2FaConfigured() && !customWebAuthenticationDetails.isConfigure2Fa()) {
throw new TwoFaKeyNotSetException();
} else {
if (verificationCode == null || verificationCode.isEmpty()) {
throw new OtpRequiredException();
} else if (!TwoFactorUtility.validateOtp(verificationCode, user.getTwoFaKey())) {
throw new InvalidOtpException("Invalid verfication code");
}
}
}
return new UsernamePasswordAuthenticationToken(user, result.getCredentials(), result.getAuthorities());
} catch (BadCredentialsException e) {
String error = null;
if (user.getUserId() != 1) {
error = updateInvalidLoginAttempts(user, loginCount, unlockTime);
} else {
error = "Login Failed.Invalid email or password.";
}
throw new BadCredentialsException(error);
}
}
use of org.usermanagement.dao.entity.UserEntity in project open-kilda by telstra.
the class UserConversionUtil method toUserEntity.
/**
* To user entity.
*
* @param userInfo the user info
* @param roleEntities the role entities
* @return the user entity
*/
public static UserEntity toUserEntity(final UserInfo userInfo, final Set<RoleEntity> roleEntities) {
UserEntity userEntity = new UserEntity();
userEntity.setUsername(userInfo.getUsername().toLowerCase());
userEntity.setPassword(StringUtil.encodeString(password));
userEntity.setEmail(userInfo.getEmail().toLowerCase());
userEntity.setName(userInfo.getName());
userEntity.setRoles(roleEntities);
userEntity.setActiveFlag(true);
userEntity.setLoginTime(new Timestamp(System.currentTimeMillis()));
userEntity.setLogoutTime(new Timestamp(System.currentTimeMillis()));
userEntity.setIsAuthorized(true);
userEntity.setIs2FaEnabled(true);
userEntity.setIs2FaConfigured(false);
StatusEntity statusEntity = Status.ACTIVE.getStatusEntity();
userEntity.setStatusEntity(statusEntity);
return userEntity;
}
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