Skip to content

Commit

Permalink
SSO login bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
muralibasani committed Jun 14, 2024
1 parent 88f9b90 commit 26e925d
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 63 deletions.
39 changes: 19 additions & 20 deletions coral/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.aiven.klaw.helpers.db.rdbms;

import static org.springframework.beans.BeanUtils.copyProperties;

import io.aiven.klaw.dao.*;
import io.aiven.klaw.model.enums.ApiResultStatus;
import io.aiven.klaw.model.enums.EntityType;
import io.aiven.klaw.model.enums.NewUserStatus;
import io.aiven.klaw.model.enums.RequestStatus;
import io.aiven.klaw.repository.*;
import java.sql.Timestamp;
Expand Down Expand Up @@ -380,13 +381,21 @@ public String insertIntoRegisterUsers(RegisterUserInfo userInfo) {
Optional<UserInfo> userNameExists = userInfoRepo.findById(userInfo.getUsername());
if (userNameExists.isPresent()) return "Failure. User already exists";

// STAGING status comes from AD users
RegisterUserInfo userRegistration =
registerInfoRepo.findFirstByUsernameAndStatusIn(
userInfo.getUsername(),
List.of(NewUserStatus.PENDING.value, NewUserStatus.STAGING.value));
if (userRegistration != null) {
return "Failure. Registration already exists";
Optional<RegisterUserInfo> optionalUserRegistration =
registerInfoRepo.findByUsername(userInfo.getUsername());
if (optionalUserRegistration.isPresent()) {
if ("APPROVED".equals(optionalUserRegistration.get().getStatus())) {
// do nothing -- user is deleted
} else if (!"STAGING".equals(optionalUserRegistration.get().getStatus())
&& !"PENDING".equals(optionalUserRegistration.get().getStatus())) {
return "Failure. Registration already exists";
} else {
int id = optionalUserRegistration.get().getId();
copyProperties(userInfo, optionalUserRegistration.get());
optionalUserRegistration.get().setId(id);
registerInfoRepo.save(optionalUserRegistration.get());
return ApiResultStatus.SUCCESS.value;
}
}

registerInfoRepo.save(userInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,10 @@ public void updateNewUserRequest(String username, String approver, boolean isApp
if (isApprove) {
status = NewUserStatus.APPROVED.value;
} else {
status = NewUserStatus.DECLINED.value;
// In case if user registration is declined, delete the record from db, so user can try to
// register again with any new data.
registerInfoRepo.deleteById("" + registerUser.getId());
return;
}
if (registerUser != null) {
if (NewUserStatus.PENDING.value.equals(registerUser.getStatus())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,8 @@ public ApiResponse addNewUser(UserInfoModel newUser, boolean isExternal) throws

if (isExternal) {

if ("".equals(newUser.getUserPassword())) {
if ("".equals(newUser.getUserPassword())
|| ACTIVE_DIRECTORY.value.equals(authenticationType)) {
mailService.sendMail(
newUser.getUsername(),
newUser.getUserPassword(),
Expand Down
13 changes: 13 additions & 0 deletions core/src/test/java/io/aiven/klaw/MockMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.aiven.klaw.model.requests.EnvModel;
import io.aiven.klaw.model.requests.KwClustersModel;
import io.aiven.klaw.model.requests.KwRolesPermissionsModel;
import io.aiven.klaw.model.requests.RegisterUserInfoModel;
import io.aiven.klaw.model.requests.TeamModel;
import io.aiven.klaw.model.requests.UserInfoModel;
import io.aiven.klaw.model.response.EnvParams;
Expand Down Expand Up @@ -53,6 +54,18 @@ public UserInfoModel getUserInfoModel(String username, String role, String team)
return userInfoModel;
}

public RegisterUserInfoModel getRegisterUserInfoModel(String username, String role) {
RegisterUserInfoModel userInfoModel = new RegisterUserInfoModel();
userInfoModel.setUsername(username);
userInfoModel.setPwd("testpwd");
userInfoModel.setRole(role);
userInfoModel.setTeamId(1001);
userInfoModel.setFullname("New User");
userInfoModel.setMailid("[email protected]");

return userInfoModel;
}

public UserInfoModel getUserInfoModelSwitchTeams(
String username, String role, int teamId, int switchTeamSize) {
UserInfoModel userInfoModel = new UserInfoModel();
Expand Down
Loading

0 comments on commit 26e925d

Please sign in to comment.